diff --git a/dist/xeokit-sdk.cjs.js b/dist/xeokit-sdk.cjs.js index 2dc7703075..3336a0c9a9 100644 --- a/dist/xeokit-sdk.cjs.js +++ b/dist/xeokit-sdk.cjs.js @@ -24000,6 +24000,16 @@ function buildVertex$3(mesh) { src.push(" mat[2][2] =1.0;"); src.push("}"); } + + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("void main(void) {"); src.push("vec4 localPosition = vec4(position, 1.0); "); if (quantizedGeometry) { @@ -24026,7 +24036,7 @@ function buildVertex$3(mesh) { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); return src; } @@ -24229,6 +24239,8 @@ PickMeshRenderer.prototype.drawMesh = function (frameCtx, mesh) { const r = pickID & 0xFF; gl.uniform4f(this._uPickColor, r / 255, g / 255, b / 255, a / 255); + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); + if (geometryState.indicesBuf) { gl.drawElements(geometryState.primitive, geometryState.indicesBuf.numItems, geometryState.indicesBuf.itemType, 0); frameCtx.drawElements++; @@ -24262,6 +24274,7 @@ PickMeshRenderer.prototype._allocate = function (mesh) { this._aPosition = program.getAttribute("position"); this._uClippable = program.getLocation("clippable"); this._uPickColor = program.getLocation("pickColor"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uOffset = program.getLocation("offset"); if (scene.logarithmicDepthBufferEnabled ) { this._uLogDepthBufFC = program.getLocation("logDepthBufFC"); @@ -24299,8 +24312,6 @@ function buildVertex$2(mesh) { const scene = mesh.scene; const clipping = scene._sectionPlanesState.sectionPlanes.length > 0; const quantizedGeometry = !!mesh._geometry._state.compressGeometry; - mesh._state.billboard; - mesh._state.stationary; const src = []; src.push('#version 300 es'); src.push("// Surface picking vertex shader"); @@ -24322,6 +24333,16 @@ function buildVertex$2(mesh) { src.push("}"); src.push("out float isPerspective;"); } + + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("out vec4 vColor;"); if (quantizedGeometry) { src.push("uniform mat4 positionsDecodeMatrix;"); @@ -24343,7 +24364,7 @@ function buildVertex$2(mesh) { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); return src; } @@ -24536,6 +24557,9 @@ PickTriangleRenderer.prototype.drawMesh = function (frameCtx, mesh) { } else { this._aPosition.bindArrayBuffer(positionsBuf); } + + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); + pickColorsBuf.bind(); gl.enableVertexAttribArray(this._aColor.location); gl.vertexAttribPointer(this._aColor.location, pickColorsBuf.itemSize, pickColorsBuf.itemType, true, 0, 0); // Normalize @@ -24567,6 +24591,7 @@ PickTriangleRenderer.prototype._allocate = function (mesh) { } this._aPosition = program.getAttribute("position"); this._aColor = program.getAttribute("color"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uClippable = program.getLocation("clippable"); this._uOffset = program.getLocation("offset"); if (scene.logarithmicDepthBufferEnabled ) { @@ -34357,7 +34382,7 @@ class RenderBuffer { read(pickX, pickY, glFormat = null, glType = null, arrayType = Uint8Array, arrayMultiplier = 4) { const x = pickX; - const y = (this.buffer.height || this.gl.drawingBufferHeight) - pickY; + const y = this.buffer.height ? (this.buffer.height - pickY - 1) : (this.gl.drawingBufferHeight - pickY); const pix = new arrayType(arrayMultiplier); const gl = this.gl; gl.readPixels(x, y, 1, 1, glFormat || gl.RGBA, glType || gl.UNSIGNED_BYTE, pix, 0); @@ -37545,7 +37570,6 @@ const edgesDefaultColor = new Float32Array([0, 0, 0, 1]); const tempVec4 = math.vec4(); const tempVec3a$w = math.vec3(); -math.vec3(); const tempVec3c$n = math.vec3(); const tempMat4a$f = math.mat4(); @@ -37618,6 +37642,18 @@ class VBOSceneModelRenderer { return src; } + _addRemapClipPosLines(src) { + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + return src; + } + getValid() { return this._hash === this._getHash(); } @@ -37751,6 +37787,7 @@ class VBOSceneModelRenderer { this._aPickColor = program.getAttribute("pickColor"); this._uPickZNear = program.getLocation("pickZNear"); this._uPickZFar = program.getLocation("pickZFar"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uColorMap = "uColorMap"; this._uMetallicRoughMap = "uMetallicRoughMap"; @@ -37791,7 +37828,6 @@ class VBOSceneModelRenderer { const program = this._program; const lightsState = scene._lightsState; const lights = lightsState.lights; - const project = scene.camera.project; program.bind(); @@ -37818,43 +37854,6 @@ class VBOSceneModelRenderer { gl.uniform3fv(this._uLightDir[i], light.dir); } } - - if (this._withSAO) { - const sao = scene.sao; - const saoEnabled = sao.possible; - if (saoEnabled) { - const viewportWidth = gl.drawingBufferWidth; - const viewportHeight = gl.drawingBufferHeight; - tempVec4[0] = viewportWidth; - tempVec4[1] = viewportHeight; - tempVec4[2] = sao.blendCutoff; - tempVec4[3] = sao.blendFactor; - gl.uniform4fv(this._uSAOParams, tempVec4); - this._program.bindTexture(this._uOcclusionTexture, frameCtx.occlusionTexture, 0); - } - } - - if (scene.logarithmicDepthBufferEnabled) { - const logDepthBufFC = 2.0 / (Math.log(project.far + 1.0) / Math.LN2); - gl.uniform1f(this._uLogDepthBufFC, logDepthBufFC); - } - - if (this._uGammaFactor) { - gl.uniform1f(this._uGammaFactor, scene.gammaFactor); - } - - if (this._uPickInvisible) { - gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible); - } - - - if (this._uShadowViewMatrix) { - gl.uniformMatrix4fv(this._uShadowViewMatrix, false, frameCtx.shadowViewMatrix); - } - - if (this._uShadowProjMatrix) { - gl.uniformMatrix4fv(this._uShadowProjMatrix, false, frameCtx.shadowProjMatrix); - } } _makeVAO(state) { @@ -38051,6 +38050,10 @@ class VBOSceneModelRenderer { gl.uniform1f(this._uPickZFar, frameCtx.pickZFar); } + if (this._uPickClipPos) { + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); + } + if (this._uPositionsDecodeMatrix) { gl.uniformMatrix4fv(this._uPositionsDecodeMatrix, false, state.positionsDecodeMatrix); } @@ -39230,6 +39233,8 @@ class TrianglesBatchingPickMeshRenderer extends VBOSceneModelTriangleBatchingRen src.push("out float vFlags;"); } + this._addRemapClipPosLines(src); + src.push("out vec4 vPickColor;"); src.push("void main(void) {"); @@ -39257,7 +39262,7 @@ class TrianglesBatchingPickMeshRenderer extends VBOSceneModelTriangleBatchingRen src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -39356,6 +39361,9 @@ class TrianglesBatchingPickDepthRenderer extends VBOSceneModelTriangleBatchingRe src.push("out vec4 vWorldPosition;"); src.push("out float vFlags;"); } + + this._addRemapClipPosLines(src); + src.push("out vec4 vViewPosition;"); src.push("void main(void) {"); @@ -39381,7 +39389,7 @@ class TrianglesBatchingPickDepthRenderer extends VBOSceneModelTriangleBatchingRe src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -39479,6 +39487,8 @@ class TrianglesBatchingPickNormalsRenderer extends VBOSceneModelTriangleBatching this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -39523,7 +39533,7 @@ class TrianglesBatchingPickNormalsRenderer extends VBOSceneModelTriangleBatching src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -40626,6 +40636,8 @@ class TrianglesBatchingPickNormalsFlatRenderer extends VBOSceneModelTriangleBatc this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -40659,7 +40671,7 @@ class TrianglesBatchingPickNormalsFlatRenderer extends VBOSceneModelTriangleBatc src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -44355,6 +44367,8 @@ class TrianglesInstancingPickMeshRenderer extends VBOSceneModelTriangleInstancin this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -44399,7 +44413,7 @@ class TrianglesInstancingPickMeshRenderer extends VBOSceneModelTriangleInstancin src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); return src; @@ -44489,6 +44503,8 @@ class TrianglesInstancingPickDepthRenderer extends VBOSceneModelTriangleInstanci this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -44531,7 +44547,7 @@ class TrianglesInstancingPickDepthRenderer extends VBOSceneModelTriangleInstanci src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); return src; @@ -44634,6 +44650,8 @@ class TrianglesInstancingPickNormalsRenderer extends VBOSceneModelTriangleInstan this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -44682,7 +44700,7 @@ class TrianglesInstancingPickNormalsRenderer extends VBOSceneModelTriangleInstan src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); return src; @@ -45800,6 +45818,8 @@ class TrianglesInstancingPickNormalsFlatRenderer extends VBOSceneModelTriangleIn this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -45838,7 +45858,7 @@ class TrianglesInstancingPickNormalsFlatRenderer extends VBOSceneModelTriangleIn src.push("vFlags = flags;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); return src; @@ -50722,6 +50742,8 @@ class PointsBatchingPickMeshRenderer extends VBOSceneModelPointBatchingRenderer this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + src.push("uniform float pointSize;"); if (pointsMaterial.perspectivePoints) { src.push("uniform float nearPlaneHeight;"); @@ -50763,7 +50785,7 @@ class PointsBatchingPickMeshRenderer extends VBOSceneModelPointBatchingRenderer if (scene.logarithmicDepthBufferEnabled) { src.push("vFragDepth = 1.0 + clipPos.w;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (pointsMaterial.perspectivePoints) { src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"); src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);"); @@ -50862,6 +50884,8 @@ class PointsBatchingPickDepthRenderer extends VBOSceneModelPointBatchingRenderer this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + src.push("uniform float pointSize;"); if (pointsMaterial.perspectivePoints) { src.push("uniform float nearPlaneHeight;"); @@ -50900,7 +50924,7 @@ class PointsBatchingPickDepthRenderer extends VBOSceneModelPointBatchingRenderer if (scene.logarithmicDepthBufferEnabled) { src.push("vFragDepth = 1.0 + clipPos.w;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (pointsMaterial.perspectivePoints) { src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"); src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);"); @@ -52345,6 +52369,8 @@ class PointsInstancingPickMeshRenderer extends VBOSceneModelPointInstancingRende this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + src.push("uniform float pointSize;"); if (pointsMaterial.perspectivePoints) { src.push("uniform float nearPlaneHeight;"); @@ -52386,6 +52412,7 @@ class PointsInstancingPickMeshRenderer extends VBOSceneModelPointInstancingRende src.push(" vFlags = flags;"); } src.push("vec4 clipPos = projMatrix * viewPosition;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (scene.logarithmicDepthBufferEnabled) { src.push("vFragDepth = 1.0 + clipPos.w;"); } @@ -52496,6 +52523,8 @@ class PointsInstancingPickDepthRenderer extends VBOSceneModelPointInstancingRend this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + src.push("uniform float pointSize;"); if (pointsMaterial.perspectivePoints) { src.push("uniform float nearPlaneHeight;"); @@ -52535,10 +52564,11 @@ class PointsInstancingPickDepthRenderer extends VBOSceneModelPointInstancingRend } src.push(" vViewPosition = viewPosition;"); src.push("vec4 clipPos = projMatrix * viewPosition;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (scene.logarithmicDepthBufferEnabled) { src.push("vFragDepth = 1.0 + clipPos.w;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (pointsMaterial.perspectivePoints) { src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"); src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);"); @@ -57329,7 +57359,7 @@ class TrianglesDataTexturePickMeshRenderer { getValid() { return this._hash === this._getHash(); - }; + } _getHash() { return this._scene._sectionPlanesState.getHash(); @@ -57390,6 +57420,7 @@ class TrianglesDataTexturePickMeshRenderer { rtcViewMatrix = camera.viewMatrix; rtcCameraEye = camera.eye; } + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); gl.uniformMatrix4fv(this._uSceneModelWorldMatrix, false, rotationMatrixConjugate); gl.uniformMatrix4fv(this._uViewMatrix, false, rtcViewMatrix); gl.uniformMatrix4fv(this._uProjMatrix, false, camera.projMatrix); @@ -57463,6 +57494,7 @@ class TrianglesDataTexturePickMeshRenderer { const program = this._program; this._uRenderPass = program.getLocation("renderPass"); this._uPickInvisible = program.getLocation("pickInvisible"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uSceneModelWorldMatrix = program.getLocation("sceneModelWorldMatrix"); this._uViewMatrix = program.getLocation("viewMatrix"); this._uProjMatrix = program.getLocation("projMatrix"); @@ -57560,6 +57592,15 @@ class TrianglesDataTexturePickMeshRenderer { src.push("out float isPerspective;"); } + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("bool isPerspectiveMatrix(mat4 m) {"); src.push(" return (m[2][3] == - 1.0);"); src.push("}"); @@ -57670,7 +57711,7 @@ class TrianglesDataTexturePickMeshRenderer { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -57759,7 +57800,7 @@ class TrianglesDataTexturePickDepthRenderer { getValid() { return this._hash === this._getHash(); - }; + } _getHash() { return this._scene._sectionPlanesState.getHash(); @@ -57833,6 +57874,7 @@ class TrianglesDataTexturePickDepthRenderer { gl.uniform3fv(this._uCameraEyeRtc, rtcCameraEye); gl.uniform1i(this._uRenderPass, renderPass); gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible); + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); gl.uniform1f(this._uPickZNear, frameCtx.pickZNear); gl.uniform1f(this._uPickZFar, frameCtx.pickZFar); gl.uniformMatrix4fv(this._uWorldMatrix, false, rotationMatrixConjugate); @@ -57907,6 +57949,7 @@ class TrianglesDataTexturePickDepthRenderer { const program = this._program; this._uRenderPass = program.getLocation("renderPass"); this._uPickInvisible = program.getLocation("pickInvisible"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uWorldMatrix = program.getLocation("worldMatrix"); this._uViewMatrix = program.getLocation("viewMatrix"); this._uProjMatrix = program.getLocation("projMatrix"); @@ -57996,6 +58039,15 @@ class TrianglesDataTexturePickDepthRenderer { src.push("out float isPerspective;"); } + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("bool isPerspectiveMatrix(mat4 m) {"); src.push(" return (m[2][3] == - 1.0);"); src.push("}"); @@ -58102,7 +58154,7 @@ class TrianglesDataTexturePickDepthRenderer { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -59063,7 +59115,7 @@ class TrianglesDataTexturePickNormalsRenderer { getValid() { return this._hash === this._getHash(); - }; + } _getHash() { return this._scene._sectionPlanesState.getHash(); @@ -59121,6 +59173,7 @@ class TrianglesDataTexturePickNormalsRenderer { gl.uniform3fv(this._uCameraEyeRtc, originCameraEye); gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible); + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); if (scene.logarithmicDepthBufferEnabled) { const logDepthBufFC = 2.0 / (Math.log(camera.project.far + 1.0) / Math.LN2); // TODO: Far should be from projection matrix? @@ -59203,6 +59256,7 @@ class TrianglesDataTexturePickNormalsRenderer { this._uRenderPass = program.getLocation("renderPass"); this._uPickInvisible = program.getLocation("pickInvisible"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uSectionPlanes = []; @@ -59287,6 +59341,15 @@ class TrianglesDataTexturePickNormalsRenderer { src.push("out float isPerspective;"); } + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("bool isPerspectiveMatrix(mat4 m) {"); src.push(" return (m[2][3] == - 1.0);"); src.push("}"); @@ -59401,7 +59464,7 @@ class TrianglesDataTexturePickNormalsRenderer { src.push(" vWorldPosition = worldPosition;"); src.push(" vFlags2 = flags2.w;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); @@ -60696,7 +60759,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer { getValid() { return this._hash === this._getHash(); - }; + } _getHash() { return this._scene._sectionPlanesState.getHash(); @@ -60769,6 +60832,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer { gl.uniform1i(this._uRenderPass, renderPass); gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible); + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix); @@ -60937,6 +61001,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer { this._uRenderPass = program.getLocation("renderPass"); this._uPickInvisible = program.getLocation("pickInvisible"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uPositionsDecodeMatrix = program.getLocation("positionsDecodeMatrix"); this._uWorldMatrix = program.getLocation("worldMatrix"); this._uViewMatrix = program.getLocation("viewMatrix"); @@ -61026,6 +61091,16 @@ class TrianglesDataTexturePickNormalsFlatRenderer { src.push("}"); src.push("out float isPerspective;"); } + + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("out vec4 vWorldPosition;"); if (clipping) { src.push("out int vFlags2;"); @@ -61104,7 +61179,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -73630,10 +73705,10 @@ const Renderer$1 = function (scene, options) { * Picks an Entity. * @private */ - this.pick = (function () { + this.pick = (function () { const tempVec3a = math.vec3(); - const tempMat4a = math.mat4(); + math.mat4(); const tempMat4b = math.mat4(); const randomVec3 = math.vec3(); @@ -73675,13 +73750,11 @@ const Renderer$1 = function (scene, options) { // Picking with arbitrary World-space ray // Align camera along ray and fire ray through center of canvas - - const pickFrustumMatrix = math.frustumMat4(-1, 1, -1, 1, 0.01, scene.camera.project.far, tempMat4a); - + if (params.matrix) { pickViewMatrix = params.matrix; - pickProjMatrix = pickFrustumMatrix; + pickProjMatrix = scene.camera.projMatrix; } else { @@ -73698,7 +73771,7 @@ const Renderer$1 = function (scene, options) { math.cross3Vec3(worldRayDir, randomVec3, up); pickViewMatrix = math.lookAtMat4v(worldRayOrigin, look, up, tempMat4b); - pickProjMatrix = pickFrustumMatrix; + pickProjMatrix = scene.camera.projMatrix; pickResult.origin = worldRayOrigin; pickResult.direction = worldRayDir; @@ -73720,7 +73793,7 @@ const Renderer$1 = function (scene, options) { } } - const pickBuffer = renderBufferManager.getRenderBuffer("pick"); + const pickBuffer = renderBufferManager.getRenderBuffer("pick", { size: [1, 1] }); pickBuffer.bind(); @@ -73782,10 +73855,12 @@ const Renderer$1 = function (scene, options) { frameCtx.pickViewMatrix = pickViewMatrix; frameCtx.pickProjMatrix = pickProjMatrix; frameCtx.pickInvisible = !!params.pickInvisible; + frameCtx.pickClipPos = [ + getClipPosX(canvasPos[0], gl.drawingBufferWidth), + getClipPosY(canvasPos[1], gl.drawingBufferHeight), + ]; - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); - - gl.clearColor(0, 0, 0, 0); + gl.viewport(0, 0, 1, 1); gl.depthMask(true); gl.enable(gl.DEPTH_TEST); gl.disable(gl.CULL_FACE); @@ -73819,8 +73894,7 @@ const Renderer$1 = function (scene, options) { } } } - const resolutionScale = scene.canvas.resolutionScale; - const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale)); + const pix = pickBuffer.read(0, 0); let pickID = pix[0] + (pix[1] * 256) + (pix[2] * 256 * 256) + (pix[3] * 256 * 256 * 256); if (pickID < 0) { @@ -73845,8 +73919,12 @@ const Renderer$1 = function (scene, options) { frameCtx.pickViewMatrix = pickViewMatrix; // Can be null frameCtx.pickProjMatrix = pickProjMatrix; // Can be null // frameCtx.pickInvisible = !!params.pickInvisible; + frameCtx.pickClipPos = [ + getClipPosX(canvasPos[0], gl.drawingBufferWidth), + getClipPosY(canvasPos[1], gl.drawingBufferHeight), + ]; - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); + gl.viewport(0, 0, 1, 1); gl.clearColor(0, 0, 0, 0); gl.enable(gl.DEPTH_TEST); @@ -73856,8 +73934,7 @@ const Renderer$1 = function (scene, options) { pickable.drawPickTriangles(frameCtx); - const resolutionScale = scene.canvas.resolutionScale; - const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale)); + const pix = pickBuffer.read(0, 0); let primIndex = pix[0] + (pix[1] * 256) + (pix[2] * 256 * 256) + (pix[3] * 256 * 256 * 256); @@ -73889,8 +73966,12 @@ const Renderer$1 = function (scene, options) { frameCtx.pickZFar = nearAndFar[1]; frameCtx.pickElementsCount = pickable.pickElementsCount; frameCtx.pickElementsOffset = pickable.pickElementsOffset; - - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); + frameCtx.pickClipPos = [ + getClipPosX(canvasPos[0], gl.drawingBufferWidth), + getClipPosY(canvasPos[1], gl.drawingBufferHeight), + ]; + + gl.viewport(0, 0, 1, 1); gl.clearColor(0, 0, 0, 0); gl.depthMask(true); @@ -73901,8 +73982,7 @@ const Renderer$1 = function (scene, options) { pickable.drawPickDepths(frameCtx); // Draw color-encoded fragment screen-space depths - const resolutionScale = scene.canvas.resolutionScale; - const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale)); + const pix = pickBuffer.read(0, 0); const screenZ = unpackDepth(pix); // Get screen-space Z at the given canvas coords @@ -74203,12 +74283,12 @@ const Renderer$1 = function (scene, options) { frameCtx.pickOrigin = pickResult.origin; frameCtx.pickViewMatrix = pickViewMatrix; frameCtx.pickProjMatrix = pickProjMatrix; + frameCtx.pickClipPos = [ + getClipPosX(canvasPos[0], gl.drawingBufferWidth), + getClipPosY(canvasPos[1], gl.drawingBufferHeight), + ]; - const pickNormalBuffer = renderBufferManager.getRenderBuffer("pick-normal"); - - pickNormalBuffer.bind(gl.RGBA32I); - - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); + gl.viewport(0, 0, 1, 1); gl.enable(gl.DEPTH_TEST); gl.disable(gl.CULL_FACE); @@ -74218,10 +74298,7 @@ const Renderer$1 = function (scene, options) { pickable.drawPickNormals(frameCtx); // Draw color-encoded fragment World-space normals - const resolutionScale = scene.canvas.resolutionScale; - const pix = pickNormalBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale), gl.RGBA_INTEGER, gl.INT, Int32Array, 4); - - pickNormalBuffer.unbind(); + const pix = pickBuffer.read(0, 0); const worldNormal = [ pix[0] / math.MAX_INT, diff --git a/dist/xeokit-sdk.es.js b/dist/xeokit-sdk.es.js index 55497f60b6..858517de51 100644 --- a/dist/xeokit-sdk.es.js +++ b/dist/xeokit-sdk.es.js @@ -23996,6 +23996,16 @@ function buildVertex$3(mesh) { src.push(" mat[2][2] =1.0;"); src.push("}"); } + + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("void main(void) {"); src.push("vec4 localPosition = vec4(position, 1.0); "); if (quantizedGeometry) { @@ -24022,7 +24032,7 @@ function buildVertex$3(mesh) { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); return src; } @@ -24225,6 +24235,8 @@ PickMeshRenderer.prototype.drawMesh = function (frameCtx, mesh) { const r = pickID & 0xFF; gl.uniform4f(this._uPickColor, r / 255, g / 255, b / 255, a / 255); + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); + if (geometryState.indicesBuf) { gl.drawElements(geometryState.primitive, geometryState.indicesBuf.numItems, geometryState.indicesBuf.itemType, 0); frameCtx.drawElements++; @@ -24258,6 +24270,7 @@ PickMeshRenderer.prototype._allocate = function (mesh) { this._aPosition = program.getAttribute("position"); this._uClippable = program.getLocation("clippable"); this._uPickColor = program.getLocation("pickColor"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uOffset = program.getLocation("offset"); if (scene.logarithmicDepthBufferEnabled ) { this._uLogDepthBufFC = program.getLocation("logDepthBufFC"); @@ -24295,8 +24308,6 @@ function buildVertex$2(mesh) { const scene = mesh.scene; const clipping = scene._sectionPlanesState.sectionPlanes.length > 0; const quantizedGeometry = !!mesh._geometry._state.compressGeometry; - mesh._state.billboard; - mesh._state.stationary; const src = []; src.push('#version 300 es'); src.push("// Surface picking vertex shader"); @@ -24318,6 +24329,16 @@ function buildVertex$2(mesh) { src.push("}"); src.push("out float isPerspective;"); } + + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("out vec4 vColor;"); if (quantizedGeometry) { src.push("uniform mat4 positionsDecodeMatrix;"); @@ -24339,7 +24360,7 @@ function buildVertex$2(mesh) { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); return src; } @@ -24532,6 +24553,9 @@ PickTriangleRenderer.prototype.drawMesh = function (frameCtx, mesh) { } else { this._aPosition.bindArrayBuffer(positionsBuf); } + + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); + pickColorsBuf.bind(); gl.enableVertexAttribArray(this._aColor.location); gl.vertexAttribPointer(this._aColor.location, pickColorsBuf.itemSize, pickColorsBuf.itemType, true, 0, 0); // Normalize @@ -24563,6 +24587,7 @@ PickTriangleRenderer.prototype._allocate = function (mesh) { } this._aPosition = program.getAttribute("position"); this._aColor = program.getAttribute("color"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uClippable = program.getLocation("clippable"); this._uOffset = program.getLocation("offset"); if (scene.logarithmicDepthBufferEnabled ) { @@ -34353,7 +34378,7 @@ class RenderBuffer { read(pickX, pickY, glFormat = null, glType = null, arrayType = Uint8Array, arrayMultiplier = 4) { const x = pickX; - const y = (this.buffer.height || this.gl.drawingBufferHeight) - pickY; + const y = this.buffer.height ? (this.buffer.height - pickY - 1) : (this.gl.drawingBufferHeight - pickY); const pix = new arrayType(arrayMultiplier); const gl = this.gl; gl.readPixels(x, y, 1, 1, glFormat || gl.RGBA, glType || gl.UNSIGNED_BYTE, pix, 0); @@ -37541,7 +37566,6 @@ const edgesDefaultColor = new Float32Array([0, 0, 0, 1]); const tempVec4 = math.vec4(); const tempVec3a$w = math.vec3(); -math.vec3(); const tempVec3c$n = math.vec3(); const tempMat4a$f = math.mat4(); @@ -37614,6 +37638,18 @@ class VBOSceneModelRenderer { return src; } + _addRemapClipPosLines(src) { + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + return src; + } + getValid() { return this._hash === this._getHash(); } @@ -37747,6 +37783,7 @@ class VBOSceneModelRenderer { this._aPickColor = program.getAttribute("pickColor"); this._uPickZNear = program.getLocation("pickZNear"); this._uPickZFar = program.getLocation("pickZFar"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uColorMap = "uColorMap"; this._uMetallicRoughMap = "uMetallicRoughMap"; @@ -37787,7 +37824,6 @@ class VBOSceneModelRenderer { const program = this._program; const lightsState = scene._lightsState; const lights = lightsState.lights; - const project = scene.camera.project; program.bind(); @@ -37814,43 +37850,6 @@ class VBOSceneModelRenderer { gl.uniform3fv(this._uLightDir[i], light.dir); } } - - if (this._withSAO) { - const sao = scene.sao; - const saoEnabled = sao.possible; - if (saoEnabled) { - const viewportWidth = gl.drawingBufferWidth; - const viewportHeight = gl.drawingBufferHeight; - tempVec4[0] = viewportWidth; - tempVec4[1] = viewportHeight; - tempVec4[2] = sao.blendCutoff; - tempVec4[3] = sao.blendFactor; - gl.uniform4fv(this._uSAOParams, tempVec4); - this._program.bindTexture(this._uOcclusionTexture, frameCtx.occlusionTexture, 0); - } - } - - if (scene.logarithmicDepthBufferEnabled) { - const logDepthBufFC = 2.0 / (Math.log(project.far + 1.0) / Math.LN2); - gl.uniform1f(this._uLogDepthBufFC, logDepthBufFC); - } - - if (this._uGammaFactor) { - gl.uniform1f(this._uGammaFactor, scene.gammaFactor); - } - - if (this._uPickInvisible) { - gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible); - } - - - if (this._uShadowViewMatrix) { - gl.uniformMatrix4fv(this._uShadowViewMatrix, false, frameCtx.shadowViewMatrix); - } - - if (this._uShadowProjMatrix) { - gl.uniformMatrix4fv(this._uShadowProjMatrix, false, frameCtx.shadowProjMatrix); - } } _makeVAO(state) { @@ -38047,6 +38046,10 @@ class VBOSceneModelRenderer { gl.uniform1f(this._uPickZFar, frameCtx.pickZFar); } + if (this._uPickClipPos) { + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); + } + if (this._uPositionsDecodeMatrix) { gl.uniformMatrix4fv(this._uPositionsDecodeMatrix, false, state.positionsDecodeMatrix); } @@ -39226,6 +39229,8 @@ class TrianglesBatchingPickMeshRenderer extends VBOSceneModelTriangleBatchingRen src.push("out float vFlags;"); } + this._addRemapClipPosLines(src); + src.push("out vec4 vPickColor;"); src.push("void main(void) {"); @@ -39253,7 +39258,7 @@ class TrianglesBatchingPickMeshRenderer extends VBOSceneModelTriangleBatchingRen src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -39352,6 +39357,9 @@ class TrianglesBatchingPickDepthRenderer extends VBOSceneModelTriangleBatchingRe src.push("out vec4 vWorldPosition;"); src.push("out float vFlags;"); } + + this._addRemapClipPosLines(src); + src.push("out vec4 vViewPosition;"); src.push("void main(void) {"); @@ -39377,7 +39385,7 @@ class TrianglesBatchingPickDepthRenderer extends VBOSceneModelTriangleBatchingRe src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -39475,6 +39483,8 @@ class TrianglesBatchingPickNormalsRenderer extends VBOSceneModelTriangleBatching this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -39519,7 +39529,7 @@ class TrianglesBatchingPickNormalsRenderer extends VBOSceneModelTriangleBatching src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -40622,6 +40632,8 @@ class TrianglesBatchingPickNormalsFlatRenderer extends VBOSceneModelTriangleBatc this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -40655,7 +40667,7 @@ class TrianglesBatchingPickNormalsFlatRenderer extends VBOSceneModelTriangleBatc src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -44351,6 +44363,8 @@ class TrianglesInstancingPickMeshRenderer extends VBOSceneModelTriangleInstancin this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -44395,7 +44409,7 @@ class TrianglesInstancingPickMeshRenderer extends VBOSceneModelTriangleInstancin src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); return src; @@ -44485,6 +44499,8 @@ class TrianglesInstancingPickDepthRenderer extends VBOSceneModelTriangleInstanci this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -44527,7 +44543,7 @@ class TrianglesInstancingPickDepthRenderer extends VBOSceneModelTriangleInstanci src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); return src; @@ -44630,6 +44646,8 @@ class TrianglesInstancingPickNormalsRenderer extends VBOSceneModelTriangleInstan this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -44678,7 +44696,7 @@ class TrianglesInstancingPickNormalsRenderer extends VBOSceneModelTriangleInstan src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); return src; @@ -45796,6 +45814,8 @@ class TrianglesInstancingPickNormalsFlatRenderer extends VBOSceneModelTriangleIn this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + if (scene.logarithmicDepthBufferEnabled) { src.push("uniform float logDepthBufFC;"); src.push("out float vFragDepth;"); @@ -45834,7 +45854,7 @@ class TrianglesInstancingPickNormalsFlatRenderer extends VBOSceneModelTriangleIn src.push("vFlags = flags;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); return src; @@ -50718,6 +50738,8 @@ class PointsBatchingPickMeshRenderer extends VBOSceneModelPointBatchingRenderer this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + src.push("uniform float pointSize;"); if (pointsMaterial.perspectivePoints) { src.push("uniform float nearPlaneHeight;"); @@ -50759,7 +50781,7 @@ class PointsBatchingPickMeshRenderer extends VBOSceneModelPointBatchingRenderer if (scene.logarithmicDepthBufferEnabled) { src.push("vFragDepth = 1.0 + clipPos.w;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (pointsMaterial.perspectivePoints) { src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"); src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);"); @@ -50858,6 +50880,8 @@ class PointsBatchingPickDepthRenderer extends VBOSceneModelPointBatchingRenderer this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + src.push("uniform float pointSize;"); if (pointsMaterial.perspectivePoints) { src.push("uniform float nearPlaneHeight;"); @@ -50896,7 +50920,7 @@ class PointsBatchingPickDepthRenderer extends VBOSceneModelPointBatchingRenderer if (scene.logarithmicDepthBufferEnabled) { src.push("vFragDepth = 1.0 + clipPos.w;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (pointsMaterial.perspectivePoints) { src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"); src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);"); @@ -52341,6 +52365,8 @@ class PointsInstancingPickMeshRenderer extends VBOSceneModelPointInstancingRende this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + src.push("uniform float pointSize;"); if (pointsMaterial.perspectivePoints) { src.push("uniform float nearPlaneHeight;"); @@ -52382,6 +52408,7 @@ class PointsInstancingPickMeshRenderer extends VBOSceneModelPointInstancingRende src.push(" vFlags = flags;"); } src.push("vec4 clipPos = projMatrix * viewPosition;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (scene.logarithmicDepthBufferEnabled) { src.push("vFragDepth = 1.0 + clipPos.w;"); } @@ -52492,6 +52519,8 @@ class PointsInstancingPickDepthRenderer extends VBOSceneModelPointInstancingRend this._addMatricesUniformBlockLines(src); + this._addRemapClipPosLines(src); + src.push("uniform float pointSize;"); if (pointsMaterial.perspectivePoints) { src.push("uniform float nearPlaneHeight;"); @@ -52531,10 +52560,11 @@ class PointsInstancingPickDepthRenderer extends VBOSceneModelPointInstancingRend } src.push(" vViewPosition = viewPosition;"); src.push("vec4 clipPos = projMatrix * viewPosition;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (scene.logarithmicDepthBufferEnabled) { src.push("vFragDepth = 1.0 + clipPos.w;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); if (pointsMaterial.perspectivePoints) { src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"); src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);"); @@ -57325,7 +57355,7 @@ class TrianglesDataTexturePickMeshRenderer { getValid() { return this._hash === this._getHash(); - }; + } _getHash() { return this._scene._sectionPlanesState.getHash(); @@ -57386,6 +57416,7 @@ class TrianglesDataTexturePickMeshRenderer { rtcViewMatrix = camera.viewMatrix; rtcCameraEye = camera.eye; } + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); gl.uniformMatrix4fv(this._uSceneModelWorldMatrix, false, rotationMatrixConjugate); gl.uniformMatrix4fv(this._uViewMatrix, false, rtcViewMatrix); gl.uniformMatrix4fv(this._uProjMatrix, false, camera.projMatrix); @@ -57459,6 +57490,7 @@ class TrianglesDataTexturePickMeshRenderer { const program = this._program; this._uRenderPass = program.getLocation("renderPass"); this._uPickInvisible = program.getLocation("pickInvisible"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uSceneModelWorldMatrix = program.getLocation("sceneModelWorldMatrix"); this._uViewMatrix = program.getLocation("viewMatrix"); this._uProjMatrix = program.getLocation("projMatrix"); @@ -57556,6 +57588,15 @@ class TrianglesDataTexturePickMeshRenderer { src.push("out float isPerspective;"); } + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("bool isPerspectiveMatrix(mat4 m) {"); src.push(" return (m[2][3] == - 1.0);"); src.push("}"); @@ -57666,7 +57707,7 @@ class TrianglesDataTexturePickMeshRenderer { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -57755,7 +57796,7 @@ class TrianglesDataTexturePickDepthRenderer { getValid() { return this._hash === this._getHash(); - }; + } _getHash() { return this._scene._sectionPlanesState.getHash(); @@ -57829,6 +57870,7 @@ class TrianglesDataTexturePickDepthRenderer { gl.uniform3fv(this._uCameraEyeRtc, rtcCameraEye); gl.uniform1i(this._uRenderPass, renderPass); gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible); + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); gl.uniform1f(this._uPickZNear, frameCtx.pickZNear); gl.uniform1f(this._uPickZFar, frameCtx.pickZFar); gl.uniformMatrix4fv(this._uWorldMatrix, false, rotationMatrixConjugate); @@ -57903,6 +57945,7 @@ class TrianglesDataTexturePickDepthRenderer { const program = this._program; this._uRenderPass = program.getLocation("renderPass"); this._uPickInvisible = program.getLocation("pickInvisible"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uWorldMatrix = program.getLocation("worldMatrix"); this._uViewMatrix = program.getLocation("viewMatrix"); this._uProjMatrix = program.getLocation("projMatrix"); @@ -57992,6 +58035,15 @@ class TrianglesDataTexturePickDepthRenderer { src.push("out float isPerspective;"); } + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("bool isPerspectiveMatrix(mat4 m) {"); src.push(" return (m[2][3] == - 1.0);"); src.push("}"); @@ -58098,7 +58150,7 @@ class TrianglesDataTexturePickDepthRenderer { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -59059,7 +59111,7 @@ class TrianglesDataTexturePickNormalsRenderer { getValid() { return this._hash === this._getHash(); - }; + } _getHash() { return this._scene._sectionPlanesState.getHash(); @@ -59117,6 +59169,7 @@ class TrianglesDataTexturePickNormalsRenderer { gl.uniform3fv(this._uCameraEyeRtc, originCameraEye); gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible); + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); if (scene.logarithmicDepthBufferEnabled) { const logDepthBufFC = 2.0 / (Math.log(camera.project.far + 1.0) / Math.LN2); // TODO: Far should be from projection matrix? @@ -59199,6 +59252,7 @@ class TrianglesDataTexturePickNormalsRenderer { this._uRenderPass = program.getLocation("renderPass"); this._uPickInvisible = program.getLocation("pickInvisible"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uSectionPlanes = []; @@ -59283,6 +59337,15 @@ class TrianglesDataTexturePickNormalsRenderer { src.push("out float isPerspective;"); } + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("bool isPerspectiveMatrix(mat4 m) {"); src.push(" return (m[2][3] == - 1.0);"); src.push("}"); @@ -59397,7 +59460,7 @@ class TrianglesDataTexturePickNormalsRenderer { src.push(" vWorldPosition = worldPosition;"); src.push(" vFlags2 = flags2.w;"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push("}"); src.push("}"); @@ -60692,7 +60755,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer { getValid() { return this._hash === this._getHash(); - }; + } _getHash() { return this._scene._sectionPlanesState.getHash(); @@ -60765,6 +60828,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer { gl.uniform1i(this._uRenderPass, renderPass); gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible); + gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos); gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix); @@ -60933,6 +60997,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer { this._uRenderPass = program.getLocation("renderPass"); this._uPickInvisible = program.getLocation("pickInvisible"); + this._uPickClipPos = program.getLocation("pickClipPos"); this._uPositionsDecodeMatrix = program.getLocation("positionsDecodeMatrix"); this._uWorldMatrix = program.getLocation("worldMatrix"); this._uViewMatrix = program.getLocation("viewMatrix"); @@ -61022,6 +61087,16 @@ class TrianglesDataTexturePickNormalsFlatRenderer { src.push("}"); src.push("out float isPerspective;"); } + + src.push("uniform vec2 pickClipPos;"); + + src.push("vec4 remapClipPos(vec4 clipPos) {"); + src.push(" clipPos.xy /= clipPos.w;"); + src.push(" clipPos.xy -= pickClipPos;"); + src.push(" clipPos.xy *= clipPos.w;"); + src.push(" return clipPos;"); + src.push("}"); + src.push("out vec4 vWorldPosition;"); if (clipping) { src.push("out int vFlags2;"); @@ -61100,7 +61175,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer { src.push("vFragDepth = 1.0 + clipPos.w;"); src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"); } - src.push("gl_Position = clipPos;"); + src.push("gl_Position = remapClipPos(clipPos);"); src.push(" }"); src.push("}"); return src; @@ -73626,10 +73701,10 @@ const Renderer$1 = function (scene, options) { * Picks an Entity. * @private */ - this.pick = (function () { + this.pick = (function () { const tempVec3a = math.vec3(); - const tempMat4a = math.mat4(); + math.mat4(); const tempMat4b = math.mat4(); const randomVec3 = math.vec3(); @@ -73671,13 +73746,11 @@ const Renderer$1 = function (scene, options) { // Picking with arbitrary World-space ray // Align camera along ray and fire ray through center of canvas - - const pickFrustumMatrix = math.frustumMat4(-1, 1, -1, 1, 0.01, scene.camera.project.far, tempMat4a); - + if (params.matrix) { pickViewMatrix = params.matrix; - pickProjMatrix = pickFrustumMatrix; + pickProjMatrix = scene.camera.projMatrix; } else { @@ -73694,7 +73767,7 @@ const Renderer$1 = function (scene, options) { math.cross3Vec3(worldRayDir, randomVec3, up); pickViewMatrix = math.lookAtMat4v(worldRayOrigin, look, up, tempMat4b); - pickProjMatrix = pickFrustumMatrix; + pickProjMatrix = scene.camera.projMatrix; pickResult.origin = worldRayOrigin; pickResult.direction = worldRayDir; @@ -73716,7 +73789,7 @@ const Renderer$1 = function (scene, options) { } } - const pickBuffer = renderBufferManager.getRenderBuffer("pick"); + const pickBuffer = renderBufferManager.getRenderBuffer("pick", { size: [1, 1] }); pickBuffer.bind(); @@ -73778,10 +73851,12 @@ const Renderer$1 = function (scene, options) { frameCtx.pickViewMatrix = pickViewMatrix; frameCtx.pickProjMatrix = pickProjMatrix; frameCtx.pickInvisible = !!params.pickInvisible; + frameCtx.pickClipPos = [ + getClipPosX(canvasPos[0], gl.drawingBufferWidth), + getClipPosY(canvasPos[1], gl.drawingBufferHeight), + ]; - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); - - gl.clearColor(0, 0, 0, 0); + gl.viewport(0, 0, 1, 1); gl.depthMask(true); gl.enable(gl.DEPTH_TEST); gl.disable(gl.CULL_FACE); @@ -73815,8 +73890,7 @@ const Renderer$1 = function (scene, options) { } } } - const resolutionScale = scene.canvas.resolutionScale; - const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale)); + const pix = pickBuffer.read(0, 0); let pickID = pix[0] + (pix[1] * 256) + (pix[2] * 256 * 256) + (pix[3] * 256 * 256 * 256); if (pickID < 0) { @@ -73841,8 +73915,12 @@ const Renderer$1 = function (scene, options) { frameCtx.pickViewMatrix = pickViewMatrix; // Can be null frameCtx.pickProjMatrix = pickProjMatrix; // Can be null // frameCtx.pickInvisible = !!params.pickInvisible; + frameCtx.pickClipPos = [ + getClipPosX(canvasPos[0], gl.drawingBufferWidth), + getClipPosY(canvasPos[1], gl.drawingBufferHeight), + ]; - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); + gl.viewport(0, 0, 1, 1); gl.clearColor(0, 0, 0, 0); gl.enable(gl.DEPTH_TEST); @@ -73852,8 +73930,7 @@ const Renderer$1 = function (scene, options) { pickable.drawPickTriangles(frameCtx); - const resolutionScale = scene.canvas.resolutionScale; - const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale)); + const pix = pickBuffer.read(0, 0); let primIndex = pix[0] + (pix[1] * 256) + (pix[2] * 256 * 256) + (pix[3] * 256 * 256 * 256); @@ -73885,8 +73962,12 @@ const Renderer$1 = function (scene, options) { frameCtx.pickZFar = nearAndFar[1]; frameCtx.pickElementsCount = pickable.pickElementsCount; frameCtx.pickElementsOffset = pickable.pickElementsOffset; - - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); + frameCtx.pickClipPos = [ + getClipPosX(canvasPos[0], gl.drawingBufferWidth), + getClipPosY(canvasPos[1], gl.drawingBufferHeight), + ]; + + gl.viewport(0, 0, 1, 1); gl.clearColor(0, 0, 0, 0); gl.depthMask(true); @@ -73897,8 +73978,7 @@ const Renderer$1 = function (scene, options) { pickable.drawPickDepths(frameCtx); // Draw color-encoded fragment screen-space depths - const resolutionScale = scene.canvas.resolutionScale; - const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale)); + const pix = pickBuffer.read(0, 0); const screenZ = unpackDepth(pix); // Get screen-space Z at the given canvas coords @@ -74199,12 +74279,12 @@ const Renderer$1 = function (scene, options) { frameCtx.pickOrigin = pickResult.origin; frameCtx.pickViewMatrix = pickViewMatrix; frameCtx.pickProjMatrix = pickProjMatrix; + frameCtx.pickClipPos = [ + getClipPosX(canvasPos[0], gl.drawingBufferWidth), + getClipPosY(canvasPos[1], gl.drawingBufferHeight), + ]; - const pickNormalBuffer = renderBufferManager.getRenderBuffer("pick-normal"); - - pickNormalBuffer.bind(gl.RGBA32I); - - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); + gl.viewport(0, 0, 1, 1); gl.enable(gl.DEPTH_TEST); gl.disable(gl.CULL_FACE); @@ -74214,10 +74294,7 @@ const Renderer$1 = function (scene, options) { pickable.drawPickNormals(frameCtx); // Draw color-encoded fragment World-space normals - const resolutionScale = scene.canvas.resolutionScale; - const pix = pickNormalBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale), gl.RGBA_INTEGER, gl.INT, Int32Array, 4); - - pickNormalBuffer.unbind(); + const pix = pickBuffer.read(0, 0); const worldNormal = [ pix[0] / math.MAX_INT, diff --git a/dist/xeokit-sdk.es5.js b/dist/xeokit-sdk.es5.js index b103ed0711..caffb78676 100644 --- a/dist/xeokit-sdk.es5.js +++ b/dist/xeokit-sdk.es5.js @@ -5052,20 +5052,20 @@ var indicesBuf;if(geometryState.primitive===gl.TRIANGLES){indicesBuf=geometry._g * @author xeolabs / https://github.com/xeolabs */ /** * @private - */var PickMeshShaderSource=/*#__PURE__*/_createClass(function PickMeshShaderSource(mesh){_classCallCheck(this,PickMeshShaderSource);this.vertex=buildVertex$3(mesh);this.fragment=buildFragment$3(mesh);});function buildVertex$3(mesh){var scene=mesh.scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;var billboard=mesh._state.billboard;var stationary=mesh._state.stationary;var src=[];src.push('#version 300 es');src.push("// Mesh picking vertex shader");src.push("in vec3 position;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("out vec4 vViewPosition;");src.push("uniform vec3 offset;");if(quantizedGeometry){src.push("uniform mat4 positionsDecodeMatrix;");}if(clipping){src.push("out vec4 vWorldPosition;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(billboard==="spherical"||billboard==="cylindrical"){src.push("void billboard(inout mat4 mat) {");src.push(" mat[0][0] = 1.0;");src.push(" mat[0][1] = 0.0;");src.push(" mat[0][2] = 0.0;");if(billboard==="spherical"){src.push(" mat[1][0] = 0.0;");src.push(" mat[1][1] = 1.0;");src.push(" mat[1][2] = 0.0;");}src.push(" mat[2][0] = 0.0;");src.push(" mat[2][1] = 0.0;");src.push(" mat[2][2] =1.0;");src.push("}");}src.push("void main(void) {");src.push("vec4 localPosition = vec4(position, 1.0); ");if(quantizedGeometry){src.push("localPosition = positionsDecodeMatrix * localPosition;");}src.push("mat4 viewMatrix2 = viewMatrix;");src.push("mat4 modelMatrix2 = modelMatrix;");if(stationary){src.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");}if(billboard==="spherical"||billboard==="cylindrical"){src.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;");src.push("billboard(modelMatrix2);");src.push("billboard(viewMatrix2);");}src.push(" vec4 worldPosition = modelMatrix2 * localPosition;");src.push(" worldPosition.xyz = worldPosition.xyz + offset;");src.push(" vec4 viewPosition = viewMatrix2 * worldPosition;");if(clipping){src.push(" vWorldPosition = worldPosition;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");return src;}function buildFragment$3(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Mesh picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform vec4 pickColor;");if(clipping){src.push("uniform bool clippable;");src.push("in vec4 vWorldPosition;");for(var i=0;i 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = pickColor; ");src.push("}");return src;}/** + */var PickMeshShaderSource=/*#__PURE__*/_createClass(function PickMeshShaderSource(mesh){_classCallCheck(this,PickMeshShaderSource);this.vertex=buildVertex$3(mesh);this.fragment=buildFragment$3(mesh);});function buildVertex$3(mesh){var scene=mesh.scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;var billboard=mesh._state.billboard;var stationary=mesh._state.stationary;var src=[];src.push('#version 300 es');src.push("// Mesh picking vertex shader");src.push("in vec3 position;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("out vec4 vViewPosition;");src.push("uniform vec3 offset;");if(quantizedGeometry){src.push("uniform mat4 positionsDecodeMatrix;");}if(clipping){src.push("out vec4 vWorldPosition;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(billboard==="spherical"||billboard==="cylindrical"){src.push("void billboard(inout mat4 mat) {");src.push(" mat[0][0] = 1.0;");src.push(" mat[0][1] = 0.0;");src.push(" mat[0][2] = 0.0;");if(billboard==="spherical"){src.push(" mat[1][0] = 0.0;");src.push(" mat[1][1] = 1.0;");src.push(" mat[1][2] = 0.0;");}src.push(" mat[2][0] = 0.0;");src.push(" mat[2][1] = 0.0;");src.push(" mat[2][2] =1.0;");src.push("}");}src.push("uniform vec2 pickClipPos;");src.push("vec4 remapClipPos(vec4 clipPos) {");src.push(" clipPos.xy /= clipPos.w;");src.push(" clipPos.xy -= pickClipPos;");src.push(" clipPos.xy *= clipPos.w;");src.push(" return clipPos;");src.push("}");src.push("void main(void) {");src.push("vec4 localPosition = vec4(position, 1.0); ");if(quantizedGeometry){src.push("localPosition = positionsDecodeMatrix * localPosition;");}src.push("mat4 viewMatrix2 = viewMatrix;");src.push("mat4 modelMatrix2 = modelMatrix;");if(stationary){src.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");}if(billboard==="spherical"||billboard==="cylindrical"){src.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;");src.push("billboard(modelMatrix2);");src.push("billboard(viewMatrix2);");}src.push(" vec4 worldPosition = modelMatrix2 * localPosition;");src.push(" worldPosition.xyz = worldPosition.xyz + offset;");src.push(" vec4 viewPosition = viewMatrix2 * worldPosition;");if(clipping){src.push(" vWorldPosition = worldPosition;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push("}");return src;}function buildFragment$3(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Mesh picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform vec4 pickColor;");if(clipping){src.push("uniform bool clippable;");src.push("in vec4 vWorldPosition;");for(var i=0;i 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = pickColor; ");src.push("}");return src;}/** * @author xeolabs / https://github.com/xeolabs */var tempVec3a$A=math.vec3();// No ID, because there is exactly one PickMeshRenderer per scene /** * @private */var PickMeshRenderer=function PickMeshRenderer(hash,mesh){this._hash=hash;this._shaderSource=new PickMeshShaderSource(mesh);this._scene=mesh.scene;this._useCount=0;this._allocate(mesh);};var renderers$3={};PickMeshRenderer.get=function(mesh){var hash=[mesh.scene.canvas.canvas.id,mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.hash,mesh._state.hash].join(";");var renderer=renderers$3[hash];if(!renderer){renderer=new PickMeshRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}renderers$3[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};PickMeshRenderer.prototype.put=function(){if(--this._useCount===0){if(this._program){this._program.destroy();}delete renderers$3[this._hash];stats.memory.programs--;}};PickMeshRenderer.prototype.webglContextRestored=function(){this._program=null;};PickMeshRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var scene=this._scene;var gl=scene.canvas.gl;var meshState=mesh._state;var materialState=mesh._material._state;var geometryState=mesh._geometry._state;var origin=mesh.origin;if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCPickViewMatrix(meshState.originHash,origin):frameCtx.pickViewMatrix);if(meshState.clippable){var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex>24&0xFF;var b=pickID>>16&0xFF;var g=pickID>>8&0xFF;var r=pickID&0xFF;gl.uniform4f(this._uPickColor,r/255,g/255,b/255,a/255);if(geometryState.indicesBuf){gl.drawElements(geometryState.primitive,geometryState.indicesBuf.numItems,geometryState.indicesBuf.itemType,0);frameCtx.drawElements++;}else if(geometryState.positions){gl.drawArrays(gl.TRIANGLES,0,geometryState.positions.numItems);}};PickMeshRenderer.prototype._allocate=function(mesh){var scene=mesh.scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._shaderSource);if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uModelMatrix=program.getLocation("modelMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=scene._sectionPlanesState.sectionPlanes;for(var _i98=0,len=clips.length;_i98>24&0xFF;var b=pickID>>16&0xFF;var g=pickID>>8&0xFF;var r=pickID&0xFF;gl.uniform4f(this._uPickColor,r/255,g/255,b/255,a/255);gl.uniform2fv(this._uPickClipPos,frameCtx.pickClipPos);if(geometryState.indicesBuf){gl.drawElements(geometryState.primitive,geometryState.indicesBuf.numItems,geometryState.indicesBuf.itemType,0);frameCtx.drawElements++;}else if(geometryState.positions){gl.drawArrays(gl.TRIANGLES,0,geometryState.positions.numItems);}};PickMeshRenderer.prototype._allocate=function(mesh){var scene=mesh.scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._shaderSource);if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uModelMatrix=program.getLocation("modelMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];var clips=scene._sectionPlanesState.sectionPlanes;for(var _i98=0,len=clips.length;_i980;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;mesh._state.billboard;mesh._state.stationary;var src=[];src.push('#version 300 es');src.push("// Surface picking vertex shader");src.push("in vec3 position;");src.push("in vec4 color;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform vec3 offset;");if(clipping){src.push("uniform bool clippable;");src.push("out vec4 vWorldPosition;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("out vec4 vColor;");if(quantizedGeometry){src.push("uniform mat4 positionsDecodeMatrix;");}src.push("void main(void) {");src.push("vec4 localPosition = vec4(position, 1.0); ");if(quantizedGeometry){src.push("localPosition = positionsDecodeMatrix * localPosition;");}src.push(" vec4 worldPosition = modelMatrix * localPosition; ");src.push(" worldPosition.xyz = worldPosition.xyz + offset;");src.push(" vec4 viewPosition = viewMatrix * worldPosition;");if(clipping){src.push(" vWorldPosition = worldPosition;");}src.push(" vColor = color;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");return src;}function buildFragment$2(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Surface picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");src.push("in vec4 vColor;");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("uniform bool clippable;");src.push("in vec4 vWorldPosition;");for(var _i99=0;_i99 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vColor;");src.push("}");return src;}/** + */var PickTriangleShaderSource=/*#__PURE__*/_createClass(function PickTriangleShaderSource(mesh){_classCallCheck(this,PickTriangleShaderSource);this.vertex=buildVertex$2(mesh);this.fragment=buildFragment$2(mesh);});function buildVertex$2(mesh){var scene=mesh.scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var quantizedGeometry=!!mesh._geometry._state.compressGeometry;var src=[];src.push('#version 300 es');src.push("// Surface picking vertex shader");src.push("in vec3 position;");src.push("in vec4 color;");src.push("uniform mat4 modelMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform vec3 offset;");if(clipping){src.push("uniform bool clippable;");src.push("out vec4 vWorldPosition;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("uniform vec2 pickClipPos;");src.push("vec4 remapClipPos(vec4 clipPos) {");src.push(" clipPos.xy /= clipPos.w;");src.push(" clipPos.xy -= pickClipPos;");src.push(" clipPos.xy *= clipPos.w;");src.push(" return clipPos;");src.push("}");src.push("out vec4 vColor;");if(quantizedGeometry){src.push("uniform mat4 positionsDecodeMatrix;");}src.push("void main(void) {");src.push("vec4 localPosition = vec4(position, 1.0); ");if(quantizedGeometry){src.push("localPosition = positionsDecodeMatrix * localPosition;");}src.push(" vec4 worldPosition = modelMatrix * localPosition; ");src.push(" worldPosition.xyz = worldPosition.xyz + offset;");src.push(" vec4 viewPosition = viewMatrix * worldPosition;");if(clipping){src.push(" vWorldPosition = worldPosition;");}src.push(" vColor = color;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push("}");return src;}function buildFragment$2(mesh){var scene=mesh.scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Surface picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");src.push("in vec4 vColor;");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("uniform bool clippable;");src.push("in vec4 vWorldPosition;");for(var _i99=0;_i99 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vColor;");src.push("}");return src;}/** * @author xeolabs / https://github.com/xeolabs */var tempVec3a$z=math.vec3();/** * @private - */var PickTriangleRenderer=function PickTriangleRenderer(hash,mesh){this._hash=hash;this._scene=mesh.scene;this._useCount=0;this._shaderSource=new PickTriangleShaderSource(mesh);this._allocate(mesh);};var renderers$2={};PickTriangleRenderer.get=function(mesh){var hash=[mesh.scene.canvas.canvas.id,mesh.scene._sectionPlanesState.getHash(),mesh._geometry._state.compressGeometry?"cp":"",mesh._state.hash].join(";");var renderer=renderers$2[hash];if(!renderer){renderer=new PickTriangleRenderer(hash,mesh);if(renderer.errors){console.log(renderer.errors.join("\n"));return null;}renderers$2[hash]=renderer;stats.memory.programs++;}renderer._useCount++;return renderer;};PickTriangleRenderer.prototype.put=function(){if(--this._useCount===0){if(this._program){this._program.destroy();}delete renderers$2[this._hash];stats.memory.programs--;}};PickTriangleRenderer.prototype.webglContextRestored=function(){this._program=null;};PickTriangleRenderer.prototype.drawMesh=function(frameCtx,mesh){if(!this._program){this._allocate(mesh);}var scene=this._scene;var gl=scene.canvas.gl;var meshState=mesh._state;var materialState=mesh._material._state;var geometry=mesh._geometry;var geometryState=mesh._geometry._state;var origin=mesh.origin;var backfaces=materialState.backfaces;var frontface=materialState.frontface;var project=scene.camera.project;var positionsBuf=geometry._getPickTrianglePositions();var pickColorsBuf=geometry._getPickTriangleColors();this._program.bind();frameCtx.useProgram++;if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(project.far+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}gl.uniformMatrix4fv(this._uViewMatrix,false,origin?frameCtx.getRTCPickViewMatrix(meshState.originHash,origin):frameCtx.pickViewMatrix);if(meshState.clippable){var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var renderFlags=mesh.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0&&arguments[0]!==undefined?arguments[0]:null;var width;var height;/** * @type {WebGL2RenderingContext} */var gl=this.gl;if(this.size){width=this.size[0];height=this.size[1];}else{width=gl.drawingBufferWidth;height=gl.drawingBufferHeight;}if(this.buffer){if(this.buffer.width===width&&this.buffer.height===height){return;}else{gl.deleteTexture(this.buffer.texture);gl.deleteFramebuffer(this.buffer.framebuf);gl.deleteRenderbuffer(this.buffer.renderbuf);}}var colorTexture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,colorTexture);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);if(!internalformat){gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,width,height,0,gl.RGBA,gl.UNSIGNED_BYTE,null);}else{gl.texStorage2D(gl.TEXTURE_2D,1,internalformat,width,height);}var depthTexture;if(this._hasDepthTexture){depthTexture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,depthTexture);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.NEAREST);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.texImage2D(gl.TEXTURE_2D,0,gl.DEPTH_COMPONENT32F,width,height,0,gl.DEPTH_COMPONENT,gl.FLOAT,null);}var renderbuf=gl.createRenderbuffer();gl.bindRenderbuffer(gl.RENDERBUFFER,renderbuf);gl.renderbufferStorage(gl.RENDERBUFFER,gl.DEPTH_COMPONENT32F,width,height);var framebuf=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,framebuf);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,colorTexture,0);if(this._hasDepthTexture){gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.DEPTH_ATTACHMENT,gl.TEXTURE_2D,depthTexture,0);}else{gl.framebufferRenderbuffer(gl.FRAMEBUFFER,gl.DEPTH_ATTACHMENT,gl.RENDERBUFFER,renderbuf);}gl.bindTexture(gl.TEXTURE_2D,null);gl.bindRenderbuffer(gl.RENDERBUFFER,null);gl.bindFramebuffer(gl.FRAMEBUFFER,null);// Verify framebuffer is OK -gl.bindFramebuffer(gl.FRAMEBUFFER,framebuf);if(!gl.isFramebuffer(framebuf)){throw"Invalid framebuffer";}gl.bindFramebuffer(gl.FRAMEBUFFER,null);var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);switch(status){case gl.FRAMEBUFFER_COMPLETE:break;case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case gl.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+status;}this.buffer={framebuf:framebuf,renderbuf:renderbuf,texture:colorTexture,depthTexture:depthTexture,width:width,height:height};this.bound=false;}},{key:"clear",value:function clear(){if(!this.bound){throw"Render buffer not bound";}var gl=this.gl;gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);}},{key:"read",value:function read(pickX,pickY){var glFormat=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;var glType=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var arrayType=arguments.length>4&&arguments[4]!==undefined?arguments[4]:Uint8Array;var arrayMultiplier=arguments.length>5&&arguments[5]!==undefined?arguments[5]:4;var x=pickX;var y=(this.buffer.height||this.gl.drawingBufferHeight)-pickY;var pix=new arrayType(arrayMultiplier);var gl=this.gl;gl.readPixels(x,y,1,1,glFormat||gl.RGBA,glType||gl.UNSIGNED_BYTE,pix,0);return pix;}},{key:"readArray",value:function readArray(){var glFormat=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var glType=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var arrayType=arguments.length>2&&arguments[2]!==undefined?arguments[2]:Uint8Array;var arrayMultiplier=arguments.length>3&&arguments[3]!==undefined?arguments[3]:4;var pix=new arrayType(this.buffer.width*this.buffer.height*arrayMultiplier);var gl=this.gl;gl.readPixels(0,0,this.buffer.width,this.buffer.height,glFormat||gl.RGBA,glType||gl.UNSIGNED_BYTE,pix,0);return pix;}/** +gl.bindFramebuffer(gl.FRAMEBUFFER,framebuf);if(!gl.isFramebuffer(framebuf)){throw"Invalid framebuffer";}gl.bindFramebuffer(gl.FRAMEBUFFER,null);var status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);switch(status){case gl.FRAMEBUFFER_COMPLETE:break;case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case gl.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+status;}this.buffer={framebuf:framebuf,renderbuf:renderbuf,texture:colorTexture,depthTexture:depthTexture,width:width,height:height};this.bound=false;}},{key:"clear",value:function clear(){if(!this.bound){throw"Render buffer not bound";}var gl=this.gl;gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);}},{key:"read",value:function read(pickX,pickY){var glFormat=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;var glType=arguments.length>3&&arguments[3]!==undefined?arguments[3]:null;var arrayType=arguments.length>4&&arguments[4]!==undefined?arguments[4]:Uint8Array;var arrayMultiplier=arguments.length>5&&arguments[5]!==undefined?arguments[5]:4;var x=pickX;var y=this.buffer.height?this.buffer.height-pickY-1:this.gl.drawingBufferHeight-pickY;var pix=new arrayType(arrayMultiplier);var gl=this.gl;gl.readPixels(x,y,1,1,glFormat||gl.RGBA,glType||gl.UNSIGNED_BYTE,pix,0);return pix;}},{key:"readArray",value:function readArray(){var glFormat=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var glType=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var arrayType=arguments.length>2&&arguments[2]!==undefined?arguments[2]:Uint8Array;var arrayMultiplier=arguments.length>3&&arguments[3]!==undefined?arguments[3]:4;var pix=new arrayType(this.buffer.width*this.buffer.height*arrayMultiplier);var gl=this.gl;gl.readPixels(0,0,this.buffer.width,this.buffer.height,glFormat||gl.RGBA,glType||gl.UNSIGNED_BYTE,pix,0);return pix;}/** * Returns an HTMLCanvas containing the contents of the RenderBuffer as an image. * * - The HTMLCanvas has a CanvasRenderingContext2D. @@ -10072,7 +10072,7 @@ NOT_RENDERED:0,// Normal rendering - mutually exclusive modes COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,// Emphasis silhouette rendering - mutually exclusive modes SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,// Edges rendering - mutually exclusive modes EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,// Picking -PICK:11};var defaultColor$2=new Float32Array([1,1,1,1]);var edgesDefaultColor=new Float32Array([0,0,0,1]);var tempVec4=math.vec4();var tempVec3a$w=math.vec3();math.vec3();var tempVec3c$n=math.vec3();var tempMat4a$f=math.mat4();var VBOSceneModelRenderer=/*#__PURE__*/function(){function VBOSceneModelRenderer(scene){var withSAO=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var _ref6=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref6$instancing=_ref6.instancing,instancing=_ref6$instancing===void 0?false:_ref6$instancing,_ref6$edges=_ref6.edges,edges=_ref6$edges===void 0?false:_ref6$edges;_classCallCheck(this,VBOSceneModelRenderer);this._scene=scene;this._withSAO=withSAO;this._instancing=instancing;this._edges=edges;this._hash=this._getHash();/** +PICK:11};var defaultColor$2=new Float32Array([1,1,1,1]);var edgesDefaultColor=new Float32Array([0,0,0,1]);var tempVec4=math.vec4();var tempVec3a$w=math.vec3();var tempVec3c$n=math.vec3();var tempMat4a$f=math.mat4();var VBOSceneModelRenderer=/*#__PURE__*/function(){function VBOSceneModelRenderer(scene){var withSAO=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var _ref6=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref6$instancing=_ref6.instancing,instancing=_ref6$instancing===void 0?false:_ref6$instancing,_ref6$edges=_ref6.edges,edges=_ref6$edges===void 0?false:_ref6$edges;_classCallCheck(this,VBOSceneModelRenderer);this._scene=scene;this._withSAO=withSAO;this._instancing=instancing;this._edges=edges;this._hash=this._getHash();/** * Matrices Uniform Block Buffer * * In shaders, matrices in the Matrices Uniform Block MUST be set in this order: @@ -10088,10 +10088,10 @@ PICK:11};var defaultColor$2=new Float32Array([1,1,1,1]);var edgesDefaultColor=ne */this._vaoCache=new WeakMap();this._allocate();}/** * Should be overrided by subclasses if it does not only "depend" on section planes state. * @returns { string } - */_createClass(VBOSceneModelRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){return[""];}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){return[""];}},{key:"_addMatricesUniformBlockLines",value:function _addMatricesUniformBlockLines(src){var normals=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;src.push("uniform Matrices {");src.push(" mat4 worldMatrix;");src.push(" mat4 viewMatrix;");src.push(" mat4 projMatrix;");src.push(" mat4 positionsDecodeMatrix;");if(normals){src.push(" mat4 worldNormalMatrix;");src.push(" mat4 viewNormalMatrix;");}src.push("};");return src;}},{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"setSectionPlanesStateUniforms",value:function setSectionPlanesStateUniforms(layer){var scene=this._scene;var gl=scene.canvas.gl;var model=layer.model,layerIndex=layer.layerIndex;var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex1&&arguments[1]!==undefined?arguments[1]:false;src.push("uniform Matrices {");src.push(" mat4 worldMatrix;");src.push(" mat4 viewMatrix;");src.push(" mat4 projMatrix;");src.push(" mat4 positionsDecodeMatrix;");if(normals){src.push(" mat4 worldNormalMatrix;");src.push(" mat4 viewNormalMatrix;");}src.push("};");return src;}},{key:"_addRemapClipPosLines",value:function _addRemapClipPosLines(src){src.push("uniform vec2 pickClipPos;");src.push("vec4 remapClipPos(vec4 clipPos) {");src.push(" clipPos.xy /= clipPos.w;");src.push(" clipPos.xy -= pickClipPos;");src.push(" clipPos.xy *= clipPos.w;");src.push(" return clipPos;");src.push("}");return src;}},{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"setSectionPlanesStateUniforms",value:function setSectionPlanesStateUniforms(layer){var scene=this._scene;var gl=scene.canvas.gl;var model=layer.model,layerIndex=layer.layerIndex;var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0){this._uReflectionMap="reflectionMap";}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}this._uSectionPlanes=[];for(var _i120=0,_len17=scene._sectionPlanesState.sectionPlanes.length;_i120<_len17;_i120++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i120),pos:program.getLocation("sectionPlanePos"+_i120),dir:program.getLocation("sectionPlaneDir"+_i120)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aUV=program.getAttribute("uv");this._aColor=program.getAttribute("color");this._aMetallicRoughness=program.getAttribute("metallicRoughness");this._aFlags=program.getAttribute("flags");this._aPickColor=program.getAttribute("pickColor");this._uPickZNear=program.getLocation("pickZNear");this._uPickZFar=program.getLocation("pickZFar");this._uColorMap="uColorMap";this._uMetallicRoughMap="uMetallicRoughMap";this._uEmissiveMap="uEmissiveMap";this._uNormalMap="uNormalMap";this._uAOMap="uAOMap";if(this._instancing){this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._aModelNormalMatrixCol0=program.getAttribute("modelNormalMatrixCol0");this._aModelNormalMatrixCol1=program.getAttribute("modelNormalMatrixCol1");this._aModelNormalMatrixCol2=program.getAttribute("modelNormalMatrixCol2");}if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}if(scene.pointsMaterial._state.filterIntensity){this._uIntensityRange=program.getLocation("intensityRange");}this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;program.bind();frameCtx.textureUnit=0;if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,lightsState.getAmbientColorAndIntensity());}for(var _i121=0,len=lights.length;_i1213&&arguments[3]!==undefined?arguments[3]:{},_ref7$colorUniform=_ref7.colorUniform,colorUniform=_ref7$colorUniform===void 0?false:_ref7$colorUniform,_ref7$incrementDrawSt=_ref7.incrementDrawState,incrementDrawState=_ref7$incrementDrawSt===void 0?false:_ref7$incrementDrawSt;var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var scene=this._scene;var gl=scene.canvas.gl;var state=layer._state,model=layer.model;var textureSet=state.textureSet,origin=state.origin,positionsDecodeMatrix=state.positionsDecodeMatrix;var lightsState=scene._lightsState;var pointsMaterial=scene.pointsMaterial;var camera=model.scene.camera;var viewNormalMatrix=camera.viewNormalMatrix,project=camera.project;var viewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var position=model.position,rotationMatrix=model.rotationMatrix,rotationMatrixConjugate=model.rotationMatrixConjugate,worldNormalMatrix=model.worldNormalMatrix;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}if(this._vaoCache.has(layer)){gl.bindVertexArray(this._vaoCache.get(layer));}else{this._vaoCache.set(layer,this._makeVAO(state));}var offset=0;var mat4Size=4*4;this._matricesUniformBlockBufferData.set(rotationMatrixConjugate,0);var gotOrigin=origin[0]!==0||origin[1]!==0||origin[2]!==0;var gotPosition=position[0]!==0||position[1]!==0||position[2]!==0;if(gotOrigin||gotPosition){var rtcOrigin=tempVec3a$w;if(gotOrigin){var rotatedOrigin=math.transformPoint3(rotationMatrix,origin,tempVec3c$n);rtcOrigin[0]=rotatedOrigin[0];rtcOrigin[1]=rotatedOrigin[1];rtcOrigin[2]=rotatedOrigin[2];}else{rtcOrigin[0]=0;rtcOrigin[1]=0;rtcOrigin[2]=0;}rtcOrigin[0]+=position[0];rtcOrigin[1]+=position[1];rtcOrigin[2]+=position[2];this._matricesUniformBlockBufferData.set(createRTCViewMat(viewMatrix,rtcOrigin,tempMat4a$f),offset+=mat4Size);}else{this._matricesUniformBlockBufferData.set(viewMatrix,offset+=mat4Size);}this._matricesUniformBlockBufferData.set(frameCtx.pickProjMatrix||project.matrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(positionsDecodeMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(worldNormalMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(viewNormalMatrix,offset+=mat4Size);gl.bindBuffer(gl.UNIFORM_BUFFER,this._matricesUniformBlockBuffer);gl.bufferData(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,gl.DYNAMIC_DRAW);gl.bindBufferBase(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);gl.uniform1i(this._uRenderPass,renderPass);this.setSectionPlanesStateUniforms(layer);if(scene.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix? -gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}if(this._uZFar){gl.uniform1f(this._uZFar,scene.camera.project.far);}}if(this._uPickInvisible){gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);}if(this._uPickZNear){gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);}if(this._uPickZFar){gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);}if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,state.positionsDecodeMatrix);}if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,state.uvDecodeMatrix);}if(this._uIntensityRange&&pointsMaterial.filterIntensity){gl.uniform2f(this._uIntensityRange,pointsMaterial.minIntensity,pointsMaterial.maxIntensity);}if(this._uPointSize){gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);}if(this._uNearPlaneHeight){var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);}if(textureSet){var colorTexture=textureSet.colorTexture,metallicRoughnessTexture=textureSet.metallicRoughnessTexture,emissiveTexture=textureSet.emissiveTexture,normalsTexture=textureSet.normalsTexture,occlusionTexture=textureSet.occlusionTexture;if(this._uColorMap&&colorTexture){this._program.bindTexture(this._uColorMap,colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uMetallicRoughMap&&metallicRoughnessTexture){this._program.bindTexture(this._uMetallicRoughMap,metallicRoughnessTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uEmissiveMap&&emissiveTexture){this._program.bindTexture(this._uEmissiveMap,emissiveTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uNormalMap&&normalsTexture){this._program.bindTexture(this._uNormalMap,normalsTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uAOMap&&occlusionTexture){this._program.bindTexture(this._uAOMap,occlusionTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}}if(lightsState.reflectionMaps.length>0&&lightsState.reflectionMaps[0].texture&&this._uReflectionMap){this._program.bindTexture(this._uReflectionMap,lightsState.reflectionMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(lightsState.lightMaps.length>0&&lightsState.lightMaps[0].texture&&this._uLightMap){this._program.bindTexture(this._uLightMap,lightsState.lightMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4[0]=viewportWidth;tempVec4[1]=viewportHeight;tempVec4[2]=sao.blendCutoff;tempVec4[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}if(colorUniform){var colorKey=this._edges?"edgeColor":"fillColor";var alphaKey=this._edges?"edgeAlpha":"fillAlpha";if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var material=scene.xrayMaterial._state;var _color=material[colorKey];var alpha=material[alphaKey];gl.uniform4f(this._uColor,_color[0],_color[1],_color[2],alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var _material=scene.highlightMaterial._state;var _color2=_material[colorKey];var _alpha=_material[alphaKey];gl.uniform4f(this._uColor,_color2[0],_color2[1],_color2[2],_alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var _material2=scene.selectedMaterial._state;var _color3=_material2[colorKey];var _alpha2=_material2[alphaKey];gl.uniform4f(this._uColor,_color3[0],_color3[1],_color3[2],_alpha2);}else{gl.uniform4fv(this._uColor,this._edges?edgesDefaultColor:defaultColor$2);}}this._draw({state:state,frameCtx:frameCtx,incrementDrawState:incrementDrawState});gl.bindVertexArray(null);}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;stats.memory.programs--;}}]);return VBOSceneModelRenderer;}();var VBOSceneModelTriangleBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere){_inherits(VBOSceneModelTriangleBatchingRenderer,_VBOSceneModelRendere);var _super37=_createSuper(VBOSceneModelTriangleBatchingRenderer);function VBOSceneModelTriangleBatchingRenderer(scene,withSAO){var _ref8=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref8$instancing=_ref8.instancing,instancing=_ref8$instancing===void 0?false:_ref8$instancing,_ref8$edges=_ref8.edges,edges=_ref8$edges===void 0?false:_ref8$edges;_classCallCheck(this,VBOSceneModelTriangleBatchingRenderer);return _super37.call(this,scene,withSAO,{instancing:instancing,edges:edges});}_createClass(VBOSceneModelTriangleBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){gl.drawElements(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0);}else{var count=frameCtx.pickElementsCount||state.indicesBuf.numItems;var offset=frameCtx.pickElementsOffset?frameCtx.pickElementsOffset*state.indicesBuf.itemByteSize:0;gl.drawElements(gl.TRIANGLES,count,state.indicesBuf.itemType,offset);if(incrementDrawState){frameCtx.drawElements++;}}}}]);return VBOSceneModelTriangleBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelTriangleBatchingEdgesRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl){_inherits(VBOSceneModelTriangleBatchingEdgesRenderer,_VBOSceneModelTriangl);var _super38=_createSuper(VBOSceneModelTriangleBatchingEdgesRenderer);function VBOSceneModelTriangleBatchingEdgesRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelTriangleBatchingEdgesRenderer);return _super38.call(this,scene,withSAO,{instancing:false,edges:true});}return _createClass(VBOSceneModelTriangleBatchingEdgesRenderer);}(VBOSceneModelTriangleBatchingRenderer);var VBOSceneModelTriangleInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere2){_inherits(VBOSceneModelTriangleInstancingRenderer,_VBOSceneModelRendere2);var _super39=_createSuper(VBOSceneModelTriangleInstancingRenderer);function VBOSceneModelTriangleInstancingRenderer(scene,withSAO){var _ref9=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref9$edges=_ref9.edges,edges=_ref9$edges===void 0?false:_ref9$edges;_classCallCheck(this,VBOSceneModelTriangleInstancingRenderer);return _super39.call(this,scene,withSAO,{instancing:true,edges:edges});}_createClass(VBOSceneModelTriangleInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){gl.drawElementsInstanced(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0,state.numInstances);}else{gl.drawElementsInstanced(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0,state.numInstances);if(incrementDrawState){frameCtx.drawElements++;}}}}]);return VBOSceneModelTriangleInstancingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelTriangleInstancingEdgesRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl2){_inherits(VBOSceneModelTriangleInstancingEdgesRenderer,_VBOSceneModelTriangl2);var _super40=_createSuper(VBOSceneModelTriangleInstancingEdgesRenderer);function VBOSceneModelTriangleInstancingEdgesRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelTriangleInstancingEdgesRenderer);return _super40.call(this,scene,withSAO,{instancing:true,edges:true});}return _createClass(VBOSceneModelTriangleInstancingEdgesRenderer);}(VBOSceneModelTriangleInstancingRenderer);var VBOSceneModelPointBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere3){_inherits(VBOSceneModelPointBatchingRenderer,_VBOSceneModelRendere3);var _super41=_createSuper(VBOSceneModelPointBatchingRenderer);function VBOSceneModelPointBatchingRenderer(){_classCallCheck(this,VBOSceneModelPointBatchingRenderer);return _super41.apply(this,arguments);}_createClass(VBOSceneModelPointBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawArrays(gl.POINTS,0,state.positionsBuf.numItems);if(incrementDrawState){frameCtx.drawArrays++;}}}]);return VBOSceneModelPointBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelPointInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere4){_inherits(VBOSceneModelPointInstancingRenderer,_VBOSceneModelRendere4);var _super42=_createSuper(VBOSceneModelPointInstancingRenderer);function VBOSceneModelPointInstancingRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelPointInstancingRenderer);return _super42.call(this,scene,withSAO,{instancing:true});}_createClass(VBOSceneModelPointInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawArraysInstanced(gl.POINTS,0,state.positionsBuf.numItems,state.numInstances);if(incrementDrawState){frameCtx.drawArrays++;}}}]);return VBOSceneModelPointInstancingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelLineBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere5){_inherits(VBOSceneModelLineBatchingRenderer,_VBOSceneModelRendere5);var _super43=_createSuper(VBOSceneModelLineBatchingRenderer);function VBOSceneModelLineBatchingRenderer(){_classCallCheck(this,VBOSceneModelLineBatchingRenderer);return _super43.apply(this,arguments);}_createClass(VBOSceneModelLineBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawElements(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);if(incrementDrawState){frameCtx.drawElements++;}}}]);return VBOSceneModelLineBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelLineInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere6){_inherits(VBOSceneModelLineInstancingRenderer,_VBOSceneModelRendere6);var _super44=_createSuper(VBOSceneModelLineInstancingRenderer);function VBOSceneModelLineInstancingRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelLineInstancingRenderer);return _super44.call(this,scene,withSAO,{instancing:true});}_createClass(VBOSceneModelLineInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawElementsInstanced(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0,state.numInstances);if(incrementDrawState){frameCtx.drawElements++;}}}]);return VBOSceneModelLineInstancingRenderer;}(VBOSceneModelRenderer);/** +var lights=lightsState.lights;var light;for(var _i119=0,len=lights.length;_i1190){this._uReflectionMap="reflectionMap";}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}this._uSectionPlanes=[];for(var _i120=0,_len17=scene._sectionPlanesState.sectionPlanes.length;_i120<_len17;_i120++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i120),pos:program.getLocation("sectionPlanePos"+_i120),dir:program.getLocation("sectionPlaneDir"+_i120)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aUV=program.getAttribute("uv");this._aColor=program.getAttribute("color");this._aMetallicRoughness=program.getAttribute("metallicRoughness");this._aFlags=program.getAttribute("flags");this._aPickColor=program.getAttribute("pickColor");this._uPickZNear=program.getLocation("pickZNear");this._uPickZFar=program.getLocation("pickZFar");this._uPickClipPos=program.getLocation("pickClipPos");this._uColorMap="uColorMap";this._uMetallicRoughMap="uMetallicRoughMap";this._uEmissiveMap="uEmissiveMap";this._uNormalMap="uNormalMap";this._uAOMap="uAOMap";if(this._instancing){this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._aModelNormalMatrixCol0=program.getAttribute("modelNormalMatrixCol0");this._aModelNormalMatrixCol1=program.getAttribute("modelNormalMatrixCol1");this._aModelNormalMatrixCol2=program.getAttribute("modelNormalMatrixCol2");}if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}if(scene.pointsMaterial._state.filterIntensity){this._uIntensityRange=program.getLocation("intensityRange");}this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lightsState=scene._lightsState;var lights=lightsState.lights;program.bind();frameCtx.textureUnit=0;if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,lightsState.getAmbientColorAndIntensity());}for(var _i121=0,len=lights.length;_i1213&&arguments[3]!==undefined?arguments[3]:{},_ref7$colorUniform=_ref7.colorUniform,colorUniform=_ref7$colorUniform===void 0?false:_ref7$colorUniform,_ref7$incrementDrawSt=_ref7.incrementDrawState,incrementDrawState=_ref7$incrementDrawSt===void 0?false:_ref7$incrementDrawSt;var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var scene=this._scene;var gl=scene.canvas.gl;var state=layer._state,model=layer.model;var textureSet=state.textureSet,origin=state.origin,positionsDecodeMatrix=state.positionsDecodeMatrix;var lightsState=scene._lightsState;var pointsMaterial=scene.pointsMaterial;var camera=model.scene.camera;var viewNormalMatrix=camera.viewNormalMatrix,project=camera.project;var viewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var position=model.position,rotationMatrix=model.rotationMatrix,rotationMatrixConjugate=model.rotationMatrixConjugate,worldNormalMatrix=model.worldNormalMatrix;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}if(this._vaoCache.has(layer)){gl.bindVertexArray(this._vaoCache.get(layer));}else{this._vaoCache.set(layer,this._makeVAO(state));}var offset=0;var mat4Size=4*4;this._matricesUniformBlockBufferData.set(rotationMatrixConjugate,0);var gotOrigin=origin[0]!==0||origin[1]!==0||origin[2]!==0;var gotPosition=position[0]!==0||position[1]!==0||position[2]!==0;if(gotOrigin||gotPosition){var rtcOrigin=tempVec3a$w;if(gotOrigin){var rotatedOrigin=math.transformPoint3(rotationMatrix,origin,tempVec3c$n);rtcOrigin[0]=rotatedOrigin[0];rtcOrigin[1]=rotatedOrigin[1];rtcOrigin[2]=rotatedOrigin[2];}else{rtcOrigin[0]=0;rtcOrigin[1]=0;rtcOrigin[2]=0;}rtcOrigin[0]+=position[0];rtcOrigin[1]+=position[1];rtcOrigin[2]+=position[2];this._matricesUniformBlockBufferData.set(createRTCViewMat(viewMatrix,rtcOrigin,tempMat4a$f),offset+=mat4Size);}else{this._matricesUniformBlockBufferData.set(viewMatrix,offset+=mat4Size);}this._matricesUniformBlockBufferData.set(frameCtx.pickProjMatrix||project.matrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(positionsDecodeMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(worldNormalMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(viewNormalMatrix,offset+=mat4Size);gl.bindBuffer(gl.UNIFORM_BUFFER,this._matricesUniformBlockBuffer);gl.bufferData(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,gl.DYNAMIC_DRAW);gl.bindBufferBase(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);gl.uniform1i(this._uRenderPass,renderPass);this.setSectionPlanesStateUniforms(layer);if(scene.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix? +gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}if(this._uZFar){gl.uniform1f(this._uZFar,scene.camera.project.far);}}if(this._uPickInvisible){gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);}if(this._uPickZNear){gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);}if(this._uPickZFar){gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);}if(this._uPickClipPos){gl.uniform2fv(this._uPickClipPos,frameCtx.pickClipPos);}if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,state.positionsDecodeMatrix);}if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,state.uvDecodeMatrix);}if(this._uIntensityRange&&pointsMaterial.filterIntensity){gl.uniform2f(this._uIntensityRange,pointsMaterial.minIntensity,pointsMaterial.maxIntensity);}if(this._uPointSize){gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);}if(this._uNearPlaneHeight){var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);}if(textureSet){var colorTexture=textureSet.colorTexture,metallicRoughnessTexture=textureSet.metallicRoughnessTexture,emissiveTexture=textureSet.emissiveTexture,normalsTexture=textureSet.normalsTexture,occlusionTexture=textureSet.occlusionTexture;if(this._uColorMap&&colorTexture){this._program.bindTexture(this._uColorMap,colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uMetallicRoughMap&&metallicRoughnessTexture){this._program.bindTexture(this._uMetallicRoughMap,metallicRoughnessTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uEmissiveMap&&emissiveTexture){this._program.bindTexture(this._uEmissiveMap,emissiveTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uNormalMap&&normalsTexture){this._program.bindTexture(this._uNormalMap,normalsTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uAOMap&&occlusionTexture){this._program.bindTexture(this._uAOMap,occlusionTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}}if(lightsState.reflectionMaps.length>0&&lightsState.reflectionMaps[0].texture&&this._uReflectionMap){this._program.bindTexture(this._uReflectionMap,lightsState.reflectionMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(lightsState.lightMaps.length>0&&lightsState.lightMaps[0].texture&&this._uLightMap){this._program.bindTexture(this._uLightMap,lightsState.lightMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4[0]=viewportWidth;tempVec4[1]=viewportHeight;tempVec4[2]=sao.blendCutoff;tempVec4[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}if(colorUniform){var colorKey=this._edges?"edgeColor":"fillColor";var alphaKey=this._edges?"edgeAlpha":"fillAlpha";if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var material=scene.xrayMaterial._state;var _color=material[colorKey];var alpha=material[alphaKey];gl.uniform4f(this._uColor,_color[0],_color[1],_color[2],alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var _material=scene.highlightMaterial._state;var _color2=_material[colorKey];var _alpha=_material[alphaKey];gl.uniform4f(this._uColor,_color2[0],_color2[1],_color2[2],_alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var _material2=scene.selectedMaterial._state;var _color3=_material2[colorKey];var _alpha2=_material2[alphaKey];gl.uniform4f(this._uColor,_color3[0],_color3[1],_color3[2],_alpha2);}else{gl.uniform4fv(this._uColor,this._edges?edgesDefaultColor:defaultColor$2);}}this._draw({state:state,frameCtx:frameCtx,incrementDrawState:incrementDrawState});gl.bindVertexArray(null);}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;stats.memory.programs--;}}]);return VBOSceneModelRenderer;}();var VBOSceneModelTriangleBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere){_inherits(VBOSceneModelTriangleBatchingRenderer,_VBOSceneModelRendere);var _super37=_createSuper(VBOSceneModelTriangleBatchingRenderer);function VBOSceneModelTriangleBatchingRenderer(scene,withSAO){var _ref8=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref8$instancing=_ref8.instancing,instancing=_ref8$instancing===void 0?false:_ref8$instancing,_ref8$edges=_ref8.edges,edges=_ref8$edges===void 0?false:_ref8$edges;_classCallCheck(this,VBOSceneModelTriangleBatchingRenderer);return _super37.call(this,scene,withSAO,{instancing:instancing,edges:edges});}_createClass(VBOSceneModelTriangleBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){gl.drawElements(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0);}else{var count=frameCtx.pickElementsCount||state.indicesBuf.numItems;var offset=frameCtx.pickElementsOffset?frameCtx.pickElementsOffset*state.indicesBuf.itemByteSize:0;gl.drawElements(gl.TRIANGLES,count,state.indicesBuf.itemType,offset);if(incrementDrawState){frameCtx.drawElements++;}}}}]);return VBOSceneModelTriangleBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelTriangleBatchingEdgesRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl){_inherits(VBOSceneModelTriangleBatchingEdgesRenderer,_VBOSceneModelTriangl);var _super38=_createSuper(VBOSceneModelTriangleBatchingEdgesRenderer);function VBOSceneModelTriangleBatchingEdgesRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelTriangleBatchingEdgesRenderer);return _super38.call(this,scene,withSAO,{instancing:false,edges:true});}return _createClass(VBOSceneModelTriangleBatchingEdgesRenderer);}(VBOSceneModelTriangleBatchingRenderer);var VBOSceneModelTriangleInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere2){_inherits(VBOSceneModelTriangleInstancingRenderer,_VBOSceneModelRendere2);var _super39=_createSuper(VBOSceneModelTriangleInstancingRenderer);function VBOSceneModelTriangleInstancingRenderer(scene,withSAO){var _ref9=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref9$edges=_ref9.edges,edges=_ref9$edges===void 0?false:_ref9$edges;_classCallCheck(this,VBOSceneModelTriangleInstancingRenderer);return _super39.call(this,scene,withSAO,{instancing:true,edges:edges});}_createClass(VBOSceneModelTriangleInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){gl.drawElementsInstanced(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0,state.numInstances);}else{gl.drawElementsInstanced(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0,state.numInstances);if(incrementDrawState){frameCtx.drawElements++;}}}}]);return VBOSceneModelTriangleInstancingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelTriangleInstancingEdgesRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl2){_inherits(VBOSceneModelTriangleInstancingEdgesRenderer,_VBOSceneModelTriangl2);var _super40=_createSuper(VBOSceneModelTriangleInstancingEdgesRenderer);function VBOSceneModelTriangleInstancingEdgesRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelTriangleInstancingEdgesRenderer);return _super40.call(this,scene,withSAO,{instancing:true,edges:true});}return _createClass(VBOSceneModelTriangleInstancingEdgesRenderer);}(VBOSceneModelTriangleInstancingRenderer);var VBOSceneModelPointBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere3){_inherits(VBOSceneModelPointBatchingRenderer,_VBOSceneModelRendere3);var _super41=_createSuper(VBOSceneModelPointBatchingRenderer);function VBOSceneModelPointBatchingRenderer(){_classCallCheck(this,VBOSceneModelPointBatchingRenderer);return _super41.apply(this,arguments);}_createClass(VBOSceneModelPointBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawArrays(gl.POINTS,0,state.positionsBuf.numItems);if(incrementDrawState){frameCtx.drawArrays++;}}}]);return VBOSceneModelPointBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelPointInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere4){_inherits(VBOSceneModelPointInstancingRenderer,_VBOSceneModelRendere4);var _super42=_createSuper(VBOSceneModelPointInstancingRenderer);function VBOSceneModelPointInstancingRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelPointInstancingRenderer);return _super42.call(this,scene,withSAO,{instancing:true});}_createClass(VBOSceneModelPointInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawArraysInstanced(gl.POINTS,0,state.positionsBuf.numItems,state.numInstances);if(incrementDrawState){frameCtx.drawArrays++;}}}]);return VBOSceneModelPointInstancingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelLineBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere5){_inherits(VBOSceneModelLineBatchingRenderer,_VBOSceneModelRendere5);var _super43=_createSuper(VBOSceneModelLineBatchingRenderer);function VBOSceneModelLineBatchingRenderer(){_classCallCheck(this,VBOSceneModelLineBatchingRenderer);return _super43.apply(this,arguments);}_createClass(VBOSceneModelLineBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawElements(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);if(incrementDrawState){frameCtx.drawElements++;}}}]);return VBOSceneModelLineBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelLineInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere6){_inherits(VBOSceneModelLineInstancingRenderer,_VBOSceneModelRendere6);var _super44=_createSuper(VBOSceneModelLineInstancingRenderer);function VBOSceneModelLineInstancingRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelLineInstancingRenderer);return _super44.call(this,scene,withSAO,{instancing:true});}_createClass(VBOSceneModelLineInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawElementsInstanced(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0,state.numInstances);if(incrementDrawState){frameCtx.drawElements++;}}}]);return VBOSceneModelLineInstancingRenderer;}(VBOSceneModelRenderer);/** * @private */var TrianglesBatchingColorRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl3){_inherits(TrianglesBatchingColorRenderer,_VBOSceneModelTriangl3);var _super45=_createSuper(TrianglesBatchingColorRenderer);function TrianglesBatchingColorRenderer(){_classCallCheck(this,TrianglesBatchingColorRenderer);return _super45.apply(this,arguments);}_createClass(TrianglesBatchingColorRenderer,[{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,layer,renderPass){_get(_getPrototypeOf(TrianglesBatchingColorRenderer.prototype),"drawLayer",this).call(this,frameCtx,layer,renderPass,{incrementDrawState:true});}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.sectionPlanes.length>0;var light;var src=[];src.push("#version 300 es");src.push("// Triangles batching draw vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec3 normal;");src.push("in vec4 color;");src.push("in float flags;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}this._addMatricesUniformBlockLines(src,true);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("uniform vec4 lightAmbient;");for(var _i122=0,len=lightsState.lights.length;_i122= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vColor;");src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT // renderPass = COLOR_OPAQUE @@ -10123,21 +10123,21 @@ src.push("int edgeFlag = int(flags) >> 8 & 0xF;");src.push("if (edgeFlag != rend src.push("} else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");//src.push("vColor = vec4(float(color.r-100.0) / 255.0, float(color.g-100.0) / 255.0, float(color.b-100.0) / 255.0, float(color.a) / 255.0);"); src.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry edges drawing fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i132=0,len=sectionPlanesState.sectionPlanes.length;_i132> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i133=0,_len24=sectionPlanesState.sectionPlanes.length;_i133<_len24;_i133++){src.push("if (sectionPlaneActive"+_i133+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i133+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i133+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vColor;");src.push("}");return src;}}]);return TrianglesBatchingEdgesColorRenderer;}(VBOSceneModelTriangleBatchingEdgesRenderer);/** * @private - */var TrianglesBatchingPickMeshRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl8){_inherits(TrianglesBatchingPickMeshRenderer,_VBOSceneModelTriangl8);var _super50=_createSuper(TrianglesBatchingPickMeshRenderer);function TrianglesBatchingPickMeshRenderer(){_classCallCheck(this,TrianglesBatchingPickMeshRenderer);return _super50.apply(this,arguments);}_createClass(TrianglesBatchingPickMeshRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry picking vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("in vec4 pickColor;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK + */var TrianglesBatchingPickMeshRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl8){_inherits(TrianglesBatchingPickMeshRenderer,_VBOSceneModelTriangl8);var _super50=_createSuper(TrianglesBatchingPickMeshRenderer);function TrianglesBatchingPickMeshRenderer(){_classCallCheck(this,TrianglesBatchingPickMeshRenderer);return _super50.apply(this,arguments);}_createClass(TrianglesBatchingPickMeshRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry picking vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("in vec4 pickColor;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}this._addRemapClipPosLines(src);src.push("out vec4 vPickColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i134=0;_i134 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vPickColor; ");src.push("}");return src;}}]);return TrianglesBatchingPickMeshRenderer;}(VBOSceneModelTriangleBatchingRenderer);/** +src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i134=0;_i134 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vPickColor; ");src.push("}");return src;}}]);return TrianglesBatchingPickMeshRenderer;}(VBOSceneModelTriangleBatchingRenderer);/** * @private - */var TrianglesBatchingPickDepthRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl9){_inherits(TrianglesBatchingPickDepthRenderer,_VBOSceneModelTriangl9);var _super51=_createSuper(TrianglesBatchingPickDepthRenderer);function TrianglesBatchingPickDepthRenderer(){_classCallCheck(this,TrianglesBatchingPickDepthRenderer);return _super51.apply(this,arguments);}_createClass(TrianglesBatchingPickDepthRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK + */var TrianglesBatchingPickDepthRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl9){_inherits(TrianglesBatchingPickDepthRenderer,_VBOSceneModelTriangl9);var _super51=_createSuper(TrianglesBatchingPickDepthRenderer);function TrianglesBatchingPickDepthRenderer(){_classCallCheck(this,TrianglesBatchingPickDepthRenderer);return _super51.apply(this,arguments);}_createClass(TrianglesBatchingPickDepthRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}this._addRemapClipPosLines(src);src.push("out vec4 vViewPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i135=0;_i135 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth +src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i135=0;_i135 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth src.push("}");return src;}}]);return TrianglesBatchingPickDepthRenderer;}(VBOSceneModelTriangleBatchingRenderer);/** * @private - */var TrianglesBatchingPickNormalsRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl10){_inherits(TrianglesBatchingPickNormalsRenderer,_VBOSceneModelTriangl10);var _super52=_createSuper(TrianglesBatchingPickNormalsRenderer);function TrianglesBatchingPickNormalsRenderer(){_classCallCheck(this,TrianglesBatchingPickNormalsRenderer);return _super52.apply(this,arguments);}_createClass(TrianglesBatchingPickNormalsRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec3 normal;");src.push("in float flags;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("vec3 octDecode(vec2 oct) {");src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");src.push(" if (v.z < 0.0) {");src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec3 vWorldNormal;");src.push("out vec4 outColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK + */var TrianglesBatchingPickNormalsRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl10){_inherits(TrianglesBatchingPickNormalsRenderer,_VBOSceneModelTriangl10);var _super52=_createSuper(TrianglesBatchingPickNormalsRenderer);function TrianglesBatchingPickNormalsRenderer(){_classCallCheck(this,TrianglesBatchingPickNormalsRenderer);return _super52.apply(this,arguments);}_createClass(TrianglesBatchingPickNormalsRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec3 normal;");src.push("in float flags;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("vec3 octDecode(vec2 oct) {");src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");src.push(" if (v.z < 0.0) {");src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec3 vWorldNormal;");src.push("out vec4 outColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vec3 worldNormal = octDecode(normal.xy); ");src.push(" vWorldNormal = worldNormal;");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i136=0;_i136 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outNormal = ivec4(vWorldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}}]);return TrianglesBatchingPickNormalsRenderer;}(VBOSceneModelTriangleBatchingRenderer);/** +src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vec3 worldNormal = octDecode(normal.xy); ");src.push(" vWorldNormal = worldNormal;");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i136=0;_i136 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outNormal = ivec4(vWorldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}}]);return TrianglesBatchingPickNormalsRenderer;}(VBOSceneModelTriangleBatchingRenderer);/** * @private */var TrianglesBatchingOcclusionRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl11){_inherits(TrianglesBatchingOcclusionRenderer,_VBOSceneModelTriangl11);var _super53=_createSuper(TrianglesBatchingOcclusionRenderer);function TrianglesBatchingOcclusionRenderer(){_classCallCheck(this,TrianglesBatchingOcclusionRenderer);return _super53.apply(this,arguments);}_createClass(TrianglesBatchingOcclusionRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching occlusion vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in float flags;");this._addMatricesUniformBlockLines(src);if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT // renderPass = COLOR_OPAQUE @@ -10182,10 +10182,10 @@ src.push("float aoFactor = texture(uAOMap, vUV).r;");src.push("vec3 outgoingLigh // Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject src.push(" float viewportWidth = uSAOParams[0];");src.push(" float viewportHeight = uSAOParams[1];");src.push(" float blendCutoff = uSAOParams[2];");src.push(" float blendFactor = uSAOParams[3];");src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");src.push(" fragColor = vec4(outgoingLight.rgb * ambient * aoFactor, opacity);");}else{src.push(" fragColor = vec4(outgoingLight.rgb * aoFactor, opacity);");}if(gammaOutput){src.push("fragColor = linearToGamma(fragColor, gammaFactor);");}src.push("outColor = fragColor;");if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}}]);return TrianglesBatchingPBRRenderer;}(VBOSceneModelTriangleBatchingRenderer);/** * @private - */var TrianglesBatchingPickNormalsFlatRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl16){_inherits(TrianglesBatchingPickNormalsFlatRenderer,_VBOSceneModelTriangl16);var _super58=_createSuper(TrianglesBatchingPickNormalsFlatRenderer);function TrianglesBatchingPickNormalsFlatRenderer(){_classCallCheck(this,TrianglesBatchingPickNormalsFlatRenderer);return _super58.apply(this,arguments);}_createClass(TrianglesBatchingPickNormalsFlatRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick flat normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("out vec4 vWorldPosition;");if(clipping){src.push("out float vFlags;");}src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK + */var TrianglesBatchingPickNormalsFlatRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl16){_inherits(TrianglesBatchingPickNormalsFlatRenderer,_VBOSceneModelTriangl16);var _super58=_createSuper(TrianglesBatchingPickNormalsFlatRenderer);function TrianglesBatchingPickNormalsFlatRenderer(){_classCallCheck(this,TrianglesBatchingPickNormalsFlatRenderer);return _super58.apply(this,arguments);}_createClass(TrianglesBatchingPickNormalsFlatRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick flat normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("out vec4 vWorldPosition;");if(clipping){src.push("out float vFlags;");}src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vWorldPosition = worldPosition;");if(clipping){src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick flat normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("in vec4 vWorldPosition;");if(clipping){src.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i146=0;_i146 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outNormal = ivec4(worldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}}]);return TrianglesBatchingPickNormalsFlatRenderer;}(VBOSceneModelTriangleBatchingRenderer);/** +src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vWorldPosition = worldPosition;");if(clipping){src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching pick flat normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("in vec4 vWorldPosition;");if(clipping){src.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i146=0;_i146 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outNormal = ivec4(worldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}}]);return TrianglesBatchingPickNormalsFlatRenderer;}(VBOSceneModelTriangleBatchingRenderer);/** * @private */var TrianglesBatchingColorTextureRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl17){_inherits(TrianglesBatchingColorTextureRenderer,_VBOSceneModelTriangl17);var _super59=_createSuper(TrianglesBatchingColorTextureRenderer);function TrianglesBatchingColorTextureRenderer(){_classCallCheck(this,TrianglesBatchingColorTextureRenderer);return _super59.apply(this,arguments);}_createClass(TrianglesBatchingColorTextureRenderer,[{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,layer,renderPass){_get(_getPrototypeOf(TrianglesBatchingColorTextureRenderer.prototype),"drawLayer",this).call(this,frameCtx,layer,renderPass,{incrementDrawState:true});}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Triangles batching color texture vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec2 uv;");src.push("in float flags;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}this._addMatricesUniformBlockLines(src);src.push("uniform mat3 uvDecodeMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vViewPosition;");src.push("out vec4 vColor;");src.push("out vec2 vUV;");src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT // renderPass = COLOR_OPAQUE @@ -10383,23 +10383,23 @@ src.push("} else {");src.push("vec4 worldPosition = positionsDecodeMatrix * vec4 src.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry edges drawing fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i184=0,len=sectionPlanesState.sectionPlanes.length;_i184> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i185=0,_len47=sectionPlanesState.sectionPlanes.length;_i185<_len47;_i185++){src.push("if (sectionPlaneActive"+_i185+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i185+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i185+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vColor;");src.push("}");return src;}}]);return TrianglesInstancingEdgesColorRenderer;}(VBOSceneModelTriangleInstancingEdgesRenderer);/** * @private */var TrianglesInstancingPickMeshRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl23){_inherits(TrianglesInstancingPickMeshRenderer,_VBOSceneModelTriangl23);var _super67=_createSuper(TrianglesInstancingPickMeshRenderer);function TrianglesInstancingPickMeshRenderer(){_classCallCheck(this,TrianglesInstancingPickMeshRenderer);return _super67.apply(this,arguments);}_createClass(TrianglesInstancingPickMeshRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry picking vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("in vec4 pickColor;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix -src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK +src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i186=0;_i186> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i187=0;_i187 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vPickColor; ");src.push("}");return src;}}]);return TrianglesInstancingPickMeshRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** +src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i186=0;_i186> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i187=0;_i187 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vPickColor; ");src.push("}");return src;}}]);return TrianglesInstancingPickMeshRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** * @private */var TrianglesInstancingPickDepthRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl24){_inherits(TrianglesInstancingPickDepthRenderer,_VBOSceneModelTriangl24);var _super68=_createSuper(TrianglesInstancingPickDepthRenderer);function TrianglesInstancingPickDepthRenderer(){_classCallCheck(this,TrianglesInstancingPickDepthRenderer);return _super68.apply(this,arguments);}_createClass(TrianglesInstancingPickDepthRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix -src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK +src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push(" vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i188=0;_i188> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i189=0;_i189 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth +src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push(" vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i188=0;_i188> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i189=0;_i189 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth src.push("}");return src;}}]);return TrianglesInstancingPickDepthRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** * @private */var TrianglesInstancingPickNormalsRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl25){_inherits(TrianglesInstancingPickNormalsRenderer,_VBOSceneModelTriangl25);var _super69=_createSuper(TrianglesInstancingPickNormalsRenderer);function TrianglesInstancingPickNormalsRenderer(){_classCallCheck(this,TrianglesInstancingPickNormalsRenderer);return _super69.apply(this,arguments);}_createClass(TrianglesInstancingPickNormalsRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec2 normal;");src.push("in float flags;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix -src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("in vec4 modelNormalMatrixCol0;");src.push("in vec4 modelNormalMatrixCol1;");src.push("in vec4 modelNormalMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("vec3 octDecode(vec2 oct) {");src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");src.push(" if (v.z < 0.0) {");src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec3 vWorldNormal;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK +src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("in vec4 modelNormalMatrixCol0;");src.push("in vec4 modelNormalMatrixCol1;");src.push("in vec4 modelNormalMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("vec3 octDecode(vec2 oct) {");src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");src.push(" if (v.z < 0.0) {");src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec3 vWorldNormal;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); ");src.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));");src.push(" vWorldNormal = worldNormal;");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i190=0;_i190> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outNormal = ivec4(vWorldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}}]);return TrianglesInstancingPickNormalsRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** +src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); ");src.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));");src.push(" vWorldNormal = worldNormal;");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i190=0;_i190> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outNormal = ivec4(vWorldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}}]);return TrianglesInstancingPickNormalsRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** * @private */var TrianglesInstancingOcclusionRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl26){_inherits(TrianglesInstancingOcclusionRenderer,_VBOSceneModelTriangl26);var _super70=_createSuper(TrianglesInstancingOcclusionRenderer);function TrianglesInstancingOcclusionRenderer(){_classCallCheck(this,TrianglesInstancingOcclusionRenderer);return _super70.apply(this,arguments);}_createClass(TrianglesInstancingOcclusionRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// TrianglesInstancingOcclusionRenderer vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in float flags;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");this._addMatricesUniformBlockLines(src);if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT @@ -10443,10 +10443,10 @@ src.push("vec3 outgoingLight = (lightAmbient.rgb * lightAmbient.a * baseColor * src.push(" float viewportWidth = uSAOParams[0];");src.push(" float viewportHeight = uSAOParams[1];");src.push(" float blendCutoff = uSAOParams[2];");src.push(" float blendFactor = uSAOParams[3];");src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");src.push(" fragColor = vec4(outgoingLight.rgb * ambient, opacity);");}else{src.push(" fragColor = vec4(outgoingLight.rgb, opacity);");}if(gammaOutput){src.push("fragColor = linearToGamma(fragColor, gammaFactor);");}src.push("outColor = fragColor;");if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("}");return src;}}]);return TrianglesInstancingPBRRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** * @private */var TrianglesInstancingPickNormalsFlatRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl31){_inherits(TrianglesInstancingPickNormalsFlatRenderer,_VBOSceneModelTriangl31);var _super75=_createSuper(TrianglesInstancingPickNormalsFlatRenderer);function TrianglesInstancingPickNormalsFlatRenderer(){_classCallCheck(this,TrianglesInstancingPickNormalsFlatRenderer);return _super75.apply(this,arguments);}_createClass(TrianglesInstancingPickNormalsFlatRenderer,[{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry normals vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix -src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out float vFlags;");}src.push("out vec4 vWorldPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK +src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out float vFlags;");}src.push("out vec4 vWorldPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vWorldPosition = worldPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}if(clipping){src.push("vFlags = flags;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("in vec4 vWorldPosition;");if(clipping){src.push("in float vFlags;");for(var _i201=0;_i201> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outNormal = ivec4(worldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}}]);return TrianglesInstancingPickNormalsFlatRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** +src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vWorldPosition = worldPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}if(clipping){src.push("vFlags = flags;");}src.push("gl_Position = remapClipPos(clipPos);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("in vec4 vWorldPosition;");if(clipping){src.push("in float vFlags;");for(var _i201=0;_i201> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outNormal = ivec4(worldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}}]);return TrianglesInstancingPickNormalsFlatRenderer;}(VBOSceneModelTriangleInstancingRenderer);/** * @private */var TrianglesInstancingColorTextureRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl32){_inherits(TrianglesInstancingColorTextureRenderer,_VBOSceneModelTriangl32);var _super76=_createSuper(TrianglesInstancingColorTextureRenderer);function TrianglesInstancingColorTextureRenderer(){_classCallCheck(this,TrianglesInstancingColorTextureRenderer);return _super76.apply(this,arguments);}_createClass(TrianglesInstancingColorTextureRenderer,[{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene.gammaOutput,scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,layer,renderPass){_get(_getPrototypeOf(TrianglesInstancingColorTextureRenderer.prototype),"drawLayer",this).call(this,frameCtx,layer,renderPass,{incrementDrawState:true});}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Instancing geometry drawing vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec4 color;");src.push("in vec2 uv;");src.push("in float flags;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 modelMatrixCol0;");// Modeling matrix src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");this._addMatricesUniformBlockLines(src);src.push("uniform mat3 uvDecodeMatrix;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vViewPosition;");src.push("out vec4 vColor;");src.push("out vec2 vUV;");src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT @@ -10756,15 +10756,15 @@ src.push("} else {");}src.push("vec4 worldPosition = worldMatrix * (positionsDec src.push("int silhouetteFlag = int(flags) >> 4 & 0xF;");src.push("if (silhouetteFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex src.push("} else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push("vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var i;var len;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batching silhouette vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(i=0,len=sectionPlanesState.sectionPlanes.length;i 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = color;");src.push("}");return src;}}]);return PointsBatchingSilhouetteRenderer;}(VBOSceneModelPointBatchingRenderer);/** * @private - */var PointsBatchingPickMeshRenderer=/*#__PURE__*/function(_VBOSceneModelPointBa3){_inherits(PointsBatchingPickMeshRenderer,_VBOSceneModelPointBa3);var _super85=_createSuper(PointsBatchingPickMeshRenderer);function PointsBatchingPickMeshRenderer(){_classCallCheck(this,PointsBatchingPickMeshRenderer);return _super85.apply(this,arguments);}_createClass(PointsBatchingPickMeshRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points batching pick mesh vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("in vec4 pickColor;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK + */var PointsBatchingPickMeshRenderer=/*#__PURE__*/function(_VBOSceneModelPointBa3){_inherits(PointsBatchingPickMeshRenderer,_VBOSceneModelPointBa3);var _super85=_createSuper(PointsBatchingPickMeshRenderer);function PointsBatchingPickMeshRenderer(){_classCallCheck(this,PointsBatchingPickMeshRenderer);return _super85.apply(this,arguments);}_createClass(PointsBatchingPickMeshRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points batching pick mesh vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("in vec4 pickColor;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("gl_PointSize += 10.0;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batching pick mesh vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var i=0;i 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i231=0;_i231 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vPickColor; ");src.push("}");return src;}}]);return PointsBatchingPickMeshRenderer;}(VBOSceneModelPointBatchingRenderer);/** +src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = remapClipPos(clipPos);");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("gl_PointSize += 10.0;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batching pick mesh vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var i=0;i 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i231=0;_i231 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vPickColor; ");src.push("}");return src;}}]);return PointsBatchingPickMeshRenderer;}(VBOSceneModelPointBatchingRenderer);/** * @private - */var PointsBatchingPickDepthRenderer=/*#__PURE__*/function(_VBOSceneModelPointBa4){_inherits(PointsBatchingPickDepthRenderer,_VBOSceneModelPointBa4);var _super86=_createSuper(PointsBatchingPickDepthRenderer);function PointsBatchingPickDepthRenderer(){_classCallCheck(this,PointsBatchingPickDepthRenderer);return _super86.apply(this,arguments);}_createClass(PointsBatchingPickDepthRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points batched pick depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK + */var PointsBatchingPickDepthRenderer=/*#__PURE__*/function(_VBOSceneModelPointBa4){_inherits(PointsBatchingPickDepthRenderer,_VBOSceneModelPointBa4);var _super86=_createSuper(PointsBatchingPickDepthRenderer);function PointsBatchingPickDepthRenderer(){_classCallCheck(this,PointsBatchingPickDepthRenderer);return _super86.apply(this,arguments);}_createClass(PointsBatchingPickDepthRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points batched pick depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("gl_PointSize += 10.0;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batched pick depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i232=0;_i232 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth +src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = remapClipPos(clipPos);");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("gl_PointSize += 10.0;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points batched pick depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i232=0;_i232 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth src.push("}");return src;}}]);return PointsBatchingPickDepthRenderer;}(VBOSceneModelPointBatchingRenderer);/** * @private */var PointsBatchingOcclusionRenderer=/*#__PURE__*/function(_VBOSceneModelPointBa5){_inherits(PointsBatchingOcclusionRenderer,_VBOSceneModelPointBa5);var _super87=_createSuper(PointsBatchingOcclusionRenderer);function PointsBatchingOcclusionRenderer(){_classCallCheck(this,PointsBatchingOcclusionRenderer);return _super87.apply(this,arguments);}_createClass(PointsBatchingOcclusionRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var clipping=scene._sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points batching occlusion vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");this._addMatricesUniformBlockLines(src);src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT @@ -10855,16 +10855,16 @@ src.push("int silhouetteFlag = int(flags) >> 4 & 0xF;");src.push("if (silhouette src.push("} else {");src.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push("vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push("vWorldPosition = worldPosition;");src.push("vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);");src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing silhouette fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i249=0,len=sectionPlanesState.sectionPlanes.length;_i249 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i250=0,_len70=sectionPlanesState.sectionPlanes.length;_i250<_len70;_i250++){src.push("if (sectionPlaneActive"+_i250+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i250+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i250+".xyz), 0.0, 1000.0);");src.push("}");}src.push("if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vColor;");src.push("}");return src;}}]);return PointsInstancingSilhouetteRenderer;}(VBOSceneModelPointInstancingRenderer);/** * @private */var PointsInstancingPickMeshRenderer=/*#__PURE__*/function(_VBOSceneModelPointIn3){_inherits(PointsInstancingPickMeshRenderer,_VBOSceneModelPointIn3);var _super90=_createSuper(PointsInstancingPickMeshRenderer);function PointsInstancingPickMeshRenderer(){_classCallCheck(this,PointsInstancingPickMeshRenderer);return _super90.apply(this,arguments);}_createClass(PointsInstancingPickMeshRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points instancing pick mesh vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("in vec4 pickColor;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix -src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK +src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing pick mesh fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i251=0;_i251 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i252=0;_i252 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vPickColor; ");src.push("}");return src;}}]);return PointsInstancingPickMeshRenderer;}(VBOSceneModelPointInstancingRenderer);/** +src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push("vec4 clipPos = projMatrix * viewPosition;");src.push("gl_Position = remapClipPos(clipPos);");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing pick mesh fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i251=0;_i251 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i252=0;_i252 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push("outColor = vPickColor; ");src.push("}");return src;}}]);return PointsInstancingPickMeshRenderer;}(VBOSceneModelPointInstancingRenderer);/** * @private */var PointsInstancingPickDepthRenderer=/*#__PURE__*/function(_VBOSceneModelPointIn4){_inherits(PointsInstancingPickDepthRenderer,_VBOSceneModelPointIn4);var _super91=_createSuper(PointsInstancingPickDepthRenderer);function PointsInstancingPickDepthRenderer(){_classCallCheck(this,PointsInstancingPickDepthRenderer);return _super91.apply(this,arguments);}_createClass(PointsInstancingPickDepthRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points instancing pick depth vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in float flags;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix -src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK +src.push("in vec4 modelMatrixCol1;");src.push("in vec4 modelMatrixCol2;");src.push("uniform bool pickInvisible;");this._addMatricesUniformBlockLines(src);this._addRemapClipPosLines(src);src.push("uniform float pointSize;");if(pointsMaterial.perspectivePoints){src.push("uniform float nearPlaneHeight;");}if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");}if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// pickFlag = NOT_RENDERED | PICK // renderPass = PICK src.push("int pickFlag = int(flags) >> 12 & 0xF;");src.push("if (pickFlag != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push(" vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = clipPos;");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing pick depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i253=0;_i253 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i254=0;_i254 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth +src.push("} else {");src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags = flags;");}src.push(" vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");src.push("gl_Position = remapClipPos(clipPos);");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");}src.push("gl_Position = remapClipPos(clipPos);");if(pointsMaterial.perspectivePoints){src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");src.push("gl_PointSize = max(gl_PointSize, "+Math.floor(pointsMaterial.minPerspectivePointSize)+".0);");src.push("gl_PointSize = min(gl_PointSize, "+Math.floor(pointsMaterial.maxPerspectivePointSize)+".0);");}else{src.push("gl_PointSize = pointSize;");}src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Points instancing pick depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("in float vFlags;");for(var _i253=0;_i253 1.0) {");src.push(" discard;");src.push(" }");}if(clipping){src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i254=0;_i254 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outColor = packDepth(zNormalizedDepth); ");// Must be linear depth src.push("}");return src;}}]);return PointsInstancingPickDepthRenderer;}(VBOSceneModelPointInstancingRenderer);/** * @private */var PointsInstancingOcclusionRenderer=/*#__PURE__*/function(_VBOSceneModelPointIn5){_inherits(PointsInstancingOcclusionRenderer,_VBOSceneModelPointIn5);var _super92=_createSuper(PointsInstancingOcclusionRenderer);function PointsInstancingOcclusionRenderer(){_classCallCheck(this,PointsInstancingOcclusionRenderer);return _super92.apply(this,arguments);}_createClass(PointsInstancingOcclusionRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash;}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var pointsMaterial=scene.pointsMaterial._state;var src=[];src.push('#version 300 es');src.push("// Points instancing occlusion vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("in vec4 color;");src.push("in float flags;");src.push("in vec4 modelMatrixCol0;");// Modeling matrix @@ -11380,12 +11380,12 @@ src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping) src.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// TrianglesDataTextureEdgesColorRenderer");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var _i297=0,len=sectionPlanesState.sectionPlanes.length;_i297 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var _i298=0,_len85=sectionPlanesState.sectionPlanes.length;_i298<_len85;_i298++){src.push("if (sectionPlaneActive"+_i298+") {");src.push(" dist += clamp(dot(-sectionPlaneDir"+_i298+".xyz, vWorldPosition.xyz - sectionPlanePos"+_i298+".xyz), 0.0, 1000.0);");src.push("}");}src.push(" if (dist > 0.0) { discard; }");src.push("}");}if(scene.logarithmicDepthBufferEnabled){// src.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"); src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outColor = vColor;");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureEdgesColorRenderer;}();var tempVec3a$k=math.vec3();var tempVec3b$e=math.vec3();var tempVec3c$d=math.vec3();var tempMat4a$6=math.mat4();/** * @private - */var TrianglesDataTexturePickMeshRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickMeshRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickMeshRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickMeshRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){if(!this._program){this._allocate(dataTextureLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;var position=model.position,rotationMatrix=model.rotationMatrix,rotationMatrixConjugate=model.rotationMatrixConjugate;textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var rtcViewMatrix;var rtcCameraEye;var gotOrigin=origin[0]!==0||origin[1]!==0||origin[2]!==0;var gotPosition=position[0]!==0||position[1]!==0||position[2]!==0;if(gotOrigin||gotPosition){var rtcOrigin=tempVec3a$k;if(gotOrigin){var rotatedOrigin=math.transformPoint3(rotationMatrix,origin,tempVec3b$e);rtcOrigin[0]=rotatedOrigin[0];rtcOrigin[1]=rotatedOrigin[1];rtcOrigin[2]=rotatedOrigin[2];}else{rtcOrigin[0]=0;rtcOrigin[1]=0;rtcOrigin[2]=0;}rtcOrigin[0]+=position[0];rtcOrigin[1]+=position[1];rtcOrigin[2]+=position[2];rtcViewMatrix=createRTCViewMat(camera.viewMatrix,rtcOrigin,tempMat4a$6);rtcCameraEye=tempVec3c$d;rtcCameraEye[0]=camera.eye[0]-rtcOrigin[0];rtcCameraEye[1]=camera.eye[1]-rtcOrigin[1];rtcCameraEye[2]=camera.eye[2]-rtcOrigin[2];}else{rtcViewMatrix=camera.viewMatrix;rtcCameraEye=camera.eye;}gl.uniformMatrix4fv(this._uSceneModelWorldMatrix,false,rotationMatrixConjugate);gl.uniformMatrix4fv(this._uViewMatrix,false,rtcViewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,camera.projMatrix);gl.uniform3fv(this._uCameraEyeRtc,rtcCameraEye);gl.uniform1i(this._uRenderPass,renderPass);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far from pick project matrix? + */var TrianglesDataTexturePickMeshRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickMeshRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickMeshRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickMeshRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){if(!this._program){this._allocate(dataTextureLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;var position=model.position,rotationMatrix=model.rotationMatrix,rotationMatrixConjugate=model.rotationMatrixConjugate;textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var rtcViewMatrix;var rtcCameraEye;var gotOrigin=origin[0]!==0||origin[1]!==0||origin[2]!==0;var gotPosition=position[0]!==0||position[1]!==0||position[2]!==0;if(gotOrigin||gotPosition){var rtcOrigin=tempVec3a$k;if(gotOrigin){var rotatedOrigin=math.transformPoint3(rotationMatrix,origin,tempVec3b$e);rtcOrigin[0]=rotatedOrigin[0];rtcOrigin[1]=rotatedOrigin[1];rtcOrigin[2]=rotatedOrigin[2];}else{rtcOrigin[0]=0;rtcOrigin[1]=0;rtcOrigin[2]=0;}rtcOrigin[0]+=position[0];rtcOrigin[1]+=position[1];rtcOrigin[2]+=position[2];rtcViewMatrix=createRTCViewMat(camera.viewMatrix,rtcOrigin,tempMat4a$6);rtcCameraEye=tempVec3c$d;rtcCameraEye[0]=camera.eye[0]-rtcOrigin[0];rtcCameraEye[1]=camera.eye[1]-rtcOrigin[1];rtcCameraEye[2]=camera.eye[2]-rtcOrigin[2];}else{rtcViewMatrix=camera.viewMatrix;rtcCameraEye=camera.eye;}gl.uniform2fv(this._uPickClipPos,frameCtx.pickClipPos);gl.uniformMatrix4fv(this._uSceneModelWorldMatrix,false,rotationMatrixConjugate);gl.uniformMatrix4fv(this._uViewMatrix,false,rtcViewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,camera.projMatrix);gl.uniform3fv(this._uCameraEyeRtc,rtcCameraEye);gl.uniform1i(this._uRenderPass,renderPass);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far from pick project matrix? gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices );gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16// 16 bits indices );gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32// 32 bits indices -);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uSceneModelWorldMatrix=program.getLocation("sceneModelWorldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i299=0,len=scene._sectionPlanesState.sectionPlanes.length;_i2990;var src=[];src.push("#version 300 es");src.push("// Batched geometry picking vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 sceneModelWorldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform bool pickInvisible;");// src.push("uniform sampler2D uOcclusionTexture;"); -src.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;");src.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;");src.push("uniform highp sampler2D uTexturePerObjectIdOffsets;");src.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;");src.push("uniform highp usampler2D uTexturePerPolygonIdIndices;");src.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;");src.push("uniform highp sampler2D uTextureModelMatrices;");src.push("uniform vec3 uCameraEyeRtc;");src.push("vec3 positions[3];");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("out float isPerspective;");}src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");if(clipping){src.push("smooth out vec4 vWorldPosition;");src.push("flat out uvec4 vFlags2;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");src.push("int polygonIndex = gl_VertexID / 3;");// get packed object-id +);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPickClipPos=program.getLocation("pickClipPos");this._uSceneModelWorldMatrix=program.getLocation("sceneModelWorldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i299=0,len=scene._sectionPlanesState.sectionPlanes.length;_i2990;var src=[];src.push("#version 300 es");src.push("// Batched geometry picking vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 sceneModelWorldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform bool pickInvisible;");// src.push("uniform sampler2D uOcclusionTexture;"); +src.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;");src.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;");src.push("uniform highp sampler2D uTexturePerObjectIdOffsets;");src.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;");src.push("uniform highp usampler2D uTexturePerPolygonIdIndices;");src.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;");src.push("uniform highp sampler2D uTextureModelMatrices;");src.push("uniform vec3 uCameraEyeRtc;");src.push("vec3 positions[3];");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("out float isPerspective;");}src.push("uniform vec2 pickClipPos;");src.push("vec4 remapClipPos(vec4 clipPos) {");src.push(" clipPos.xy /= clipPos.w;");src.push(" clipPos.xy -= pickClipPos;");src.push(" clipPos.xy *= clipPos.w;");src.push(" return clipPos;");src.push("}");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");if(clipping){src.push("smooth out vec4 vWorldPosition;");src.push("flat out uvec4 vFlags2;");}src.push("out vec4 vPickColor;");src.push("void main(void) {");src.push("int polygonIndex = gl_VertexID / 3;");// get packed object-id src.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;");src.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;");src.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);");src.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);");// get flags & flags2 src.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);");src.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);");// flags.w = NOT_RENDERED | PICK // renderPass = PICK @@ -11399,14 +11399,14 @@ src.push(" return;");src.push("};");// get pick-color src.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;");// get normal src.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));");src.push("vec3 position;");src.push("position = positions[gl_VertexID % 3];");// when the geometry is not solid, if needed, flip the triangle winding src.push("if (solid != 1u) {");src.push("if (isPerspectiveMatrix(projMatrix)) {");src.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;");src.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("}");src.push("} else {");src.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);");src.push("if (viewNormal.z < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("}");src.push("}");src.push("}");src.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");// get XYZ offset -src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Batched geometry picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uvec4 vFlags2;");for(var i=0;i 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");//src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"); +src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Batched geometry picking fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uvec4 vFlags2;");for(var i=0;i 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");//src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"); }src.push(" outPickColor = vPickColor; ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTexturePickMeshRenderer;}();var tempVec3a$j=math.vec3();var tempVec3b$d=math.vec3();var tempVec3c$c=math.vec3();var tempVec3d$7=math.vec3();var tempMat4a$5=math.mat4();/** * @private - */var TrianglesDataTexturePickDepthRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickDepthRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;var position=model.position,rotationMatrix=model.rotationMatrix,rotationMatrixConjugate=model.rotationMatrixConjugate;var viewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;if(!this._program){this._allocate();}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var rtcViewMatrix;var rtcCameraEye;if(origin||position[0]!==0||position[1]!==0||position[2]!==0){var rtcOrigin=tempVec3a$j;if(origin){var rotatedOrigin=tempVec3b$d;math.transformPoint3(rotationMatrix,origin,rotatedOrigin);rtcOrigin[0]=rotatedOrigin[0];rtcOrigin[1]=rotatedOrigin[1];rtcOrigin[2]=rotatedOrigin[2];}else{rtcOrigin[0]=0;rtcOrigin[1]=0;rtcOrigin[2]=0;}rtcOrigin[0]+=position[0];rtcOrigin[1]+=position[1];rtcOrigin[2]+=position[2];rtcViewMatrix=createRTCViewMat(viewMatrix,rtcOrigin,tempMat4a$5);rtcCameraEye=tempVec3c$c;rtcCameraEye[0]=camera.eye[0]-rtcOrigin[0];rtcCameraEye[1]=camera.eye[1]-rtcOrigin[1];rtcCameraEye[2]=camera.eye[2]-rtcOrigin[2];frameCtx.snapPickOrigin[0]=rtcOrigin[0];frameCtx.snapPickOrigin[1]=rtcOrigin[1];frameCtx.snapPickOrigin[2]=rtcOrigin[2];}else{rtcViewMatrix=viewMatrix;rtcCameraEye=camera.eye;frameCtx.snapPickOrigin[0]=0;frameCtx.snapPickOrigin[1]=0;frameCtx.snapPickOrigin[2]=0;}gl.uniform3fv(this._uCameraEyeRtc,rtcCameraEye);gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);gl.uniformMatrix4fv(this._uWorldMatrix,false,rotationMatrixConjugate);gl.uniformMatrix4fv(this._uViewMatrix,false,rtcViewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,camera.projMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix? + */var TrianglesDataTexturePickDepthRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickDepthRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;var position=model.position,rotationMatrix=model.rotationMatrix,rotationMatrixConjugate=model.rotationMatrixConjugate;var viewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;if(!this._program){this._allocate();}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var rtcViewMatrix;var rtcCameraEye;if(origin||position[0]!==0||position[1]!==0||position[2]!==0){var rtcOrigin=tempVec3a$j;if(origin){var rotatedOrigin=tempVec3b$d;math.transformPoint3(rotationMatrix,origin,rotatedOrigin);rtcOrigin[0]=rotatedOrigin[0];rtcOrigin[1]=rotatedOrigin[1];rtcOrigin[2]=rotatedOrigin[2];}else{rtcOrigin[0]=0;rtcOrigin[1]=0;rtcOrigin[2]=0;}rtcOrigin[0]+=position[0];rtcOrigin[1]+=position[1];rtcOrigin[2]+=position[2];rtcViewMatrix=createRTCViewMat(viewMatrix,rtcOrigin,tempMat4a$5);rtcCameraEye=tempVec3c$c;rtcCameraEye[0]=camera.eye[0]-rtcOrigin[0];rtcCameraEye[1]=camera.eye[1]-rtcOrigin[1];rtcCameraEye[2]=camera.eye[2]-rtcOrigin[2];frameCtx.snapPickOrigin[0]=rtcOrigin[0];frameCtx.snapPickOrigin[1]=rtcOrigin[1];frameCtx.snapPickOrigin[2]=rtcOrigin[2];}else{rtcViewMatrix=viewMatrix;rtcCameraEye=camera.eye;frameCtx.snapPickOrigin[0]=0;frameCtx.snapPickOrigin[1]=0;frameCtx.snapPickOrigin[2]=0;}gl.uniform3fv(this._uCameraEyeRtc,rtcCameraEye);gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniform2fv(this._uPickClipPos,frameCtx.pickClipPos);gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);gl.uniformMatrix4fv(this._uWorldMatrix,false,rotationMatrixConjugate);gl.uniformMatrix4fv(this._uViewMatrix,false,rtcViewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,camera.projMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix? gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices );gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16// 16 bits indices );gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32// 32 bits indices -);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i300=0,len=scene._sectionPlanesState.sectionPlanes.length;_i3000;var src=[];src.push("#version 300 es");src.push("// Triangles dataTexture pick depth vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform bool pickInvisible;");src.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;");src.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;");src.push("uniform highp sampler2D uTexturePerObjectIdOffsets;");src.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;");src.push("uniform highp usampler2D uTexturePerPolygonIdIndices;");src.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;");src.push("uniform highp sampler2D uTextureModelMatrices;");src.push("uniform vec3 uCameraEyeRtc;");src.push("vec3 positions[3];");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("out float isPerspective;");}src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("flat out uint vFlags2;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// constants +);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPickClipPos=program.getLocation("pickClipPos");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i300=0,len=scene._sectionPlanesState.sectionPlanes.length;_i3000;var src=[];src.push("#version 300 es");src.push("// Triangles dataTexture pick depth vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");src.push("uniform bool pickInvisible;");src.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;");src.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;");src.push("uniform highp sampler2D uTexturePerObjectIdOffsets;");src.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;");src.push("uniform highp usampler2D uTexturePerPolygonIdIndices;");src.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;");src.push("uniform highp sampler2D uTextureModelMatrices;");src.push("uniform vec3 uCameraEyeRtc;");src.push("vec3 positions[3];");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("out float isPerspective;");}src.push("uniform vec2 pickClipPos;");src.push("vec4 remapClipPos(vec4 clipPos) {");src.push(" clipPos.xy /= clipPos.w;");src.push(" clipPos.xy -= pickClipPos;");src.push(" clipPos.xy *= clipPos.w;");src.push(" return clipPos;");src.push("}");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("flat out uint vFlags2;");}src.push("out vec4 vViewPosition;");src.push("void main(void) {");// constants src.push("int polygonIndex = gl_VertexID / 3;");// get packed object-id src.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;");src.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;");src.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);");src.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);");// get flags & flags2 src.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);");src.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);");// flags.w = NOT_RENDERED | PICK @@ -11420,7 +11420,7 @@ src.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(obj src.push(" return;");src.push("};");// get normal src.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));");src.push("vec3 position;");src.push("position = positions[gl_VertexID % 3];");// when the geometry is not solid, if needed, flip the triangle winding src.push("if (solid != 1u) {");src.push("if (isPerspectiveMatrix(projMatrix)) {");src.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;");src.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("}");src.push("} else {");src.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);");src.push("if (viewNormal.z < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("}");src.push("}");src.push("}");src.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");// get XYZ offset -src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2.r;");}src.push("vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture pick depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var i=0;i 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outPackedDepth = packDepth(zNormalizedDepth); ");// Must be linear depth +src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2.r;");}src.push("vViewPosition = viewPosition;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture pick depth fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("uniform float pickZNear;");src.push("uniform float pickZFar;");if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var i=0;i 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));");src.push(" outPackedDepth = packDepth(zNormalizedDepth); ");// Must be linear depth src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTexturePickDepthRenderer;}();var tempVec3a$i=math.vec3();var tempVec3b$c=math.vec3();var tempVec3c$b=math.vec3();var tempVec3d$6=math.vec3();var tempVec3e$2=math.vec3();var tempMat4a$4=math.mat4();/** * @private */var TrianglesDataTextureSnapDepthRenderer=/*#__PURE__*/function(){function TrianglesDataTextureSnapDepthRenderer(scene){_classCallCheck(this,TrianglesDataTextureSnapDepthRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureSnapDepthRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;var position=model.position,rotationMatrix=model.rotationMatrix,rotationMatrixConjugate=model.rotationMatrixConjugate;var aabb=dataTextureLayer.aabb;var viewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var coordinateScaler=tempVec3a$i;coordinateScaler[0]=math.safeInv(aabb[3]-aabb[0])*math.MAX_INT;coordinateScaler[1]=math.safeInv(aabb[4]-aabb[1])*math.MAX_INT;coordinateScaler[2]=math.safeInv(aabb[5]-aabb[2])*math.MAX_INT;frameCtx.snapPickCoordinateScale[0]=math.safeInv(coordinateScaler[0]);frameCtx.snapPickCoordinateScale[1]=math.safeInv(coordinateScaler[1]);frameCtx.snapPickCoordinateScale[2]=math.safeInv(coordinateScaler[2]);textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var rtcViewMatrix;var rtcCameraEye;var gotOrigin=origin[0]!==0||origin[1]!==0||origin[2]!==0;var gotPosition=position[0]!==0||position[1]!==0||position[2]!==0;if(gotOrigin||gotPosition){var rtcOrigin=tempVec3b$c;if(gotOrigin){var rotatedOrigin=math.transformPoint3(rotationMatrix,origin,tempVec3c$b);rtcOrigin[0]=rotatedOrigin[0];rtcOrigin[1]=rotatedOrigin[1];rtcOrigin[2]=rotatedOrigin[2];}else{rtcOrigin[0]=0;rtcOrigin[1]=0;rtcOrigin[2]=0;}rtcOrigin[0]+=position[0];rtcOrigin[1]+=position[1];rtcOrigin[2]+=position[2];rtcViewMatrix=createRTCViewMat(viewMatrix,rtcOrigin,tempMat4a$4);rtcCameraEye=tempVec3d$6;rtcCameraEye[0]=camera.eye[0]-rtcOrigin[0];rtcCameraEye[1]=camera.eye[1]-rtcOrigin[1];rtcCameraEye[2]=camera.eye[2]-rtcOrigin[2];frameCtx.snapPickOrigin[0]=rtcOrigin[0];frameCtx.snapPickOrigin[1]=rtcOrigin[1];frameCtx.snapPickOrigin[2]=rtcOrigin[2];}else{rtcViewMatrix=viewMatrix;rtcCameraEye=camera.eye;frameCtx.snapPickOrigin[0]=0;frameCtx.snapPickOrigin[1]=0;frameCtx.snapPickOrigin[2]=0;}gl.uniform3fv(this._uCameraEyeRtc,rtcCameraEye);gl.uniform2fv(this.uVectorA,frameCtx.snapVectorA);gl.uniform2fv(this.uInverseVectorAB,frameCtx.snapInvVectorAB);gl.uniform1i(this._uLayerNumber,frameCtx.snapPickLayerNumber);gl.uniform3fv(this._uCoordinateScaler,coordinateScaler);gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniformMatrix4fv(this._uSceneModelWorldMatrix,false,rotationMatrixConjugate);gl.uniformMatrix4fv(this._uViewMatrix,false,rtcViewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,camera.projMatrix);{var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0){textureState.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8// 8 bits edge indices @@ -11458,11 +11458,11 @@ src.push("clipPos.xyzw *= tmp;");{src.push("vFragDepth = 1.0 + clipPos.w;");src. // ); // cameraEye = frameCtx.pickOrigin || cameraEye; // } -var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far should be from projection matrix? +var originCameraEye=[cameraEye[0]-origin[0],cameraEye[1]-origin[1],cameraEye[2]-origin[2]];gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uRenderPass,renderPass);gl.uniform3fv(this._uCameraEyeRtc,originCameraEye);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniform2fv(this._uPickClipPos,frameCtx.pickClipPos);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far should be from projection matrix? gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices );gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16// 16 bits indices );gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32// 32 bits indices -);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uSectionPlanes=[];for(var _i305=0,len=scene._sectionPlanesState.sectionPlanes.length;_i3050;var src=[];src.push("#version 300 es");src.push("// Triangles dataTexture pick normals vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform bool pickInvisible;");src.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;");src.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;");src.push("uniform highp sampler2D uTexturePerObjectIdOffsets;");src.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;");src.push("uniform highp usampler2D uTexturePerPolygonIdIndices;");src.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;");src.push("uniform highp sampler2D uTextureCameraMatrices;");src.push("uniform highp sampler2D uTextureModelMatrices;");src.push("uniform vec3 uCameraEyeRtc;");src.push("vec3 positions[3];");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("out float isPerspective;");}src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("flat out uint vFlags2;");}src.push("out vec3 vWorldNormal;");src.push("void main(void) {");// camera matrices +);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPickClipPos=program.getLocation("pickClipPos");this._uSectionPlanes=[];for(var _i305=0,len=scene._sectionPlanesState.sectionPlanes.length;_i3050;var src=[];src.push("#version 300 es");src.push("// Triangles dataTexture pick normals vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform bool pickInvisible;");src.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;");src.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;");src.push("uniform highp sampler2D uTexturePerObjectIdOffsets;");src.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;");src.push("uniform highp usampler2D uTexturePerPolygonIdIndices;");src.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;");src.push("uniform highp sampler2D uTextureCameraMatrices;");src.push("uniform highp sampler2D uTextureModelMatrices;");src.push("uniform vec3 uCameraEyeRtc;");src.push("vec3 positions[3];");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("out float isPerspective;");}src.push("uniform vec2 pickClipPos;");src.push("vec4 remapClipPos(vec4 clipPos) {");src.push(" clipPos.xy /= clipPos.w;");src.push(" clipPos.xy -= pickClipPos;");src.push(" clipPos.xy *= clipPos.w;");src.push(" return clipPos;");src.push("}");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("flat out uint vFlags2;");}src.push("out vec3 vWorldNormal;");src.push("void main(void) {");// camera matrices src.push("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));");src.push("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));");// model matrices src.push("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));");// constants src.push("int polygonIndex = gl_VertexID / 3;");// get packed object-id @@ -11476,7 +11476,7 @@ src.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAn src.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));");src.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));");src.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));");// get normal src.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));");src.push("vec3 position;");src.push("position = positions[gl_VertexID % 3];");// when the geometry is not solid, if needed, flip the triangle winding src.push("if (solid != 1u) {");src.push("if (isPerspectiveMatrix(projMatrix)) {");src.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;");src.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("normal = -normal;");src.push("}");src.push("} else {");src.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);");src.push("if (viewNormal.z < 0.0) {");src.push("position = positions[2 - (gl_VertexID % 3)];");src.push("normal = -normal;");src.push("}");src.push("}");src.push("}");src.push("normal = -normal;");src.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");// get XYZ offset -src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");src.push("vWorldNormal = normal.xyz;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2.w;");}src.push("gl_Position = clipPos;");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture pick normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var i=0;i 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){// src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"); +src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");src.push("vec4 viewPosition = viewMatrix * worldPosition; ");src.push("vWorldNormal = normal.xyz;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2.w;");}src.push("gl_Position = remapClipPos(clipPos);");src.push("}");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture pick normals fragment shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("flat in uint vFlags2;");for(var i=0;i 0u;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){// src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"); src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" outNormal = ivec4(vWorldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTexturePickNormalsRenderer;}();var tempVec3a$f=math.vec3();var tempVec3b$a=math.vec3();var tempVec3c$9=math.vec3();var tempVec3d$4=math.vec3();var tempMat4a$2=math.mat4();/** * @private */var TrianglesDataTextureOcclusionRenderer=/*#__PURE__*/function(){function TrianglesDataTextureOcclusionRenderer(scene){_classCallCheck(this,TrianglesDataTextureOcclusionRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTextureOcclusionRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var textureState=state.textureState;var origin=dataTextureLayer._state.origin;var position=model.position,rotationMatrix=model.rotationMatrix,rotationMatrixConjugate=model.rotationMatrixConjugate;var viewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;if(!this._program){this._allocate(dataTextureLayer);if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}textureState.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var rtcViewMatrix;var rtcCameraEye;if(origin||position[0]!==0||position[1]!==0||position[2]!==0){var rtcOrigin=tempVec3a$f;if(origin){var rotatedOrigin=tempVec3b$a;math.transformPoint3(rotationMatrix,origin,rotatedOrigin);rtcOrigin[0]=rotatedOrigin[0];rtcOrigin[1]=rotatedOrigin[1];rtcOrigin[2]=rotatedOrigin[2];}else{rtcOrigin[0]=0;rtcOrigin[1]=0;rtcOrigin[2]=0;}rtcOrigin[0]+=position[0];rtcOrigin[1]+=position[1];rtcOrigin[2]+=position[2];rtcViewMatrix=createRTCViewMat(viewMatrix,rtcOrigin,tempMat4a$2);rtcCameraEye=tempVec3c$9;rtcCameraEye[0]=camera.eye[0]-rtcOrigin[0];rtcCameraEye[1]=camera.eye[1]-rtcOrigin[1];rtcCameraEye[2]=camera.eye[2]-rtcOrigin[2];}else{rtcViewMatrix=viewMatrix;rtcCameraEye=camera.eye;}gl.uniform3fv(this._uCameraEyeRtc,rtcCameraEye);gl.uniform1i(this._uRenderPass,renderPass);gl.uniformMatrix4fv(this._uWorldMatrix,false,rotationMatrixConjugate);gl.uniformMatrix4fv(this._uViewMatrix,false,rtcViewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,camera.projMatrix);var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0){textureState.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8// 8 bits indices @@ -11524,12 +11524,12 @@ this._aFlags2=program.getAttribute("flags2");}if(scene.logarithmicDepthBufferEna // renderPass = COLOR_OPAQUE src.push("if (int(flags.x) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); ");src.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);");if(clipping){src.push(" vWorldPosition = worldPosition;");src.push(" vFlags2 = flags2;");}src.push(" vViewNormal = viewNormal;");src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){if(WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("vFragDepth = 1.0 + clipPos.w;");}else{src.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;");src.push("clipPos.z *= clipPos.w;");}src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push("#version 300 es");src.push("// Batched geometry normals fragment shader");if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("#extension GL_EXT_frag_depth : enable");}src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}if(clipping){src.push("in vec4 vWorldPosition;");src.push("in vec4 vFlags2;");for(var _i313=0;_i313 0.0);");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled&&WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]){src.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); ");src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTextureNormalsRenderer;}();var tempVec3a$c=math.vec3();/** * @private - */var TrianglesDataTexturePickNormalsFlatRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickNormalsFlatRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickNormalsFlatRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickNormalsFlatRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerObjectIdPositionsDecodeMatrix);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},1);this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerVertexIdCoordinates);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},2);this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerObjectIdColorsAndFlags);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},3);gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var viewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far should be from projection matrix? + */var TrianglesDataTexturePickNormalsFlatRenderer=/*#__PURE__*/function(){function TrianglesDataTexturePickNormalsFlatRenderer(scene){_classCallCheck(this,TrianglesDataTexturePickNormalsFlatRenderer);this._scene=scene;this._hash=this._getHash();this._allocate();}_createClass(TrianglesDataTexturePickNormalsFlatRenderer,[{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"drawLayer",value:function drawLayer(frameCtx,dataTextureLayer,renderPass){var model=dataTextureLayer.model;var scene=model.scene;var camera=scene.camera;var gl=scene.canvas.gl;var state=dataTextureLayer._state;var origin=dataTextureLayer._state.origin;if(!this._program){this._allocate(dataTextureLayer);}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram();}this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerObjectIdPositionsDecodeMatrix);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},1);this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerVertexIdCoordinates);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},2);this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerObjectIdColorsAndFlags);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},3);gl.uniform1i(this._uRenderPass,renderPass);gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);gl.uniform2fv(this._uPickClipPos,frameCtx.pickClipPos);gl.uniformMatrix4fv(this._uWorldMatrix,false,model.worldMatrix);var pickViewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var viewMatrix=origin?createRTCViewMat(pickViewMatrix,origin):pickViewMatrix;gl.uniformMatrix4fv(this._uViewMatrix,false,viewMatrix);gl.uniformMatrix4fv(this._uProjMatrix,false,frameCtx.pickProjMatrix);if(scene.logarithmicDepthBufferEnabled){var logDepthBufFC=2.0/(Math.log(camera.project.far+1.0)/Math.LN2);// TODO: Far should be from projection matrix? gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=dataTextureLayer.layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0){this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdPortionIds8Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},4);this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdIndices8Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},5);gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdPortionIds16Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},4);this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdIndices16Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},5);gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdPortionIds32Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},4);this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdIndices32Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},5);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i314=0,len=scene._sectionPlanesState.sectionPlanes.length;_i3140;var src=[];src.push("#version 300 es");src.push("// Triangles dataTexture pick flat normals vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");src.push("in uvec3 packedVertexId;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");// src.push("uniform sampler2D uOcclusionTexture;"); -src.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;");src.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;");src.push("uniform usampler2D uTexturePerVertexIdCoordinates;");src.push("uniform usampler2D uTexturePerPolygonIdIndices;");src.push("uniform isampler2D uTexturePerPolygonIdNormals;");src.push("uniform usampler2D uTexturePerPolygonIdPortionIds;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("out vec4 vWorldPosition;");if(clipping){src.push("out int vFlags2;");}src.push("void main(void) {");// constants +if(state.numIndices8Bits>0){this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdPortionIds8Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},4);this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdIndices8Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},5);gl.drawArrays(gl.TRIANGLES,0,state.numIndices8Bits);}if(state.numIndices16Bits>0){this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdPortionIds16Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},4);this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdIndices16Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},5);gl.drawArrays(gl.TRIANGLES,0,state.numIndices16Bits);}if(state.numIndices32Bits>0){this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdPortionIds32Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},4);this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function bind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,state.texturePerPolygonIdIndices32Bits);return true;},unbind:function unbind(unit){gl.activeTexture(gl["TEXTURE"+unit]);gl.bindTexture(gl.TEXTURE_2D,null);}},5);gl.drawArrays(gl.TRIANGLES,0,state.numIndices32Bits);}frameCtx.drawElements++;}},{key:"_allocate",value:function _allocate(){var scene=this._scene;var gl=scene.canvas.gl;this._program=new Program(gl,this._buildShader());if(this._program.errors){this.errors=this._program.errors;return;}var program=this._program;this._uRenderPass=program.getLocation("renderPass");this._uPickInvisible=program.getLocation("pickInvisible");this._uPickClipPos=program.getLocation("pickClipPos");this._uPositionsDecodeMatrix=program.getLocation("positionsDecodeMatrix");this._uWorldMatrix=program.getLocation("worldMatrix");this._uViewMatrix=program.getLocation("viewMatrix");this._uProjMatrix=program.getLocation("projMatrix");this._uSectionPlanes=[];for(var _i314=0,len=scene._sectionPlanesState.sectionPlanes.length;_i3140;var src=[];src.push("#version 300 es");src.push("// Triangles dataTexture pick flat normals vertex shader");src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("precision highp usampler2D;");src.push("precision highp isampler2D;");src.push("precision highp sampler2D;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("precision mediump usampler2D;");src.push("precision mediump isampler2D;");src.push("precision mediump sampler2D;");src.push("#endif");src.push("uniform int renderPass;");src.push("in uvec3 packedVertexId;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}src.push("uniform bool pickInvisible;");src.push("uniform mat4 worldMatrix;");src.push("uniform mat4 viewMatrix;");src.push("uniform mat4 projMatrix;");// src.push("uniform sampler2D uOcclusionTexture;"); +src.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;");src.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;");src.push("uniform usampler2D uTexturePerVertexIdCoordinates;");src.push("uniform usampler2D uTexturePerPolygonIdIndices;");src.push("uniform isampler2D uTexturePerPolygonIdNormals;");src.push("uniform usampler2D uTexturePerPolygonIdPortionIds;");if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("uniform vec2 pickClipPos;");src.push("vec4 remapClipPos(vec4 clipPos) {");src.push(" clipPos.xy /= clipPos.w;");src.push(" clipPos.xy -= pickClipPos;");src.push(" clipPos.xy *= clipPos.w;");src.push(" return clipPos;");src.push("}");src.push("out vec4 vWorldPosition;");if(clipping){src.push("out int vFlags2;");}src.push("void main(void) {");// constants // src.push("int objectIndex = int(packedVertexId.g) & 4095;"); src.push("int polygonIndex = gl_VertexID / 3;");src.push("int h_normal_index = polygonIndex & 4095;");src.push("int v_normal_index = polygonIndex >> 12;");// get packed object-id src.push("int h_packed_object_id_index = ((polygonIndex >> 3) / 2) & 4095;");src.push("int v_packed_object_id_index = ((polygonIndex >> 3) / 2) >> 12;");src.push("ivec3 packedObjectId = ivec3(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).rgb);");src.push("int objectIndex;");src.push("if (((polygonIndex >> 3) % 2) == 0) {");src.push(" objectIndex = (packedObjectId.r << 4) + (packedObjectId.g >> 4);");src.push("} else {");src.push(" objectIndex = ((packedObjectId.g & 15) << 8) + packedObjectId.b;");src.push("}");src.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);");// get vertex base @@ -11539,7 +11539,7 @@ src.push("vec3 position1 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2 src.push("vec3 normal = normalize(cross(position3 - position1, position2 - position1));");src.push("int vertexNumber = gl_VertexID % 3;");src.push("vec3 position;");src.push("if (vertexNumber == 0) position = position1;");src.push("else if (vertexNumber == 1) position = position2;");src.push("else position = position3;");// flags.w = NOT_RENDERED | PICK // renderPass = PICK src.push("if (int(flags.w) != renderPass) {");src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);");// Cull vertex -src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vWorldPosition = worldPosition;");if(clipping){src.push(" vFlags2 = flags2.r;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = clipPos;");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture pick flat normals fragment shader");src.push("#extension GL_OES_standard_derivatives : enable");if(scene.logarithmicDepthBufferEnabled){src.push("#extension GL_EXT_frag_depth : enable");}src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("in vec4 vWorldPosition;");if(clipping){src.push("in int vFlags2;");for(var i=0;i 0;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outNormal = ivec4(worldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTexturePickNormalsFlatRenderer;}();/** +src.push(" } else {");src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");if(scene.entityOffsetsEnabled){src.push(" worldPosition.xyz = worldPosition.xyz + offset;");}src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");src.push(" vWorldPosition = worldPosition;");if(clipping){src.push(" vFlags2 = flags2.r;");}src.push("vec4 clipPos = projMatrix * viewPosition;");if(scene.logarithmicDepthBufferEnabled){src.push("vFragDepth = 1.0 + clipPos.w;");src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");}src.push("gl_Position = remapClipPos(clipPos);");src.push(" }");src.push("}");return src;}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var clipping=sectionPlanesState.sectionPlanes.length>0;var src=[];src.push('#version 300 es');src.push("// Triangles dataTexture pick flat normals fragment shader");src.push("#extension GL_OES_standard_derivatives : enable");if(scene.logarithmicDepthBufferEnabled){src.push("#extension GL_EXT_frag_depth : enable");}src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");src.push("precision highp float;");src.push("precision highp int;");src.push("#else");src.push("precision mediump float;");src.push("precision mediump int;");src.push("#endif");if(scene.logarithmicDepthBufferEnabled){src.push("in float isPerspective;");src.push("uniform float logDepthBufFC;");src.push("in float vFragDepth;");}src.push("in vec4 vWorldPosition;");if(clipping){src.push("in int vFlags2;");for(var i=0;i 0;");src.push(" if (clippable) {");src.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }");src.push(" }");}if(scene.logarithmicDepthBufferEnabled){src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");}src.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );");src.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );");src.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );");src.push(" outNormal = ivec4(worldNormal * float(".concat(math.MAX_INT,"), 1.0);"));src.push("}");return src;}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;}}]);return TrianglesDataTexturePickNormalsFlatRenderer;}();/** * @private */var TrianglesDataTextureRenderers=/*#__PURE__*/function(){function TrianglesDataTextureRenderers(scene){_classCallCheck(this,TrianglesDataTextureRenderers);this._scene=scene;}_createClass(TrianglesDataTextureRenderers,[{key:"_compile",value:function _compile(){if(this._colorRenderer&&!this._colorRenderer.getValid()){this._colorRenderer.destroy();this._colorRenderer=null;}if(this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()){this._colorRendererWithSAO.destroy();this._colorRendererWithSAO=null;}if(this._flatColorRenderer&&!this._flatColorRenderer.getValid()){this._flatColorRenderer.destroy();this._flatColorRenderer=null;}if(this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()){this._flatColorRendererWithSAO.destroy();this._flatColorRendererWithSAO=null;}if(this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()){this._colorQualityRendererWithSAO.destroy();this._colorQualityRendererWithSAO=null;}if(this._depthRenderer&&!this._depthRenderer.getValid()){this._depthRenderer.destroy();this._depthRenderer=null;}if(this._normalsRenderer&&!this._normalsRenderer.getValid()){this._normalsRenderer.destroy();this._normalsRenderer=null;}if(this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()){this._silhouetteRenderer.destroy();this._silhouetteRenderer=null;}if(this._edgesRenderer&&!this._edgesRenderer.getValid()){this._edgesRenderer.destroy();this._edgesRenderer=null;}if(this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()){this._edgesColorRenderer.destroy();this._edgesColorRenderer=null;}if(this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()){this._pickMeshRenderer.destroy();this._pickMeshRenderer=null;}if(this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()){this._pickDepthRenderer.destroy();this._pickDepthRenderer=null;}if(this._vertexDepthRenderer&&!this._vertexDepthRenderer.getValid()){this._vertexDepthRenderer.destroy();this._vertexDepthRenderer=null;}if(this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()){this._snapDepthBufInitRenderer.destroy();this._snapDepthBufInitRenderer=null;}if(this._pickNormalsRenderer&&this._pickNormalsRenderer.getValid()===false){this._pickNormalsRenderer.destroy();this._pickNormalsRenderer=null;}if(this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.getValid()===false){this._pickNormalsFlatRenderer.destroy();this._pickNormalsFlatRenderer=null;}if(this._occlusionRenderer&&this._occlusionRenderer.getValid()===false){this._occlusionRenderer.destroy();this._occlusionRenderer=null;}}},{key:"colorRenderer",get:function get(){if(!this._colorRenderer){this._colorRenderer=new TrianglesDataTextureColorRenderer(this._scene,false);}return this._colorRenderer;}},{key:"colorRendererWithSAO",get:function get(){if(!this._colorRendererWithSAO){this._colorRendererWithSAO=new TrianglesDataTextureColorRenderer(this._scene,true);}return this._colorRendererWithSAO;}},{key:"colorQualityRendererWithSAO",get:function get(){if(!this._colorQualityRendererWithSAO){this._colorQualityRendererWithSAO=new TrianglesDataTextureColorQualityRenderer(this._scene,true);}return this._colorQualityRendererWithSAO;}},{key:"silhouetteRenderer",get:function get(){if(!this._silhouetteRenderer){this._silhouetteRenderer=new TrianglesDataTextureSilhouetteRenderer(this._scene);}return this._silhouetteRenderer;}},{key:"depthRenderer",get:function get(){if(!this._depthRenderer){this._depthRenderer=new TrianglesDataTextureDepthRenderer(this._scene);}return this._depthRenderer;}},{key:"normalsRenderer",get:function get(){if(!this._normalsRenderer){this._normalsRenderer=new TrianglesDataTextureNormalsRenderer(this._scene);}return this._normalsRenderer;}},{key:"edgesRenderer",get:function get(){if(!this._edgesRenderer){this._edgesRenderer=new TrianglesDataTextureEdgesRenderer(this._scene);}return this._edgesRenderer;}},{key:"edgesColorRenderer",get:function get(){if(!this._edgesColorRenderer){this._edgesColorRenderer=new TrianglesDataTextureEdgesColorRenderer(this._scene);}return this._edgesColorRenderer;}},{key:"pickMeshRenderer",get:function get(){if(!this._pickMeshRenderer){this._pickMeshRenderer=new TrianglesDataTexturePickMeshRenderer(this._scene);}return this._pickMeshRenderer;}},{key:"pickNormalsRenderer",get:function get(){if(!this._pickNormalsRenderer){this._pickNormalsRenderer=new TrianglesDataTexturePickNormalsRenderer(this._scene);}return this._pickNormalsRenderer;}},{key:"pickNormalsFlatRenderer",get:function get(){if(!this._pickNormalsFlatRenderer){this._pickNormalsFlatRenderer=new TrianglesDataTexturePickNormalsFlatRenderer(this._scene);}return this._pickNormalsFlatRenderer;}},{key:"pickDepthRenderer",get:function get(){if(!this._pickDepthRenderer){this._pickDepthRenderer=new TrianglesDataTexturePickDepthRenderer(this._scene);}return this._pickDepthRenderer;}},{key:"vertexDepthRenderer",get:function get(){if(!this._vertexDepthRenderer){this._vertexDepthRenderer=new TrianglesDataTextureSnapDepthRenderer(this._scene);}return this._vertexDepthRenderer;}},{key:"snapDepthBufInitRenderer",get:function get(){if(!this._snapDepthBufInitRenderer){this._snapDepthBufInitRenderer=new TrianglesDataTextureSnapDepthBufInitRenderer(this._scene);}return this._snapDepthBufInitRenderer;}},{key:"occlusionRenderer",get:function get(){if(!this._occlusionRenderer){this._occlusionRenderer=new TrianglesDataTextureOcclusionRenderer(this._scene);}return this._occlusionRenderer;}},{key:"_destroy",value:function _destroy(){if(this._colorRenderer){this._colorRenderer.destroy();}if(this._colorRendererWithSAO){this._colorRendererWithSAO.destroy();}if(this._flatColorRenderer){this._flatColorRenderer.destroy();}if(this._flatColorRendererWithSAO){this._flatColorRendererWithSAO.destroy();}if(this._colorQualityRendererWithSAO){this._colorQualityRendererWithSAO.destroy();}if(this._depthRenderer){this._depthRenderer.destroy();}if(this._normalsRenderer){this._normalsRenderer.destroy();}if(this._silhouetteRenderer){this._silhouetteRenderer.destroy();}if(this._edgesRenderer){this._edgesRenderer.destroy();}if(this._edgesColorRenderer){this._edgesColorRenderer.destroy();}if(this._pickMeshRenderer){this._pickMeshRenderer.destroy();}if(this._pickDepthRenderer){this._pickDepthRenderer.destroy();}if(this._vertexDepthRenderer){this._vertexDepthRenderer.destroy();}if(this._snapDepthBufInitRenderer){this._snapDepthBufInitRenderer.destroy();}if(this._pickNormalsRenderer){this._pickNormalsRenderer.destroy();}if(this._pickNormalsFlatRenderer){this._pickNormalsFlatRenderer.destroy();}if(this._occlusionRenderer){this._occlusionRenderer.destroy();}}}]);return TrianglesDataTextureRenderers;}();var cachdRenderers={};/** * @private @@ -14896,20 +14896,20 @@ if(selectedFillTransparentBinLen>0){for(i=0;i1&&arguments[1]!==undefined?arguments[1]:_pickResult;pickResult.reset();updateDrawlist();var look;var pickViewMatrix=null;var pickProjMatrix=null;pickResult.pickSurface=params.pickSurface;if(params.canvasPos){canvasPos[0]=params.canvasPos[0];canvasPos[1]=params.canvasPos[1];pickViewMatrix=scene.camera.viewMatrix;pickProjMatrix=scene.camera.projMatrix;pickResult.canvasPos=params.canvasPos;}else{// Picking with arbitrary World-space ray + */this.pick=function(){var tempVec3a=math.vec3();math.mat4();var tempMat4b=math.mat4();var randomVec3=math.vec3();var up=math.vec3([0,1,0]);var _pickResult=new PickResult();var nearAndFar=math.vec2();var canvasPos=math.vec3();var worldRayOrigin=math.vec3();var worldRayDir=math.vec3();math.vec3();math.vec3();return function(params){var pickResult=arguments.length>1&&arguments[1]!==undefined?arguments[1]:_pickResult;pickResult.reset();updateDrawlist();var look;var pickViewMatrix=null;var pickProjMatrix=null;pickResult.pickSurface=params.pickSurface;if(params.canvasPos){canvasPos[0]=params.canvasPos[0];canvasPos[1]=params.canvasPos[1];pickViewMatrix=scene.camera.viewMatrix;pickProjMatrix=scene.camera.projMatrix;pickResult.canvasPos=params.canvasPos;}else{// Picking with arbitrary World-space ray // Align camera along ray and fire ray through center of canvas -var pickFrustumMatrix=math.frustumMat4(-1,1,-1,1,0.01,scene.camera.project.far,tempMat4a);if(params.matrix){pickViewMatrix=params.matrix;pickProjMatrix=pickFrustumMatrix;}else{worldRayOrigin.set(params.origin||[0,0,0]);worldRayDir.set(params.direction||[0,0,1]);look=math.addVec3(worldRayOrigin,worldRayDir,tempVec3a);randomVec3[0]=Math.random();randomVec3[1]=Math.random();randomVec3[2]=Math.random();math.normalizeVec3(randomVec3);math.cross3Vec3(worldRayDir,randomVec3,up);pickViewMatrix=math.lookAtMat4v(worldRayOrigin,look,up,tempMat4b);pickProjMatrix=pickFrustumMatrix;pickResult.origin=worldRayOrigin;pickResult.direction=worldRayDir;}canvasPos[0]=canvas.clientWidth*0.5;canvasPos[1]=canvas.clientHeight*0.5;}for(var type in drawableTypeInfo){if(drawableTypeInfo.hasOwnProperty(type)){var drawableList=drawableTypeInfo[type].drawableList;for(var _i411=0,len=drawableList.length;_i4110){var pixelNumber=Math.floor(_i416/4);var w=vertexPickBuffer.size[0];var x=pixelNumber%w-Math.floor(w/2);var y=Math.floor(pixelNumber/w)-Math.floor(w/2);var dist=Math.sqrt(Math.pow(x,2)+Math.pow(y,2));snapPickResult.push({x:x,y:y,dist:dist,isVertex:snapToVertex&&snapToEdge?snapPickResultArray[_i416+3]>layerParamsSnap.length/2:snapToVertex,result:[snapPickResultArray[_i416+0],snapPickResultArray[_i416+1],snapPickResultArray[_i416+2],snapPickResultArray[_i416+3]]});}}var snappedWorldPos=null;var snapType=null;if(snapPickResult.length>0){// vertex snap first, then edge snap snapPickResult.sort(function(a,b){if(a.isVertex!==b.isVertex){return a.isVertex?-1:1;}else{return a.dist-b.dist;}});snapType=snapPickResult[0].isVertex?"vertex":"edge";snapPickResult=snapPickResult[0].result;var pickedLayerParmas=layerParamsSnap[snapPickResult[3]];var _origin12=pickedLayerParmas.origin;var _scale4=pickedLayerParmas.coordinateScale;snappedWorldPos=[snapPickResult[0]*_scale4[0]+_origin12[0],snapPickResult[1]*_scale4[1]+_origin12[1],snapPickResult[2]*_scale4[2]+_origin12[2]];}if(null===worldPos&&null==snappedWorldPos){// If neither regular pick or snap pick, return null return null;}var snappedCanvasPos=null;if(null!==snappedWorldPos){snappedCanvasPos=scene.camera.projectWorldPos(snappedWorldPos);}return{snapType:snapType,snappedToVertex:snapType==="vertex",snappedToEdge:snapType==="edge",worldPos:worldPos,snappedWorldPos:snappedWorldPos,snappedCanvasPos:snappedCanvasPos};};function unpackDepth(depthZ){var vec=[depthZ[0]/256.0,depthZ[1]/256.0,depthZ[2]/256.0,depthZ[3]/256.0];var bitShift=[1.0/(256.0*256.0*256.0),1.0/(256.0*256.0),1.0/256.0,1.0];return math.dotVec4(vec,bitShift);}function gpuPickWorldNormal(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,pickResult){frameCtx.reset();frameCtx.backfaces=true;frameCtx.frontface=true;// "ccw" -frameCtx.pickOrigin=pickResult.origin;frameCtx.pickViewMatrix=pickViewMatrix;frameCtx.pickProjMatrix=pickProjMatrix;var pickNormalBuffer=renderBufferManager.getRenderBuffer("pick-normal");pickNormalBuffer.bind(gl.RGBA32I);gl.viewport(0,0,gl.drawingBufferWidth,gl.drawingBufferHeight);gl.enable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);gl.clear(gl.DEPTH_BUFFER_BIT);gl.clearBufferiv(gl.COLOR,0,new Int32Array([0,0,0,0]));pickable.drawPickNormals(frameCtx);// Draw color-encoded fragment World-space normals -var resolutionScale=scene.canvas.resolutionScale;var pix=pickNormalBuffer.read(Math.round(canvasPos[0]*resolutionScale),Math.round(canvasPos[1]*resolutionScale),gl.RGBA_INTEGER,gl.INT,Int32Array,4);pickNormalBuffer.unbind();var worldNormal=[pix[0]/math.MAX_INT,pix[1]/math.MAX_INT,pix[2]/math.MAX_INT];math.normalizeVec3(worldNormal);pickResult.worldNormal=worldNormal;}/** +frameCtx.pickOrigin=pickResult.origin;frameCtx.pickViewMatrix=pickViewMatrix;frameCtx.pickProjMatrix=pickProjMatrix;frameCtx.pickClipPos=[getClipPosX(canvasPos[0],gl.drawingBufferWidth),getClipPosY(canvasPos[1],gl.drawingBufferHeight)];gl.viewport(0,0,1,1);gl.enable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);gl.clear(gl.DEPTH_BUFFER_BIT);gl.clearBufferiv(gl.COLOR,0,new Int32Array([0,0,0,0]));pickable.drawPickNormals(frameCtx);// Draw color-encoded fragment World-space normals +var pix=pickBuffer.read(0,0);var worldNormal=[pix[0]/math.MAX_INT,pix[1]/math.MAX_INT,pix[2]/math.MAX_INT];math.normalizeVec3(worldNormal);pickResult.worldNormal=worldNormal;}/** * Adds a {@link Marker} for occlusion testing. * @param marker */this.addMarker=function(marker){this._occlusionTester=this._occlusionTester||new OcclusionTester(scene,renderBufferManager);this._occlusionTester.addMarker(marker);scene.occlusionTestCountdown=0;};/** diff --git a/dist/xeokit-sdk.min.cjs.js b/dist/xeokit-sdk.min.cjs.js index e7aae53314..658688ea84 100644 --- a/dist/xeokit-sdk.min.cjs.js +++ b/dist/xeokit-sdk.min.cjs.js @@ -1,4 +1,4 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let r=!0,l=r?Float64Array:Float32Array;const o=new l(16),c=new l(16),u=new l(4),h={setDoublePrecisionEnabled(e){r=e,l=r?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>r,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new l(e||2),vec3:e=>new l(e||3),vec4:e=>new l(e||4),mat3:e=>new l(e||9),mat3ToMat4:(e,t=new l(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new l(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new l(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new l(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>h.dotVec4(e,e),lenVec4:e=>Math.sqrt(h.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>h.dotVec3(e,e),sqLenVec2:e=>h.dotVec2(e,e),lenVec3:e=>Math.sqrt(h.sqLenVec3(e)),distVec3:(()=>{const e=new l(3);return(t,s)=>h.lenVec3(h.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(h.sqLenVec2(e)),distVec2:(()=>{const e=new l(2);return(t,s)=>h.lenVec2(h.subVec2(t,s,e))})(),rcpVec3:(e,t)=>h.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/h.lenVec4(e);return h.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/h.lenVec3(e);return h.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/h.lenVec2(e);return h.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=h.dotVec3(e,t)/Math.sqrt(h.sqLenVec3(e)*h.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new l(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=h.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=h.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=h.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||h.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>h.m4s(0),setMat4ToOnes:()=>h.m4s(1),diagonalMat4v:e=>new l([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>h.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>h.diagonalMat4c(e,e,e,e),identityMat4:(e=new l(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new l(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>h.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new l(9));const n=e[0],i=e[3],a=e[6],r=e[1],o=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+o*I+c*v,s[4]=r*d+o*y+c*w,s[7]=r*f+o*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=h.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||h.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||h.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.translationMat4v(e,i))})(),translationMat4s:(e,t)=>h.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>h.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=h.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,p,A,d,f,I;return u=l*o,p=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||h.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*p+d,s[7]=0,s[8]=r*A+f,s[9]=r*p-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>h.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=h.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=h.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>h.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=h.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,p=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=p+v,s[2]=A-m,s[3]=0,s[4]=p-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=h.vec4()){const n=h.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],p=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(p,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(p,-1,1)),Math.abs(p)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(p,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(p,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=h.mat4())=>(h.quaternionToRotationMat4(t,n),h.scaleMat4v(s,n),h.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new l(3),t=new l(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=h.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=h.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=h.lenVec3(e);h.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,p=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=p,t[9]*=p,t[10]*=p,h.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=h.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],p=t[1],A=t[2];if(i===u&&a===p&&r===A)return h.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-p,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>h.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=h.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];h.addVec4(i,n,o),h.subVec4(i,n,c);const a=2*n[2],r=c[0],l=c[1],u=c[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=o[0]/r,s[9]=o[1]/l,s[10]=-o[2]/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/u,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],h.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=h.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new l(16),t=new l(16),s=new l(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||h.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||h.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=h.vec4()){const n=e[0]*h.DEGTORAD/2,i=e[1]*h.DEGTORAD/2,a=e[2]*h.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),p=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"YXZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"ZXY"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"ZYX"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"YZX"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o-c*u*p):"XZY"===t&&(s[0]=c*l*o-r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o+c*u*p),s},mat4ToQuaternion(e,t=h.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let p;const A=s+r+u;return A>0?(p=.5/Math.sqrt(A+1),t[3]=.25/p,t[0]=(c-l)*p,t[1]=(i-o)*p,t[2]=(a-n)*p):s>r&&s>u?(p=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/p,t[0]=.25*p,t[1]=(n+a)/p,t[2]=(i+o)/p):r>u?(p=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/p,t[0]=(n+a)/p,t[1]=.25*p,t[2]=(l+c)/p):(p=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/p,t[0]=(i+o)/p,t[1]=(l+c)/p,t[2]=.25*p),t},vec3PairToQuaternion(e,t,s=h.vec4()){const n=Math.sqrt(h.dotVec3(e,e)*h.dotVec3(t,t));let i=n+h.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):h.cross3Vec3(e,t,s),s[3]=i,h.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=h.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new l(16);return(t,s,n)=>(n=n||h.vec3(),h.quaternionToRotationMat4(t,e),h.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=h.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,p=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+p*-o-A*-l,s[1]=p*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-p*-r,s},quaternionToMat4(e,t){t=h.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,p=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+p,t[2]=f-u,t[4]=d-p,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=h.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>h.normalizeQuaternion(h.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=h.vec4()){const s=(e=h.normalizeQuaternion(e,u))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new l(e||6),AABB2:e=>new l(e||4),OBB3:e=>new l(e||32),OBB2:e=>new l(e||16),Sphere3:(e,t,s,n)=>new l([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new l(3),t=new l(3),s=new l(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],h.subVec3(t,e,s),Math.abs(h.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=h.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],p=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>p?u:p,Math.abs(h.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||h.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||h.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=h.AABB3())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MAX_DOUBLE,e[3]=h.MIN_DOUBLE,e[4]=h.MIN_DOUBLE,e[5]=h.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=h.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new l(3);return(t,s,n)=>{s=s||h.AABB3();let i,a,r,l=h.MAX_DOUBLE,o=h.MAX_DOUBLE,c=h.MAX_DOUBLE,u=h.MIN_DOUBLE,p=h.MIN_DOUBLE,A=h.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>p&&(p=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=p,s[5]=A,s}})(),OBB3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new l(3);return(t,s)=>{s=s||h.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=p);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ip&&(p=u);return n[3]=p,n}})(),getSphere3Center:(e,t=h.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=h.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MIN_DOUBLE,e[3]=h.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=h.AABB2()){let s,n,i,a,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=h.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,p=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+p*p+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=p/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3);return(a,r,l,o,c,u)=>{u=u||h.vec3();const p=h.subVec3(o,l,e),A=h.subVec3(c,l,t),d=h.cross3Vec3(r,A,s),f=h.dotVec3(p,d);if(f<1e-6)return null;const I=h.subVec3(a,l,n),y=h.dotVec3(I,d);if(y<0||y>f)return null;const m=h.cross3Vec3(I,p,i),v=h.dotVec3(r,m);if(v<0||y+v>f)return null;const w=h.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3);return(i,a,r,l,o,c)=>{c=c||h.vec3(),a=h.normalizeVec3(a,e);const u=h.subVec3(l,r,t),p=h.subVec3(o,r,s),A=h.cross3Vec3(u,p,n);h.normalizeVec3(A,A);const d=-h.dotVec3(r,A),f=-(h.dotVec3(i,A)+d)/h.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i,a,r,l)=>{const o=h.subVec3(r,i,e),c=h.subVec3(a,i,t),u=h.subVec3(n,i,s),p=h.dotVec3(o,o),A=h.dotVec3(o,c),d=h.dotVec3(o,u),f=h.dotVec3(c,c),I=h.dotVec3(c,u),y=p*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(p*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=h.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3);return(r,l,o)=>{let c,u;const p=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3),r=new l(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let p=0;p>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,p;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new l(4),t=new l(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,h.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],h.transformVec3(s,e,t),h.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new l(16),t=new l(16),s=new l(4),n=new l(4),i=new l(4),a=new l(4);return(r,l,o,c,u,p)=>{const A=h.mulMat4(o,l,e),d=h.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,h.transformVec4(d,s,n),h.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,h.transformVec4(d,i,a),h.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],h.subVec3(a,n,p),h.normalizeVec3(p)}})(),canvasPosToLocalRay:(()=>{const e=new l(3),t=new l(3);return(s,n,i,a,r,l,o)=>{h.canvasPosToWorldRay(s,n,i,r,e,t),h.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new l(16),t=new l(4),s=new l(4);return(n,i,a,r,l)=>{const o=h.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,h.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],h.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new l(6),o={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return o.triangles=s,o.leaf=!0,o;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),o.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};h.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class p{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const A={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var d=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{v.removeItem(e.id),delete P.scenes[e.id],delete m[e.id],A.components.scenes--}))},this.clear=function(){let e;for(const t in P.scenes)P.scenes.hasOwnProperty(t)&&(e=P.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete P.scenes[e.id]))},this.scheduleTask=function(e,t){w.push(e),w.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;w.length>0&&(e<0||n0&&E>0){var t=1e3/E;D+=t,T.push(t),T.length>=30&&(D-=T.shift()),A.frame.fps=Math.round(D/T.length)}!function(e){const t=P.runTasks(e+10),s=P.getNumTasks();A.frame.tasksRun=t,A.frame.tasksScheduled=s,A.frame.tasksBudget=10}(e),function(e){for(var t in g.time=e,P.scenes)if(P.scenes.hasOwnProperty(t)){var s=P.scenes[t];g.sceneId=t,g.startTime=s.startTime,g.deltaTime=null!=g.prevTime?g.time-g.prevTime:0,s.fire("tick",g,!0)}g.prevTime=e}(e),function(){const e=P.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=m[r],n||(n=m[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),b=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R);class C{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof C))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+y.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(y.isNumeric(s)||y.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+y.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+y.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+y.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():P.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(h.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){K.set(this._viewPos),K[3]=1,h.transformPoint4(this.scene.camera.projMatrix,K,Y);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+Y[0]/Y[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-Y[1]/Y[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof z?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),O(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class q{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class J{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class Z{constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var $=h.vec3(),ee=h.vec3();class te extends C{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new X(s,t.origin),this._cornerMarker=new X(s,t.corner),this._targetMarker=new X(s,t.target),this._originWorld=h.vec3(),this._cornerWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new J(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new J(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new J(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new q(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new q(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new Z(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(h.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,p=t.length;u1?i.other:i.one,i?(i=ie(i,[t]),s&&(i=ie(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const a=this._events[t];return void 0!==a&&s(a),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function ne(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),a=this.getPoint(n),r=h.subVec3(a,i,[]);return h.normalizeVec3(r,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),a=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),a+=h.lenVec3(h.subVec3(t,i,[])),n.push(a),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,a=n.length;s=t||e*n[a-1];for(var r,l=0,o=a-1;l<=o;)if((r=n[i=Math.floor(l+(o-l)/2)]-s)<0)l=i+1;else{if(!(r>0)){o=i;break}o=i-1}if(n[i=o]===s)return i/(a-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(a-1)}}class re extends ae{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,a=t[0===n?n:n-1],r=t[n],l=t[n>t.length-2?t.length-1:n+1],o=t[n>t.length-3?t.length-1:n+2],c=h.vec3();return c[0]=h.catmullRomInterpolate(a[0],r[0],l[0],o[0],i),c[1]=h.catmullRomInterpolate(a[1],r[1],l[1],o[1],i),c[2]=h.catmullRomInterpolate(a[2],r[2],l[2],o[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const le=h.vec3();const oe=h.vec3(),ce=h.vec3(),ue=h.vec3(),he=h.vec3(),pe=h.vec3();class Ae extends C{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,s){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=s;const n=this.scene.camera,i=!!e.projection&&e.projection!==n.projection;let a,r,l,o,c;if(this._eye1[0]=n.eye[0],this._eye1[1]=n.eye[1],this._eye1[2]=n.eye[2],this._look1[0]=n.look[0],this._look1[1]=n.look[1],this._look1[2]=n.look[2],this._up1[0]=n.up[0],this._up1[1]=n.up[1],this._up1[2]=n.up[2],this._orthoScale1=n.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)a=e.aabb;else if(6===e.length)a=e;else if(e.eye&&e.look||e.up)r=e.eye,l=e.look,o=e.up;else if(e.eye)r=e.eye;else if(e.look)l=e.look;else{let n=e;if((y.isNumeric(n)||y.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+y.inQuotes(c)),void(t&&(s?t.call(s):t()));i||(a=n.aabb||this.scene.aabb)}const u=e.poi;if(a){if(a[3]=1;e>1&&(e=1);const s=this.easing?Ae._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(n.eye,n.look,pe),n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,ue),n.look=h.subVec3(ue,pe,ce)):this._flyingLook&&(n.look=h.lerpVec3(s,0,1,this._look1,this._look2,ce),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,he)):this._flyingEyeLookUp&&(n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,ue),n.look=h.lerpVec3(s,0,1,this._look1,this._look2,ce),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,he)),this._projection2){const t="ortho"===this._projection2?Ae._easeOutExpo(e,0,1,1):Ae._easeInCubic(e,0,1,1);n.customProjection.matrix=h.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();P.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class de extends C{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Ae(this),this._t=0,this.state=de.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case de.SCRUBBING:return;case de.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=de.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case de.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=de.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=de.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=de.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=de.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=de.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=de.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=de.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}de.STOPPED=0,de.SCRUBBING=1,de.PLAYING=2,de.PLAYING_TO=3;class fe extends C{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),A.memory.meshes++}destroy(){super.destroy(),A.memory.meshes--}}const Ie=new e({});class ye{constructor(e){this.id=Ie.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Ie.removeItem(this.id)}}class me{constructor(e,t,s,n,i,a,r,l,o){switch(this._gl=e,this.type=t,this.allocated=!1,s.constructor){case Uint8Array:this.itemType=e.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=e.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=e.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=e.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=e.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=e.INT,this.itemByteSize=4;break;default:this.itemType=e.FLOAT,this.itemByteSize=4}this.usage=a,this.length=0,this.dataLength=n,this.numItems=0,this.itemSize=i,this.normalized=!!r,this.stride=l||0,this.offset=o||0,this._allocate(s)}_allocate(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}var ve=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();const we=function(){const e=h.mat4(),t=h.mat4();return function(s,n){n=n||h.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return h.identityMat4(e),h.translationMat4v(s,e),h.identityMat4(t),h.scalingMat4v([l/u,o/u,c/u],t),h.mulMat4(e,t,n),n}}();var ge=function(){const e=h.mat4(),t=h.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function be(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function De(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const Pe={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=Ee(e,l,"floor","ceil"),n=be(s),a=De(e,l,n),a>r&&(i=s,r=a),s=Ee(e,l,"ceil","ceil"),n=be(s),a=De(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},Re=A.memory,Ce=h.AABB3();class _e extends fe{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new ye({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=Pe.getPositionsBounds(t.positions),n=Pe.compressPositions(t.positions,e.min,e.max);s.positions=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=Pe.getUVBounds(t.uv),n=Pe.compressUVs(t.uv,e.min,e.max);s.uv=n.quantized,s.uvDecodeMatrix=n.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);t.normals&&(this._state.compressGeometry?s.normals=Pe.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),Re.meshes++,this._buildVBOs()}_buildVBOs(){const e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),Re.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new me(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),Re.positions+=e.positionsBuf.numItems),e.normals){let s=e.compressGeometry;e.normalsBuf=new me(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,s),Re.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new me(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),Re.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new me(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),Re.uvs+=e.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=ve(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),Re.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=h.buildPickTriangles(e.positions,e.indices,e.compressGeometry),n=s.positions,i=s.colors;this._pickTrianglePositionsBuf=new me(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new me(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),Re.positions+=this._pickTrianglePositionsBuf.numItems,Re.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}_webglContextLost(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}_webglContextRestored(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),Pe.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=Pe.getPositionsBounds(e),n=Pe.compressPositions(e,s.min,s.max);e=n.quantized,t.positionsDecodeMatrix=n.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),Pe.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),Pe.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=h.AABB3()),h.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=h.OBB3()),h.positions3ToAABB3(this._state.positions,Ce,this._state.positionsDecodeMatrix),h.AABB3ToOBB3(Ce,this._obb),this._obbDirty=!1),this._obb}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),Re.meshes--}}const Be=A.memory,Oe=h.AABB3();class Se extends fe{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new ye({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=h.OBB3();const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var i;if(t.positionsDecodeMatrix);else{const e=Pe.getPositionsBounds(t.positions),a=Pe.compressPositions(t.positions,e.min,e.max);i=a.quantized,s.positionsDecodeMatrix=a.decodeMatrix,s.positionsBuf=new me(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),Be.positions+=s.positionsBuf.numItems,h.positions3ToAABB3(t.positions,this._aabb),h.positions3ToAABB3(i,Oe,s.positionsDecodeMatrix),h.AABB3ToOBB3(Oe,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new me(n,n.ARRAY_BUFFER,e,e.length,4,n.STATIC_DRAW),Be.colors+=s.colorsBuf.numItems}if(t.uv){const e=Pe.getUVBounds(t.uv),i=Pe.compressUVs(t.uv,e.min,e.max),a=i.quantized;s.uvDecodeMatrix=i.decodeMatrix,s.uvBuf=new me(n,n.ARRAY_BUFFER,a,a.length,2,n.STATIC_DRAW),Be.uvs+=s.uvBuf.numItems}if(t.normals){const e=Pe.compressNormals(t.normals);let i=s.compressGeometry;s.normalsBuf=new me(n,n.ARRAY_BUFFER,e,e.length,3,n.STATIC_DRAW,i),Be.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new me(n,n.ELEMENT_ARRAY_BUFFER,e,e.length,1,n.STATIC_DRAW),Be.indices+=s.indicesBuf.numItems;const a=ve(i,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new me(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),Be.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),Be.meshes--}}var Ne={};function xe(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return y.apply(e,{positions:[h,p,A,o,p,A,o,c,A,h,c,A,h,p,A,h,c,A,h,c,u,h,p,u,h,p,A,h,p,u,o,p,u,o,p,A,o,p,A,o,p,u,o,c,u,o,c,A,o,c,u,h,c,u,h,c,A,o,c,A,h,c,u,o,c,u,o,p,u,h,p,u],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function Le(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let n=e.height||1;n<0&&(console.error("negative height not allowed - will invert"),n*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);let a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);const r=!!e.openEnded;let l=e.center;const o=l?l[0]:0,c=l?l[1]:0,u=l?l[2]:0,h=n/2,p=n/a,A=2*Math.PI/i,d=1/i,f=(t-s)/a,I=[],m=[],v=[],w=[];let g,T,E,b,D,P,R,C,_,B,O;const S=(90-180*Math.atan(n/(s-t))/Math.PI)/90;for(g=0;g<=a;g++)for(D=t-g*f,P=h-g*p,T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),m.push(D*E),m.push(S),m.push(D*b),v.push(T*d),v.push(1*g/a),I.push(D*E+o),I.push(P+c),I.push(D*b+u);for(g=0;g0){for(_=I.length/3,m.push(0),m.push(1),m.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,m.push(t*E),m.push(1),m.push(t*b),v.push(B),v.push(O),I.push(t*E+o),I.push(h+c),I.push(t*b+u);for(T=0;T0){for(_=I.length/3,m.push(0),m.push(-1),m.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(0-h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,m.push(s*E),m.push(-1),m.push(s*b),v.push(B),v.push(O),I.push(s*E+o),I.push(0-h+c),I.push(s*b+u);for(T=0;T65535?Uint32Array:Uint16Array)(h*p*6);for(g=0;g360&&(a=360);const r=e.center;let l=r?r[0]:0,o=r?r[1]:0;const c=r?r[2]:0,u=[],p=[],A=[],d=[];let f,I,m,v,w,g,T,E,b,D,P,R;for(E=0;E<=i;E++)for(T=0;T<=n;T++)f=T/n*a,I=.785398+E/i*Math.PI*2,l=t*Math.cos(f),o=t*Math.sin(f),m=(t+s*Math.cos(I))*Math.cos(f),v=(t+s*Math.cos(I))*Math.sin(f),w=s*Math.sin(I),u.push(m+l),u.push(v+o),u.push(w+c),A.push(1-T/n),A.push(E/i),g=h.normalizeVec3(h.subVec3([m,v,w],[l,o,c],[]),[]),p.push(g[0]),p.push(g[1]),p.push(g[2]);for(E=1;E<=i;E++)for(T=1;T<=n;T++)b=(n+1)*E+T-1,D=(n+1)*(E-1)+T-1,P=(n+1)*(E-1)+T,R=(n+1)*E+T,d.push(b),d.push(D),d.push(P),d.push(P),d.push(R),d.push(b);return y.apply(e,{positions:u,normals:p,uv:A,indices:d})}Ne.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},Ne.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(Ne.parse._buffToStr(e));window.location.href=s},Ne.clone=function(e){return JSON.parse(JSON.stringify(e))},Ne.bin={},Ne.bin.f=new Float32Array(1),Ne.bin.fb=new Uint8Array(Ne.bin.f.buffer),Ne.bin.rf=function(e,t){for(var s=Ne.bin.f,n=Ne.bin.fb,i=0;i<4;i++)n[i]=e[t+i];return s[0]},Ne.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Ne.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Ne.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},Ne.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},Ne.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},Ne.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},Ne.parse={},Ne.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",n=0;ni&&(i=o),ca&&(a=c),ur&&(r=u)}return{min:{x:t,y:s,z:n},max:{x:i,y:a,z:r}}};const Ge={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function je(e={}){var t=e.origin||[0,0,0],s=t[0],n=t[1],i=t[2],a=e.size||1,r=[],l=[],o=e.text;y.isNumeric(o)&&(o=""+o);for(var c,u,h,p,A,d,f,I,m,v=(o||"").split("\n"),w=0,g=0,T=.04,E=0;E0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice();let t;for(let s=0,n=e.length;s0,o=!!i.compressGeometry,c=[];c.push("#version 300 es"),c.push("// Lambertian drawing vertex shader"),c.push("in vec3 position;"),c.push("uniform mat4 modelMatrix;"),c.push("uniform mat4 viewMatrix;"),c.push("uniform mat4 projMatrix;"),c.push("uniform vec4 colorize;"),c.push("uniform vec3 offset;"),o&&c.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(c.push("uniform float logDepthBufFC;"),c.push("out float vFragDepth;"),c.push("bool isPerspectiveMatrix(mat4 m) {"),c.push(" return (m[2][3] == - 1.0);"),c.push("}"),c.push("out float isPerspective;"));l&&c.push("out vec4 vWorldPosition;");if(c.push("uniform vec4 lightAmbient;"),c.push("uniform vec4 materialColor;"),c.push("uniform vec3 materialEmissive;"),i.normalsBuf){c.push("in vec3 normal;"),c.push("uniform mat4 modelNormalMatrix;"),c.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),c.push(" }"),c.push(" return normalize(v);"),c.push("}"))}c.push("out vec4 vColor;"),"points"===i.primitiveName&&c.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(c.push("void billboard(inout mat4 mat) {"),c.push(" mat[0][0] = 1.0;"),c.push(" mat[0][1] = 0.0;"),c.push(" mat[0][2] = 0.0;"),"spherical"===a&&(c.push(" mat[1][0] = 0.0;"),c.push(" mat[1][1] = 1.0;"),c.push(" mat[1][2] = 0.0;")),c.push(" mat[2][0] = 0.0;"),c.push(" mat[2][1] = 0.0;"),c.push(" mat[2][2] =1.0;"),c.push("}"));c.push("void main(void) {"),c.push("vec4 localPosition = vec4(position, 1.0); "),c.push("vec4 worldPosition;"),o&&c.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(o?c.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):c.push("vec4 localNormal = vec4(normal, 0.0); "),c.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),c.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));c.push("mat4 viewMatrix2 = viewMatrix;"),c.push("mat4 modelMatrix2 = modelMatrix;"),r&&c.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(c.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),c.push("billboard(modelMatrix2);"),c.push("billboard(viewMatrix2);"),c.push("billboard(modelViewMatrix);"),i.normalsBuf&&(c.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),c.push("billboard(modelNormalMatrix2);"),c.push("billboard(viewNormalMatrix2);"),c.push("billboard(modelViewNormalMatrix);")),c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&c.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(c.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),c.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),c.push("float lambertian = 1.0;"),i.normalsBuf)for(let e=0,t=n.lights.length;e0,a=t.gammaOutput,r=[];r.push("#version 300 es"),r.push("// Lambertian drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(i){r.push("in vec4 vWorldPosition;"),r.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),r.push("}")}"points"===n.primitiveName&&(r.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),r.push("float r = dot(cxy, cxy);"),r.push("if (r > 1.0) {"),r.push(" discard;"),r.push("}"));t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?r.push("outColor = linearToGamma(vColor, gammaFactor);"):r.push("outColor = vColor;");return r.push("}"),r}(e)):(this.vertex=function(e){const t=e.scene;e._material;const s=e._state,n=t._sectionPlanesState,i=e._geometry._state,a=t._lightsState;let r;const l=s.billboard,o=s.background,c=s.stationary,u=function(e){if(!e._geometry._state.uvBuf)return!1;const t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),h=tt(e),p=n.sectionPlanes.length>0,A=et(e),d=!!i.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),d&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),p&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));a.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(h){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(let e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}u&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),d&&f.push("uniform mat3 uvDecodeMatrix;"));i.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===i.primitiveName&&f.push("uniform float pointSize;");"spherical"!==l&&"cylindrical"!==l||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===l&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(A){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(let e=0,t=a.lights.length;e0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(let e=0,t=a.lights.length;e0,o=tt(e),c=n.uvBuf,u="PhongMaterial"===r.type,h="MetallicMaterial"===r.type,p="SpecularMaterial"===r.type,A=et(e);t.gammaInput;const d=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));A&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),d&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(l){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var I=0;I0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),u&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = "+$e[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(h||p)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),a.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+$e[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),n.colors&&f.push("in vec4 vColor;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._occlusionMap||s._alphaMap)&&f.push("in vec2 vUV;");o&&(a.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));r.ambient&&f.push("uniform vec3 materialAmbient;");r.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==r.alpha&&null!==r.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");r.emissive&&f.push("uniform vec3 materialEmissive;");r.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==r.glossiness&&null!==r.glossiness&&f.push("uniform float materialGlossiness;");void 0!==r.shininess&&null!==r.shininess&&f.push("uniform float materialShininess;");r.specular&&f.push("uniform vec3 materialSpecular;");void 0!==r.metallic&&null!==r.metallic&&f.push("uniform float materialMetallic;");void 0!==r.roughness&&null!==r.roughness&&f.push("uniform float materialRoughness;");void 0!==r.specularF0&&null!==r.specularF0&&f.push("uniform float materialSpecularF0;");c&&s._ambientMap&&(f.push("uniform sampler2D ambientMap;"),s._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));c&&s._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),s._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));c&&s._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),s._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));c&&s._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),s._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));o&&c&&s._metallicMap&&(f.push("uniform sampler2D metallicMap;"),s._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));o&&c&&s._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),s._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));o&&c&&s._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),s._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));o&&s._normalMap&&(f.push("uniform sampler2D normalMap;"),s._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));c&&s._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),s._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));c&&s._alphaMap&&(f.push("uniform sampler2D alphaMap;"),s._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));o&&c&&s._specularMap&&(f.push("uniform sampler2D specularMap;"),s._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));o&&c&&s._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),s._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));o&&c&&s._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),s._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));o&&(s._diffuseFresnel||s._specularFresnel||s._alphaFresnel||s._emissiveFresnel||s._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),s._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),s._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),s._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),s._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),s._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),o)for(let e=0,t=a.lights.length;e 0.0) { discard; }"),f.push("}")}"points"===n.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),r.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");r.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):r.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");n.colors&&f.push("diffuseColor *= vColor.rgb;");r.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");r.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==r.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");n.colors&&f.push("alpha *= vColor.a;");void 0!==r.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==r.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==r.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==r.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._occlusionMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));c&&s._ambientMap&&(s._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+$e[s._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));c&&s._diffuseMap&&(s._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+$e[s._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));c&&s._baseColorMap&&(s._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+$e[s._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));c&&s._emissiveMap&&(s._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+$e[s._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));c&&s._alphaMap&&(s._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));c&&s._occlusionMap&&(s._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(o&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){c&&s._normalMap?(s._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),c&&s._specularMap&&(s._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),c&&s._glossinessMap&&(s._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),c&&s._specularGlossinessMap&&(s._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),c&&s._metallicMap&&(s._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),c&&s._roughnessMap&&(s._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),c&&s._metallicRoughnessMap&&(s._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),s._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),s._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),s._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),s._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),u&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),p&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),h&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),u&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||h)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(let e=0,t=a.lights.length;e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function lt(e){console.error(e.join("\n"))}class ot{constructor(e,t){this.id=at.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new st(e,e.VERTEX_SHADER,rt(this.source.vertex)),this._fragmentShader=new st(e,e.FRAGMENT_SHADER,rt(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void lt(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void lt(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void lt(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void lt(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void lt(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;s0?ct.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?ct.FS_MAX_FLOAT_PRECISION="mediump":ct.FS_MAX_FLOAT_PRECISION="lowp":ct.FS_MAX_FLOAT_PRECISION="mediump",ct.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),ct.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),ct.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),ct.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),ct.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),ct.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),ct.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),ct.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),ct.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),ct.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){ct.SUPPORTED_EXTENSIONS[e]=!0})))}const ht=h.vec3(),pt=new e({}),At=function(e,t){this.id=pt.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ze(t),this._allocate(t)},dt={};At.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,(t.gammaInput?"gi;":";")+(t.gammaOutput?"go":""),t._lightsState.getHash(),t._sectionPlanesState.getHash(),e._geometry._state.hash,e._material._state.hash,e._state.drawHash].join(";");let n=dt[s];if(!n){if(n=new At(s,e),n.errors)return console.log(n.errors.join("\n")),null;dt[s]=n,A.memory.programs++}return n._useCount++,n},At.prototype.put=function(){0==--this._useCount&&(pt.removeItem(this.id),this._program&&this._program.destroy(),delete dt[this._hash],A.memory.programs--)},At.prototype.webglContextRestored=function(){this._program=null},At.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=ct.MAX_TEXTURE_UNITS,n=t.scene,i=t._material,a=n.canvas.gl,r=this._program,l=t._state,o=t._material._state,c=t._geometry._state,u=n.camera,h=t.origin,p=l.background;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,p&&a.depthFunc(a.LEQUAL),this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,h?e.getRTCViewMatrix(l.originHash,h):u.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,u.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(u=0,h=a.sectionPlanes.length;u0&&i.lightMaps[0].texture&&this._uLightMap&&(l.bindTexture(this._uLightMap,i.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),i.reflectionMaps.length>0&&i.reflectionMaps[0].texture&&this._uReflectionMap&&(l.bindTexture(this._uReflectionMap,i.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),this._uGammaFactor&&n.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};class ft{constructor(e){this.vertex=function(e){const t=e.scene,s=t._lightsState,n=function(e){const t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,r=e._state.billboard,l=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// EmphasisFillShaderSource vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 colorize;"),o.push("uniform vec3 offset;"),a&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");if(o.push("uniform vec4 lightAmbient;"),o.push("uniform vec4 fillColor;"),n){o.push("in vec3 normal;"),o.push("uniform mat4 modelNormalMatrix;"),o.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"))}o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),a&&o.push("localPosition = positionsDecodeMatrix * localPosition;");n&&(a?o.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):o.push("vec4 localNormal = vec4(normal, 0.0); "),o.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),o.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),l&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),n&&(o.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),o.push("billboard(modelNormalMatrix2);"),o.push("billboard(viewNormalMatrix2);"),o.push("billboard(modelViewNormalMatrix);")),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&o.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),n)for(let e=0,t=s.lights.length;e0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const It=new e({}),yt=h.vec3(),mt=function(e,t){this.id=It.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new ft(t),this._allocate(t)},vt={};mt.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=vt[t];return s||(s=new mt(t,e),vt[t]=s,A.memory.programs++),s._useCount++,s},mt.prototype.put=function(){0==--this._useCount&&(It.removeItem(this.id),this._program&&this._program.destroy(),delete vt[this._hash],A.memory.programs--)},mt.prototype.webglContextRestored=function(){this._program=null},mt.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl,r=0===s?t._xrayMaterial._state:1===s?t._highlightMaterial._state:t._selectedMaterial._state,l=t._state,o=t._geometry._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Edges drawing vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec4 edgeColor;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));s&&r.push("out vec4 vWorldPosition;");r.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.push("vColor = edgeColor;"),s&&r.push("vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=e.scene._sectionPlanesState,n=e.scene.gammaOutput,i=s.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const gt=new e({}),Tt=h.vec3(),Et=function(e,t){this.id=gt.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new wt(t),this._allocate(t)},bt={};Et.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=bt[t];return s||(s=new Et(t,e),bt[t]=s,A.memory.programs++),s._useCount++,s},Et.prototype.put=function(){0==--this._useCount&&(gt.removeItem(this.id),this._program&&this._program.destroy(),delete bt[this._hash],A.memory.programs--)},Et.prototype.webglContextRestored=function(){this._program=null},Et.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl;let r;const l=t._state,o=t._geometry,c=o._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(l.originHash,u):i.viewMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh picking vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("out vec4 vViewPosition;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"));r.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(e)}}const Pt=h.vec3(),Rt=function(e,t){this._hash=e,this._shaderSource=new Dt(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Ct={};Rt.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let s=Ct[t];if(!s){if(s=new Rt(t,e),s.errors)return console.log(s.errors.join("\n")),null;Ct[t]=s,A.memory.programs++}return s._useCount++,s},Rt.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Ct[this._hash],A.memory.programs--)},Rt.prototype.webglContextRestored=function(){this._program=null},Rt.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t>24&255,u=o>>16&255,h=o>>8&255,p=255&o;n.uniform4f(this._uPickColor,p/255,h/255,u/255,c/255),r.indicesBuf?(n.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&n.drawArrays(n.TRIANGLES,0,r.positions.numItems)},Rt.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new ot(s,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0,n=!!e._geometry._state.compressGeometry;e._state.billboard,e._state.stationary;const i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),s&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("out vec4 vColor;"),n&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),n&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),s&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = clipPos;"),i.push("}"),i}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(e)}}const Bt=h.vec3(),Ot=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new _t(t),this._allocate(t)},St={};Ot.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=St[t];if(!s){if(s=new Ot(t,e),s.errors)return console.log(s.errors.join("\n")),null;St[t]=s,A.memory.programs++}return s._useCount++,s},Ot.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete St[this._hash],A.memory.programs--)},Ot.prototype.webglContextRestored=function(){this._program=null},Ot.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry,l=t._geometry._state,o=t.origin,c=a.backfaces,u=a.frontface,h=s.camera.project,p=r._getPickTrianglePositions(),A=r._getPickTriangleColors();if(this._program.bind(),e.useProgram++,s.logarithmicDepthBufferEnabled){const e=2/(Math.log(h.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,e)}if(n.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(e)}}const xt=h.vec3(),Lt=function(e,t){this._hash=e,this._shaderSource=new Nt(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Mt={};Lt.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";");let s=Mt[t];if(!s){if(s=new Lt(t,e),s.errors)return console.log(s.errors.join("\n")),null;Mt[t]=s,A.memory.programs++}return s._useCount++,s},Lt.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Mt[this._hash],A.memory.programs--)},Lt.prototype.webglContextRestored=function(){this._program=null},Lt.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._material._state,a=t._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){const t=i.backfaces;e.backfaces!==t&&(t?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=t);const s=i.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),this._lastMaterialId=i.id}const o=s.camera;if(n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCViewMatrix(a.originHash,l):o.viewMatrix),a.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,s=!!e._geometry._state.compressGeometry,n=[];n.push("// Mesh shadow vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),n.push("uniform vec3 offset;"),s&&n.push("uniform mat4 positionsDecodeMatrix;");t&&n.push("out vec4 vWorldPosition;");n.push("void main(void) {"),n.push("vec4 localPosition = vec4(position, 1.0); "),n.push("vec4 worldPosition;"),s&&n.push("localPosition = positionsDecodeMatrix * localPosition;");n.push("worldPosition = modelMatrix * localPosition;"),n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&n.push("vWorldPosition = worldPosition;");return n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n}(e),this.fragment=function(e){const t=e.scene;t.canvas.gl;const s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(e)}}const Ht=function(e,t){this._hash=e,this._shaderSource=new Ft(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Ut={};Ht.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let n=Ut[s];if(!n){if(n=new Ht(s,e),n.errors)return console.log(n.errors.join("\n")),null;Ut[s]=n,A.memory.programs++}return n._useCount++,n},Ht.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Ut[this._hash],A.memory.programs--)},Ht.prototype.webglContextRestored=function(){this._program=null},Ht.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene.canvas.gl,n=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.id!==this._lastMaterialId){const t=n.backfaces;e.backfaces!==t&&(t?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=t);const i=n.frontface;e.frontface!==i&&(i?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=i),e.lineWidth!==n.lineWidth&&(s.lineWidth(n.lineWidth),e.lineWidth=n.lineWidth),this._uPointSize&&s.uniform1i(this._uPointSize,n.pointSize),this._lastMaterialId=n.id}if(s.uniformMatrix4fv(this._uModelMatrix,s.FALSE,t.worldMatrix),i.combineGeometry){const n=t.vertexBufs;n.id!==this._lastVertexBufsId&&(n.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(n.positionsBuf,n.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),this._lastVertexBufsId=n.id)}this._uClippable&&s.uniform1i(this._uClippable,t._state.clippable),s.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(s.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(s.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(s.drawArrays(s.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},Ht.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new ot(s,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uShadowViewMatrix=n.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=n.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0){let e,t,i,a,r;for(let l=0,o=this._uSectionPlanes.length;l0)for(let s=0;s0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const Zt=function(){const e=h.vec3(),t=h.vec3(),s=h.vec3(),n=h.vec3(),i=h.vec3(),a=h.vec3(),r=h.vec4(),l=h.vec3(),o=h.vec3(),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3(),y=h.vec4(),m=h.vec4(),v=h.vec4(),w=h.vec3(),g=h.vec3(),T=h.vec3(),E=h.vec3(),b=h.vec3(),D=h.vec3(),P=h.vec3(),R=h.vec3(),C=h.vec3(),_=h.vec3(),O=h.vec3();return function(S,N,x,L){var M=L.primIndex;if(null!=M&&M>-1){const G=S.geometry._state,j=S.scene,V=j.camera,k=j.canvas;if("triangles"===G.primitiveName){L.primitive="triangle";const j=M,Q=G.indices,W=G.positions;let z,K,Y;if(Q){var F=Q[j+0],H=Q[j+1],U=Q[j+2];a[0]=F,a[1]=H,a[2]=U,L.indices=a,z=3*F,K=3*H,Y=3*U}else z=3*j,K=z+3,Y=K+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],n[0]=W[K+0],n[1]=W[K+1],n[2]=W[K+2],i[0]=W[Y+0],i[1]=W[Y+1],i[2]=W[Y+2],G.compressGeometry){const e=G.positionsDecodeMatrix;e&&(Pe.decompressPosition(s,e,s),Pe.decompressPosition(n,e,n),Pe.decompressPosition(i,e,i))}L.canvasPos?h.canvasPosToLocalRay(k.canvas,S.origin?B(N,S.origin):N,x,S.worldMatrix,L.canvasPos,e,t):L.origin&&L.direction&&h.worldRayToLocalRay(S.worldMatrix,L.origin,L.direction,e,t),h.normalizeVec3(t),h.rayPlaneIntersect(e,t,s,n,i,r),L.localPos=r,L.position=r,y[0]=r[0],y[1]=r[1],y[2]=r[2],y[3]=1,h.transformVec4(S.worldMatrix,y,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],L.canvasPos&&S.origin&&(l[0]+=S.origin[0],l[1]+=S.origin[1],l[2]+=S.origin[2]),L.worldPos=l,h.transformVec4(V.matrix,m,v),o[0]=v[0],o[1]=v[1],o[2]=v[2],L.viewPos=o,h.cartesianToBarycentric(r,s,n,i,c),L.bary=c;const X=G.normals;if(X){if(G.compressGeometry){const e=3*F,t=3*H,s=3*U;Pe.decompressNormal(X.subarray(e,e+2),u),Pe.decompressNormal(X.subarray(t,t+2),p),Pe.decompressNormal(X.subarray(s,s+2),A)}else u[0]=X[z],u[1]=X[z+1],u[2]=X[z+2],p[0]=X[K],p[1]=X[K+1],p[2]=X[K+2],A[0]=X[Y],A[1]=X[Y+1],A[2]=X[Y+2];const e=h.addVec3(h.addVec3(h.mulVec3Scalar(u,c[0],w),h.mulVec3Scalar(p,c[1],g),T),h.mulVec3Scalar(A,c[2],E),b);L.worldNormal=h.normalizeVec3(h.transformVec3(S.worldNormalMatrix,e,D))}const q=G.uv;if(q){if(d[0]=q[2*F],d[1]=q[2*F+1],f[0]=q[2*H],f[1]=q[2*H+1],I[0]=q[2*U],I[1]=q[2*U+1],G.compressGeometry){const e=G.uvDecodeMatrix;e&&(Pe.decompressUV(d,e,d),Pe.decompressUV(f,e,f),Pe.decompressUV(I,e,I))}L.uv=h.addVec3(h.addVec3(h.mulVec2Scalar(d,c[0],P),h.mulVec2Scalar(f,c[1],R),C),h.mulVec2Scalar(I,c[2],_),O)}}}}}();class $t extends C{get type(){return"Material"}constructor(e,t={}){super(e,t),A.memory.materials++}destroy(){super.destroy(),A.memory.materials--}}const es={opaque:0,mask:1,blend:2},ts=["opaque","mask","blend"];class ss extends $t{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new ye({type:"PhongMaterial",ambient:h.vec3([1,1,1]),diffuse:h.vec3([1,1,1]),specular:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=es[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return ts[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}function ns(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];let s;switch(t){case"WEBGL_depth_texture":s=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":s=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":s=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=e.getExtension(t)}return e._cachedExtensions[t]=s,s}function is(e,t,s=null){let n;const i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===s){const t=ns(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===i)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(n=ns(e,"WEBGL_compressed_texture_s3tc"),null===n)return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){const t=ns(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===i)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){const t=ns(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){const t=ns(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===i)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){const t=ns(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){const t=ns(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===i)return 3001===s?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}const as=new Uint8Array([0,0,0,1]);class rs{constructor({gl:e,target:t,format:s,type:n,wrapS:i,wrapT:a,wrapR:r,encoding:l,preloadColor:o,premultiplyAlpha:c,flipY:u}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=s||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!u,this.unpackAlignment=4,this.wrapS=i||1e3,this.wrapT=a||1e3,this.wrapR=r||1e3,this.encoding=l||3001,this.texture=e.createTexture(),o&&this.setPreloadColor(o),this.allocated=!0}setPreloadColor(e){e?(as[0]=Math.floor(255*e[0]),as[1]=Math.floor(255*e[1]),as[2]=Math.floor(255*e[2]),as[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(as[0]=0,as[1]=0,as[2]=0,as[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let s=0,n=e.length;s1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=is(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=is(s,this.wrapT);if(r&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,r),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=is(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}i?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,os(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,os(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,is(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,is(s,this.magFilter)));const l=is(s,this.format,this.encoding),o=is(s,this.type),c=ls(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t>t;return e+1}class ps extends C{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new ye({texture:new rs({gl:this.scene.canvas.gl}),matrix:h.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=h.vec2([0,0]),this._scale=h.vec2([1,1]),this._rotate=h.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),A.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this._state.texture=new rs({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}_update(){const e=this._state;if(this._matrixDirty){let t,s;0===this._translate[0]&&0===this._translate[1]||(t=h.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=h.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?h.mulMat4(t,s):s),0!==this._rotate&&(s=h.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?h.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=cs(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let s=new Image;s.onload=function(){s=cs(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),A.memory.textures--}}const As=h.vec3(),ds=h.vec3();h.vec3();const fs=h.vec3([0,-1,0]),Is=h.vec4([0,0,0,1]);class ys extends $t{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new ye({type:"LambertMaterial",ambient:h.vec3([1,1,1]),color:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),this.ambient=t.ambient,this.color=t.color,this.emissive=t.emissive,this.alpha=t.alpha,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this.backfaces=t.backfaces,this.frontface=t.frontface}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set color(e){let t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get color(){return this._state.color}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}get alpha(){return this._state.alpha}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}const ms={opaque:0,mask:1,blend:2},vs=["opaque","mask","blend"];class ws extends $t{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new ye({type:"MetallicMaterial",baseColor:h.vec4([1,1,1]),emissive:h.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.baseColor=t.baseColor,this.metallic=t.metallic,this.roughness=t.roughness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.baseColorMap&&(this._baseColorMap=this._checkComponent("Texture",t.baseColorMap)),t.metallicMap&&(this._metallicMap=this._checkComponent("Texture",t.metallicMap)),t.roughnessMap&&(this._roughnessMap=this._checkComponent("Texture",t.roughnessMap)),t.metallicRoughnessMap&&(this._metallicRoughnessMap=this._checkComponent("Texture",t.metallicRoughnessMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set baseColor(e){let t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get baseColor(){return this._state.baseColor}get baseColorMap(){return this._baseColorMap}set metallic(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}get metallic(){return this._state.metallic}get metallicMap(){return this._attached.metallicMap}set roughness(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}get roughness(){return this._state.roughness}get roughnessMap(){return this._attached.roughnessMap}get metallicRoughnessMap(){return this._attached.metallicRoughnessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._attached.emissiveMap}get occlusionMap(){return this._attached.occlusionMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._attached.alphaMap}get normalMap(){return this._attached.normalMap}set alphaMode(e){let t=ms[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return vs[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const gs={opaque:0,mask:1,blend:2},Ts=["opaque","mask","blend"];class Es extends $t{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new ye({type:"SpecularMaterial",diffuse:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),specular:h.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.diffuse=t.diffuse,this.specular=t.specular,this.glossiness=t.glossiness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.glossinessMap&&(this._glossinessMap=this._checkComponent("Texture",t.glossinessMap)),t.specularGlossinessMap&&(this._specularGlossinessMap=this._checkComponent("Texture",t.specularGlossinessMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}get diffuseMap(){return this._diffuseMap}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}get specularMap(){return this._specularMap}get specularGlossinessMap(){return this._specularGlossinessMap}set glossiness(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}get glossiness(){return this._state.glossiness}get glossinessMap(){return this._glossinessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._emissiveMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._alphaMap}get normalMap(){return this._normalMap}get occlusionMap(){return this._occlusionMap}set alphaMode(e){let t=gs[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Ts[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const bs={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class Ds extends $t{get type(){return"EmphasisMaterial"}get presets(){return bs}constructor(e,t={}){super(e,t),this._state=new ye({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(e=e||"default",this._preset===e)return;const t=bs[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(bs).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Ps={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class Rs extends $t{get type(){return"EdgeMaterial"}get presets(){return Ps}constructor(e,t={}){super(e,t),this._state=new ye({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Ps[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ps).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class Cs extends C{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=h.vec3(t.pos||[0,0,0]),this._up=h.vec3(t.up||[0,1,0]),this._normal=h.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=h.vec3(),this._rtcPos=h.vec3(),this._imageSize=h.vec2(),this._texture=new ps(this),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new Je(this,{matrix:h.inverseMat4(h.lookAtMat4v(this._pos,h.subVec3(this._pos,this._normal,h.mat4()),this._up,h.mat4())),children:[this._bitmapMesh=new Jt(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new _e(this,Fe({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new ss(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}class _s extends C{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],this._origin=h.vec3(t.origin||[0,0,0]),t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=n.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new ye({type:"dir",dir:h.vec3([1,1,1]),color:h.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=h.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,n=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],i=[0,1,0];h.lookAtMat4v(n,s,i,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=h.identityMat4()),h.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new Ss(this.scene.canvas.canvas,this.scene.canvas.gl,{size:[1024,1024]})),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function xs(e){if(!Ls(e.width)||!Ls(e.height)){const t=document.createElement("canvas");t.width=Ms(e.width),t.height=Ms(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Ls(e){return 0==(e&e-1)}function Ms(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Fs extends C{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new ye({texture:new rs({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),A.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let a=0;a=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class Vs{constructor(){this.planes=[new js,new js,new js,new js,new js,new js]}}function ks(e,t,s){const n=h.mulMat4(s,t,Gs),i=n[0],a=n[1],r=n[2],l=n[3],o=n[4],c=n[5],u=n[6],p=n[7],A=n[8],d=n[9],f=n[10],I=n[11],y=n[12],m=n[13],v=n[14],w=n[15];e.planes[0].set(l-i,p-o,I-A,w-y),e.planes[1].set(l+i,p+o,I+A,w+y),e.planes[2].set(l-a,p-c,I-d,w-m),e.planes[3].set(l+a,p+c,I+d,w+m),e.planes[4].set(l-r,p-u,I-f,w-v),e.planes[5].set(l+r,p+u,I+f,w+v)}function Qs(e,t){let s=Vs.INSIDE;const n=Hs,i=Us;n[0]=t[0],n[1]=t[1],n[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];const a=[n,i];for(let t=0;t<6;++t){const n=e.planes[t];if(n.normal[0]*a[n.testVertex[0]][0]+n.normal[1]*a[n.testVertex[1]][1]+n.normal[2]*a[n.testVertex[2]][2]+n.offset<0)return Vs.OUTSIDE;n.normal[0]*a[1-n.testVertex[0]][0]+n.normal[1]*a[1-n.testVertex[1]][1]+n.normal[2]*a[1-n.testVertex[2]][2]+n.offset<0&&(s=Vs.INTERSECT)}return s}Vs.INSIDE=0,Vs.INTERSECT=1,Vs.OUTSIDE=2;class Ws{constructor(e){this._eye=h.vec3(),this._look=h.vec3(),this._up=h.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,s=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,n=this._projection;function i(){switch(n.type){case"perspective":s.perspective.fov=n.fov,s.perspective.fovAxis=n.fovAxis,s.perspective.near=n.near,s.perspective.far=n.far;break;case"ortho":s.ortho.scale=n.scale,s.ortho.near=n.near,s.ortho.far=n.far;break;case"frustum":s.frustum.left=n.left,s.frustum.right=n.right,s.frustum.top=n.top,s.frustum.bottom=n.bottom,s.frustum.near=n.near,s.frustum.far=n.far;break;case"custom":s.customProjection.matrix=n.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:n.scale,projection:n.projection},(()=>{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const zs=h.vec3();const Ks=h.vec3();class Ys{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?y.apply(t,{}):null;const s=e.objects,n=!t||t.visible,i=!t||t.edges,a=!t||t.xrayed,r=!t||t.highlighted,l=!t||t.selected,o=!t||t.clippable,c=!t||t.pickable,u=!t||t.colorize,h=!t||t.opacity;for(let e in s)if(s.hasOwnProperty(e)){const t=s[e],p=this.numObjects;if(n&&(this.objectsVisible[p]=t.visible),i&&(this.objectsEdges[p]=t.edges),a&&(this.objectsXrayed[p]=t.xrayed),r&&(this.objectsHighlighted[p]=t.highlighted),l&&(this.objectsSelected[p]=t.selected),o&&(this.objectsClippable[p]=t.clippable),c&&(this.objectsPickable[p]=t.pickable),u){const e=t.colorize;e?(this.objectsColorize[3*p+0]=e[0],this.objectsColorize[3*p+1]=e[1],this.objectsColorize[3*p+2]=e[2],this.objectsHasColorize[p]=!0):this.objectsHasColorize[p]=!1}h&&(this.objectsOpacity[p]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,s=!t||t.visible,n=!t||t.edges,i=!t||t.xrayed,a=!t||t.highlighted,r=!t||t.selected,l=!t||t.clippable,o=!t||t.pickable,c=!t||t.colorize,u=!t||t.opacity;var h=0;const p=e.objects;for(let e in p)if(p.hasOwnProperty(e)){const t=p[e];s&&(t.visible=this.objectsVisible[h]),n&&(t.edges=this.objectsEdges[h]),i&&(t.xrayed=this.objectsXrayed[h]),a&&(t.highlighted=this.objectsHighlighted[h]),r&&(t.selected=this.objectsSelected[h]),l&&(t.clippable=this.objectsClippable[h]),o&&(t.pickable=this.objectsPickable[h]),c&&(this.objectsHasColorize[h]?(Ks[0]=this.objectsColorize[3*h+0],Ks[1]=this.objectsColorize[3*h+1],Ks[2]=this.objectsColorize[3*h+2],t.colorize=Ks):t.colorize=null),u&&(t.opacity=this.objectsOpacity[h]),h++}}}class Xs{constructor(e,t,s,n,i=null,a=0){this.model=e,this.object=null,this.parent=null,this.id=t,this._aabb=null,this.layer=i,this.portionId=a,this._color=[s[0],s[1],s[2],n],this._colorize=[s[0],s[1],s[2],n],this._colorizing=!1,this._transparent=n<255,this.numTriangles=0,this.origin=null}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const s=e<255,n=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),n&&this.layer.setTransparent(this.portionId,t,s)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,s,n){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,s,n)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex(this.portionId,e)}set aabb(e){this._aabb=e}get aabb(){return this._aabb}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const qs=new class{constructor(){this._uint8Arrays={},this._float32Arrays={}}_clear(){this._uint8Arrays={},this._float32Arrays={}}getUInt8Array(e){let t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}getFloat32Array(e){let t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}};let Js=0;const Zs={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},$s=new Float32Array([1,1,1,1]),en=new Float32Array([0,0,0,1]),tn=h.vec4(),sn=h.vec3();h.vec3();const nn=h.vec3(),an=h.mat4();class rn{constructor(e,t=!1,{instancing:s=!1,edges:n=!1}={}){this._scene=e,this._withSAO=t,this._instancing=s,this._edges=n,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}_getHash(){return this._scene._sectionPlanesState.getHash()}_buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}_buildVertexShader(){return[""]}_buildFragmentShader(){return[""]}_addMatricesUniformBlockLines(e,t=!1){return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}getValid(){return this._hash===this._getHash()}setSectionPlanesStateUniforms(e){const t=this._scene,{gl:s}=t.canvas,{model:n,layerIndex:i}=e,a=t._sectionPlanesState.sectionPlanes.length;if(a>0){const r=t._sectionPlanesState.sectionPlanes,l=i*a,o=n.renderFlags;for(let t=0;t0&&(this._uReflectionMap="reflectionMap"),s.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(let t=0,s=e._sectionPlanesState.sectionPlanes.length;t0&&d.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,d.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),d.lightMaps.length>0&&d.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,d.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),this._withSAO){const t=r.sao;if(t.possible){const s=l.drawingBufferWidth,n=l.drawingBufferHeight;tn[0]=s,tn[1]=n,tn[2]=t.blendCutoff,tn[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,tn),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++}}if(n){const e=this._edges?"edgeColor":"fillColor",t=this._edges?"edgeAlpha":"fillAlpha";if(s===Zs[(this._edges?"EDGES":"SILHOUETTE")+"_XRAYED"]){const s=r.xrayMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===Zs[(this._edges?"EDGES":"SILHOUETTE")+"_HIGHLIGHTED"]){const s=r.highlightMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===Zs[(this._edges?"EDGES":"SILHOUETTE")+"_SELECTED"]){const s=r.selectedMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else l.uniform4fv(this._uColor,this._edges?en:$s)}this._draw({state:o,frameCtx:e,incrementDrawState:i}),l.bindVertexArray(null)}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null,A.memory.programs--}}class ln extends rn{constructor(e,t,{instancing:s=!1,edges:n=!1}={}){super(e,t,{instancing:s,edges:n})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;if(this._edges)t.drawElements(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0);else{const e=n.pickElementsCount||s.indicesBuf.numItems,a=n.pickElementsOffset?n.pickElementsOffset*s.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,e,s.indicesBuf.itemType,a),i&&n.drawElements++}}}class on extends ln{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class cn extends rn{constructor(e,t,{edges:s=!1}={}){super(e,t,{instancing:!0,edges:s})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;this._edges?t.drawElementsInstanced(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances):(t.drawElementsInstanced(t.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++)}}class un extends cn{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class hn extends rn{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArrays(t.POINTS,0,s.positionsBuf.numItems),i&&n.drawArrays++}}class pn extends rn{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArraysInstanced(t.POINTS,0,s.positionsBuf.numItems,s.numInstances),i&&n.drawArrays++}}class An extends rn{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElements(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0),i&&n.drawElements++}}class dn extends rn{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElementsInstanced(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++}}class fn extends ln{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i;const a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class In extends ln{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching flat-shading draw vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._lightsState,s=e._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),n){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,s=t.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}class mn extends on{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class vn extends on{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class wn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class gn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Tn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec3 worldNormal = octDecode(normal.xy); "),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}}class En extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching occlusion fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}class bn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching depth fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}class Dn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Pn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry shadow vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push(" int colorFlag = int(flags) & 0xF;"),s.push(" bool visible = (colorFlag > 0);"),s.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push(" if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry shadow fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = encodeFloat( gl_FragCoord.z); "),s.push("}"),s}}class Rn extends ln{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Triangles batching quality draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),r.push("uniform sampler2D uAOMap;"),r.push("in vec4 vViewPosition;"),r.push("in vec3 vViewNormal;"),r.push("in vec4 vColor;"),r.push("in vec2 vUV;"),r.push("in vec2 vMetallicRoughness;"),n.lightMaps.length>0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick flat normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out float vFlags;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags = flags;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick flat normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}}class _n extends ln{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching color texture vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._lightsState,n=e._sectionPlanesState,i=n.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(let e=0,t=n.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(let e=0,t=n.sectionPlanes.length;e 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,t=s.lights.length;e5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]}}const Nn=h.mat4(),xn=h.mat4();function Ln(e,t,s){const n=e.length,i=new Uint16Array(n),a=t[0],r=t[1],l=t[2],o=t[3]-a,c=t[4]-r,u=t[5]-l,p=65525,A=p/o,d=p/c,f=p/u,I=e=>e>=0?e:0;for(let t=0;t=0?1:-1),t=(1-Math.abs(n))*(i>=0?1:-1),n=e,i=t}return new Int8Array([Math[t](127.5*n+(n<0?-1:0)),Math[s](127.5*i+(i<0?-1:0))])}function Hn(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}const Un=h.vec3(),Gn=h.vec3(),jn=h.vec3(),Vn=h.vec3(),kn=h.mat4();class Qn extends rn{drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:p}=n,A=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Un;let I,y;if(f[0]=h.safeInv(A[3]-A[0])*h.MAX_INT,f[1]=h.safeInv(A[4]-A[1])*h.MAX_INT,f[2]=h.safeInv(A[5]-A[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(f[0]),e.snapPickCoordinateScale[1]=h.safeInv(f[1]),e.snapPickCoordinateScale[2]=h.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=Gn;if(o){const e=jn;h.transformPoint3(u,o,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=B(d,t,kn),y=Vn,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(p,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),l.indicesBuf.bind(),r.drawElements(r.TRIANGLES,l.indicesBuf.numItems,l.indicesBuf.itemType,0),l.indicesBuf.unbind()}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Wn=h.vec3(),zn=h.vec3(),Kn=h.vec3(),Yn=h.vec3(),Xn=h.mat4();class qn extends rn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:p}=n,A=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Wn;let I,y;if(f[0]=h.safeInv(A[3]-A[0])*h.MAX_INT,f[1]=h.safeInv(A[4]-A[1])*h.MAX_INT,f[2]=h.safeInv(A[5]-A[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(f[0]),e.snapPickCoordinateScale[1]=h.safeInv(f[1]),e.snapPickCoordinateScale[2]=h.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=zn;if(o){const e=Kn;h.transformPoint3(u,o,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=B(d,t,Xn),y=Yn,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(p,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(l.edgeIndicesBuf.bind(),r.drawElements(r.LINES,l.edgeIndicesBuf.numItems,l.edgeIndicesBuf.itemType,0),l.edgeIndicesBuf.unbind()):r.drawArrays(r.POINTS,0,l.positionsBuf.numItems)}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0;e.pointsMaterial._state;const s=[];return s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class Jn{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Qn(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new qn(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Zn={};const $n=h.mat4(),ei=h.mat4(),ti=h.vec4([0,0,0,1]),si=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]),h.OBB3();const ni=h.vec3(),ii=h.vec3(),ai=h.vec3(),ri=h.vec3(),li=h.vec3(),oi=h.vec3(),ci=h.vec3();class ui{constructor(e){console.info("Creating TrianglesBatchingLayer"),this.model=e.model,this.sortId="TrianglesBatchingLayer"+(e.solid?"-solid":"-surface")+(e.autoNormals?"-autonormals":"-normals")+(e.textureSet&&e.textureSet.colorTexture?"-colorTexture":"")+(e.textureSet&&e.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=On[t];return s||(s=new Bn(e),On[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete On[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=Zn[t];return s||(s=new Jn(e),Zn[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Zn[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Sn(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ye({origin:h.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:e.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=h.mat4(e.positionsDecodeMatrix)),e.uvDecodeMatrix?(this._state.uvDecodeMatrix=h.mat3(e.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,e.origin&&this._state.origin.set(e.origin),this.aabb=h.collapseAABB3(),this.solid=!!e.solid}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(let e=0,t=i.length;e0){const e=$n;I?h.inverseMat4(h.transposeMat4(I,ei),e):h.identityMat4(e,e),function(e,t,s,n,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let r,l,o,c,u,p,A=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(p=0;pu&&(o=r,u=c),r=Fn(d,"floor","ceil"),l=Hn(r),c=a(d,l),c>u&&(o=r,u=c),r=Fn(d,"ceil","ceil"),l=Hn(r),c=a(d,l),c>u&&(o=r,u=c),n[i+p+0]=o[0],n[i+p+1]=o[1],n[i+p+2]=0}(e,n,n.length,w.normals,w.normals.length)}if(l)for(let e=0,t=l.length;e0)for(let e=0,t=a.length;e0)for(let e=0,t=r.length;e0){const n=this._state.positionsDecodeMatrix?new Uint16Array(s.positions):Ln(s.positions,this._modelAABB,this._state.positionsDecodeMatrix=h.mat4());if(e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(let e=0,t=this._portions.length;e0){const n=new Int8Array(s.normals);let i=!0;e.normalsBuf=new me(t,t.ARRAY_BUFFER,n,s.normals.length,3,t.STATIC_DRAW,i)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new me(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.uv.length>0)if(e.uvDecodeMatrix){let n=!1;e.uvBuf=new me(t,t.ARRAY_BUFFER,s.uv,s.uv.length,2,t.STATIC_DRAW,n)}else{const n=Pe.getUVBounds(s.uv),i=Pe.compressUVs(s.uv,n.min,n.max),a=i.quantized;let r=!1;e.uvDecodeMatrix=h.mat3(i.decodeMatrix),e.uvBuf=new me(t,t.ARRAY_BUFFER,a,a.length,2,t.STATIC_DRAW,r)}if(s.metallicRoughness.length>0){const n=new Uint8Array(s.metallicRoughness);let i=!1;e.metallicRoughnessBuf=new me(t,t.ARRAY_BUFFER,n,s.metallicRoughness.length,2,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n),a=!1;e.flagsBuf=new me(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new me(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new me(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}if(s.edgeIndices.length>0){const n=new Uint32Array(s.edgeIndices);e.edgeIndicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,n,s.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}isEmpty(){return!this._state.indicesBuf}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=e,n=this._portions[s],i=4*n.vertsBaseIndex,a=4*n.numVerts,r=this._scratchMemory.getUInt8Array(a),l=t[0],o=t[1],c=t[2],u=t[3];for(let e=0;em)&&(m=e,n.set(v),i&&h.triangleNormal(d,f,I,i),y=!0)}}return y&&i&&(h.transformVec3(this.model.worldNormalMatrix,i,i),h.normalizeVec3(i)),y}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}class hi extends cn{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i,a,r;const l=[];for(l.push("#version 300 es"),l.push("// Instancing geometry drawing vertex shader"),l.push("uniform int renderPass;"),l.push("in vec3 position;"),l.push("in vec2 normal;"),l.push("in vec4 color;"),l.push("in float flags;"),e.entityOffsetsEnabled&&l.push("in vec3 offset;"),l.push("in vec4 modelMatrixCol0;"),l.push("in vec4 modelMatrixCol1;"),l.push("in vec4 modelMatrixCol2;"),l.push("in vec4 modelNormalMatrixCol0;"),l.push("in vec4 modelNormalMatrixCol1;"),l.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(l,!0),e.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;")),l.push("uniform vec4 lightAmbient;"),i=0,a=s.lights.length;i= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"),n&&(l.push("out vec4 vWorldPosition;"),l.push("out float vFlags;")),l.push("out vec4 vColor;"),l.push("void main(void) {"),l.push("int colorFlag = int(flags) & 0xF;"),l.push("if (colorFlag != renderPass) {"),l.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),l.push("} else {"),l.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),l.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix * worldPosition; "),l.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),l.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),l.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),i=0,a=s.lights.length;i0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class pi extends cn{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState;let n,i;const a=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry flat-shading drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),a){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}for(r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),n=0,i=s.lights.length;n0,s=[];return s.push("#version 300 es"),s.push("// Instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing fill fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class di extends un{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class fi extends un{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Ii extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class yi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class mi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec2 normal;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("in vec4 modelNormalMatrixCol0;"),s.push("in vec4 modelNormalMatrixCol1;"),s.push("in vec4 modelNormalMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}}class vi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// TrianglesInstancingOcclusionRenderer vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesInstancingOcclusionRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}class wi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}class gi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Ti extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}const Ei={3e3:"linearToLinear",3001:"sRGBToLinear"};class bi extends cn{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Instancing geometry quality drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),r.push("#define PI 3.14159265359"),r.push("#define RECIPROCAL_PI 0.31830988618"),r.push("#define RECIPROCAL_PI2 0.15915494"),r.push("#define EPSILON 1e-6"),r.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),r.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),r.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),r.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),r.push(" return normalize(surf_norm );"),r.push(" }"),r.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),r.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),r.push(" vec2 st0 = dFdx( uv.st );"),r.push(" vec2 st1 = dFdy( uv.st );"),r.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),r.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),r.push(" vec3 N = normalize( surf_norm );"),r.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),r.push(" mat3 tsn = mat3( S, T, N );"),r.push(" return normalize( tsn * mapN );"),r.push("}"),r.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),r.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),r.push("}"),r.push("struct IncidentLight {"),r.push(" vec3 color;"),r.push(" vec3 direction;"),r.push("};"),r.push("struct ReflectedLight {"),r.push(" vec3 diffuse;"),r.push(" vec3 specular;"),r.push("};"),r.push("struct Geometry {"),r.push(" vec3 position;"),r.push(" vec3 viewNormal;"),r.push(" vec3 worldNormal;"),r.push(" vec3 viewEyeDir;"),r.push("};"),r.push("struct Material {"),r.push(" vec3 diffuseColor;"),r.push(" float specularRoughness;"),r.push(" vec3 specularColor;"),r.push(" float shine;"),r.push("};"),r.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),r.push(" float r = ggxRoughness + 0.0001;"),r.push(" return (2.0 / (r * r) - 2.0);"),r.push("}"),r.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),r.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),r.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),r.push("}"),n.reflectionMaps.length>0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = "+Ei[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = "+Ei[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&s.push("out float vFlags;"),s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&s.push("vFlags = flags;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}}class Pi extends cn{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState;let i,a;const r=s.sectionPlanes.length>0,l=[];if(l.push("#version 300 es"),l.push("// Instancing geometry drawing fragment shader"),l.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),l.push("precision highp float;"),l.push("precision highp int;"),l.push("#else"),l.push("precision mediump float;"),l.push("precision mediump int;"),l.push("#endif"),e.logarithmicDepthBufferEnabled&&(l.push("in float isPerspective;"),l.push("uniform float logDepthBufFC;"),l.push("in float vFragDepth;")),l.push("uniform sampler2D uColorMap;"),this._withSAO&&(l.push("uniform sampler2D uOcclusionTexture;"),l.push("uniform vec4 uSAOParams;"),l.push("const float packUpscale = 256. / 255.;"),l.push("const float unpackDownScale = 255. / 256.;"),l.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),l.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),l.push("float unpackRGBToFloat( const in vec4 v ) {"),l.push(" return dot( v, unPackFactors );"),l.push("}")),l.push("uniform float gammaFactor;"),l.push("vec4 linearToLinear( in vec4 value ) {"),l.push(" return value;"),l.push("}"),l.push("vec4 sRGBToLinear( in vec4 value ) {"),l.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),l.push("}"),l.push("vec4 gammaToLinear( in vec4 value) {"),l.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),l.push("}"),t&&(l.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),l.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),l.push("}")),r){l.push("in vec4 vWorldPosition;"),l.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),l.push(" if (clippable) {"),l.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),l.push(" discard;"),l.push(" }"),l.push("}")}for(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),l.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),l.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),l.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),i=0,a=n.lights.length;i0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Li=h.vec3(),Mi=h.vec3(),Fi=h.vec3(),Hi=h.vec3(),Ui=h.mat4();class Gi extends rn{constructor(e){super(e,!1,{instancing:!0})}drawLayer(e,t,s){if(!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:p}=n,A=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Li;let I,y;if(f[0]=h.safeInv(A[3]-A[0])*h.MAX_INT,f[1]=h.safeInv(A[4]-A[1])*h.MAX_INT,f[2]=h.safeInv(A[5]-A[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(f[0]),e.snapPickCoordinateScale[1]=h.safeInv(f[1]),e.snapPickCoordinateScale[2]=h.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=Mi;if(o){const e=h.transformPoint3(u,o,Fi);t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=B(d,t,Ui),y=Hi,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(p,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(l.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(l.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(l.modelMatrixCol2Buf),r.vertexAttribDivisor(this._aModelMatrixCol0.location,1),r.vertexAttribDivisor(this._aModelMatrixCol1.location,1),r.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(l.flagsBuf),r.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(l.edgeIndicesBuf.bind(),r.drawElementsInstanced(r.LINES,l.edgeIndicesBuf.numItems,l.edgeIndicesBuf.itemType,0,l.numInstances),l.edgeIndicesBuf.unbind()):r.drawArraysInstanced(r.POINTS,0,l.positionsBuf.numItems,l.numInstances),r.vertexAttribDivisor(this._aModelMatrixCol0.location,0),r.vertexAttribDivisor(this._aModelMatrixCol1.location,0),r.vertexAttribDivisor(this._aModelMatrixCol2.location,0),r.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&r.vertexAttribDivisor(this._aOffset.location,0)}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class ji{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new xi(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Gi(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Vi={};const ki=new Uint8Array(4),Qi=new Float32Array(1),Wi=h.vec4([0,0,0,1]),zi=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]);const Ki=new Float32Array(3),Yi=h.vec3(),Xi=h.vec3(),qi=h.vec3(),Ji=h.vec3(),Zi=h.vec3(),$i=h.vec3(),ea=h.vec3();class ta{constructor(e){console.info("Creating TrianglesInstancingLayer"),this.model=e.model,this.sortId="TrianglesInstancingLayer"+(e.solid?"-solid":"-surface")+(e.normals?"-normals":"-autoNormals"),this.layerIndex=e.layerIndex,this._instancingRenderers=function(e){const t=e.id;let s=Ci[t];return s||(s=new Ri(e),Ci[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Ci[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=Vi[t];return s||(s=new ji(e),Vi[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Vi[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new ye({numInstances:0,obb:h.OBB3(),origin:h.vec3(),geometry:e.geometry,textureSet:e.textureSet,pbrSupported:!1,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],e.origin&&this._state.origin.set(e.origin),this._finalized=!1,this.aabb=h.collapseAABB3(),this.solid=!!e.solid,this.numIndices=e.geometry.numIndices}createPortion(e){const t=e.color,s=e.metallic,n=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,r=e.aabb,l=e.pickColor;if(this._finalized)throw"Already finalized";const o=t[0],c=t[1],u=t[2];if(this._colors.push(o),this._colors.push(c),this._colors.push(u),this._colors.push(i),this._metallicRoughness.push(null!=s?s:0),this._metallicRoughness.push(null!=n?n:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){let e=h.transposeMat4(a,h.mat4()),t=h.inverseMat4(e);this._modelNormalMatrixCol0.push(t[0]),this._modelNormalMatrixCol0.push(t[4]),this._modelNormalMatrixCol0.push(t[8]),this._modelNormalMatrixCol0.push(t[12]),this._modelNormalMatrixCol1.push(t[1]),this._modelNormalMatrixCol1.push(t[5]),this._modelNormalMatrixCol1.push(t[9]),this._modelNormalMatrixCol1.push(t[13]),this._modelNormalMatrixCol2.push(t[2]),this._modelNormalMatrixCol2.push(t[6]),this._modelNormalMatrixCol2.push(t[10]),this._modelNormalMatrixCol2.push(t[14])}this._pickColors.push(l[0]),this._pickColors.push(l[1]),this._pickColors.push(l[2]),this._pickColors.push(l[3]);const p=this._state.geometry.positionsCompressed.length,A=this._state.geometry.positionsCompressed,d=this._state.geometry.positionsDecodeMatrix;for(let e=0;e0){let t=!1;e.colorsBuf=new me(n,n.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,n.DYNAMIC_DRAW,t),this._colors=[]}if(this._metallicRoughness.length>0){const t=new Uint8Array(this._metallicRoughness);let s=!1;e.metallicRoughnessBuf=new me(n,n.ARRAY_BUFFER,t,this._metallicRoughness.length,2,n.STATIC_DRAW,s)}if(a>0){let t=!1;e.flagsBuf=new me(n,n.ARRAY_BUFFER,new Float32Array(a),a,1,n.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;e.offsetsBuf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,n.DYNAMIC_DRAW,t),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){const s=!1;e.positionsBuf=new me(n,n.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,n.STATIC_DRAW,s),e.positionsDecodeMatrix=h.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){const s=new Uint8Array(t.colorsCompressed),i=!1;e.colorsBuf=new me(n,n.ARRAY_BUFFER,s,s.length,4,n.STATIC_DRAW,i)}if(t.uvCompressed&&t.uvCompressed.length>0){const s=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new me(n,n.ARRAY_BUFFER,s,s.length,2,n.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new me(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,n.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new me(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,n.STATIC_DRAW)),this._modelMatrixCol0.length>0){const t=!1;e.modelMatrixCol0Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelMatrixCol1Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelMatrixCol2Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol1Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol2Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){const t=!1;e.pickColorsBuf=new me(n,n.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,n.STATIC_DRAW,t),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&s&&s.colorTexture&&s.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!s&&!!s.colorTexture,this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";ki[0]=t[0],ki[1]=t[1],ki[2]=t[2],ki[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(ki,4*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&j),l=!!(t&V),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Zs.NOT_RENDERED:s?Zs.COLOR_TRANSPARENT:Zs.COLOR_OPAQUE,h=!n||c?Zs.NOT_RENDERED:r?Zs.SILHOUETTE_SELECTED:a?Zs.SILHOUETTE_HIGHLIGHTED:i?Zs.SILHOUETTE_XRAYED:Zs.NOT_RENDERED;let p=0;p=!n||c?Zs.NOT_RENDERED:r?Zs.EDGES_SELECTED:a?Zs.EDGES_HIGHLIGHTED:i?Zs.EDGES_XRAYED:l?s?Zs.EDGES_COLOR_TRANSPARENT:Zs.EDGES_COLOR_OPAQUE:Zs.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Zs.PICK:Zs.NOT_RENDERED)<<12,A|=(t&F?1:0)<<16,Qi[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Qi,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ki[0]=t[0],Ki[1]=t[1],Ki[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Ki,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}getEachVertex(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;const s=this._state,n=s.geometry,i=this._portions[e];if(!i)return void this.model.error("portion not found: "+e);const a=n.quantizedPositions,r=s.origin,l=i.offset,o=r[0]+l[0],c=r[1]+l[1],u=r[2]+l[2],p=Wi,A=i.matrix,d=this.model.sceneModelMatrix,f=s.positionsDecodeMatrix;for(let e=0,s=a.length;ev)&&(v=e,n.set(w),i&&h.triangleNormal(f,I,y,i),m=!0)}}return m&&i&&(h.transformVec3(l.normalMatrix,i,i),h.transformVec3(this.model.worldNormalMatrix,i,i),h.normalizeVec3(i)),m}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}class sa extends An{drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class na extends An{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class ia{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new sa(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new na(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const aa={};class ra{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const la=h.vec4([0,0,0,1]),oa=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]),h.OBB3();class ca{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=aa[t];return s||(s=new ia(e),aa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete aa[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new ra(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ye({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:h.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=h.vec3(e.origin)),this.aabb=h.collapseAABB3()}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Ln(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new me(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.colors.length>0){const n=s.colors.length/4,i=new Float32Array(n);let a=!1;e.flagsBuf=new me(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new me(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2],c=t[3];for(let e=0;e0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 lightAmbient;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class ha extends dn{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 color;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class pa{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new ua(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ha(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Aa={};const da=new Uint8Array(4),fa=new Float32Array(1),Ia=h.vec4([0,0,0,1]),ya=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]);const ma=new Float32Array(3);class va{constructor(e){this.model=e.model,this.material=e.material,this.sortId="LinesInstancingLayer",this.layerIndex=e.layerIndex,this._linesInstancingRenderers=function(e){const t=e.id;let s=Aa[t];return s||(s=new pa(e),Aa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Aa[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new ye({obb:h.OBB3(),numInstances:0,origin:null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],e.origin&&(this._state.origin=h.vec3(e.origin)),this._finalized=!1,this.aabb=h.collapseAABB3()}createPortion(e){const t=e.color,s=e.opacity,n=e.meshMatrix,i=e.aabb;if(this._finalized)throw"Already finalized";const a=t[0],r=t[1],l=t[2];t[3],this._colors.push(a),this._colors.push(r),this._colors.push(l),this._colors.push(s),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(n[0]),this._modelMatrixCol0.push(n[4]),this._modelMatrixCol0.push(n[8]),this._modelMatrixCol0.push(n[12]),this._modelMatrixCol1.push(n[1]),this._modelMatrixCol1.push(n[5]),this._modelMatrixCol1.push(n[9]),this._modelMatrixCol1.push(n[13]),this._modelMatrixCol2.push(n[2]),this._modelMatrixCol2.push(n[6]),this._modelMatrixCol2.push(n[10]),this._modelMatrixCol2.push(n[14]),h.collapseAABB3(i);const o=this._state.obb,c=o.length;for(let e=0;e0){let t=!1;this._state.colorsBuf=new me(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,t),this._colors=[]}if(s>0){let t=!1;this._state.flagsBuf=new me(e,e.ARRAY_BUFFER,new Float32Array(s),s,1,e.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";da[0]=t[0],da[1]=t[1],da[2]=t[2],da[3]=t[3],this._state.colorsBuf.setData(da,4*e,4)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&j),l=!!(t&V),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Zs.NOT_RENDERED:s?Zs.COLOR_TRANSPARENT:Zs.COLOR_OPAQUE,h=!n||c?Zs.NOT_RENDERED:r?Zs.SILHOUETTE_SELECTED:a?Zs.SILHOUETTE_HIGHLIGHTED:i?Zs.SILHOUETTE_XRAYED:Zs.NOT_RENDERED;let p=0;p=!n||c?Zs.NOT_RENDERED:r?Zs.EDGES_SELECTED:a?Zs.EDGES_HIGHLIGHTED:i?Zs.EDGES_XRAYED:l?s?Zs.EDGES_COLOR_TRANSPARENT:Zs.EDGES_COLOR_OPAQUE:Zs.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Zs.PICK:Zs.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,fa[0]=A,this._state.flagsBuf.setData(fa,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(ma[0]=t[0],ma[1]=t[1],ma[2]=t[2],this._state.offsetsBuf.setData(ma,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesXRayed(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawOcclusion(e,t){}drawShadow(e,t){}drawPickMesh(e,t){}drawPickDepths(e,t){}drawPickNormals(e,t){}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}class wa extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial,n=[];return n.push("#version 300 es"),n.push("// Points batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class ga extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}class Ta extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class Ea extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batched pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batched pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class ba extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push(" gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class Da{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new wa(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ga(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Ta(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Ea(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new ba(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const Pa={};class Ra{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]}}const Ca=h.vec4(),_a=h.vec4(),Ba=h.vec4([0,0,0,1]),Oa=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]),h.OBB3();class Sa{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=Pa[t];return s||(s=new Da(e),Pa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Pa[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Ra(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ye({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:h.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=h.vec3(e.origin)),this.aabb=h.collapseAABB3()}canCreatePortion(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}createPortion(e){if(this._finalized)throw"Already finalized";const t=e.positions,s=e.positionsCompressed,n=e.color,i=e.colorsCompressed,a=e.colors,r=e.meshMatrix,l=e.worldAABB,o=e.pickColor,c=this._buffer,u=c.positions.length/3;let p;if(this._preCompressedPositionsExpected){if(!s)throw"positionsCompressed expected";for(let e=0,t=s.length;e0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Ln(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new me(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n);let a=!1;e.flagsBuf=new me(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new me(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new me(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized"}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2];for(let e=0;e0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class xa extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 silhouetteColor;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class La extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick mesh fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class Ma extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Fa extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Ha extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class Ua extends pn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("gl_PointSize = pointSize;"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }"),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Ga{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Na(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new xa(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Ha(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new La(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Ma(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Fa(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new Ua(this._scene)),this._shadowRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}const ja={};const Va=new Uint8Array(4),ka=new Float32Array(1),Qa=h.vec4([0,0,0,1]),Wa=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]);const za=new Float32Array(3);class Ka{constructor(e){this.model=e.model,this.material=e.material,this.sortId="PointsInstancingLayer",this.layerIndex=e.layerIndex,this._pointsInstancingRenderers=function(e){const t=e.id;let s=ja[t];return s||(s=new Ga(e),ja[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete ja[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new ye({obb:h.OBB3(),numInstances:0,origin:e.origin?h.vec3(e.origin):null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=h.collapseAABB3()}createPortion(e){const t=e.meshMatrix,s=e.aabb,n=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(n[0]),this._pickColors.push(n[1]),this._pickColors.push(n[2]),this._pickColors.push(n[3]),h.collapseAABB3(s);const i=this._state.obb,a=i.length;for(let e=0;e0){let n=!1;s.flagsBuf=new me(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,n)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;s.offsetsBuf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(n.positionsCompressed&&n.positionsCompressed.length>0){const t=!1;s.positionsBuf=new me(e,e.ARRAY_BUFFER,n.positionsCompressed,n.positionsCompressed.length,3,e.STATIC_DRAW,t),s.positionsDecodeMatrix=h.mat4(n.positionsDecodeMatrix)}if(n.colorsCompressed&&n.colorsCompressed.length>0){const t=new Uint8Array(n.colorsCompressed),i=!1;s.colorsBuf=new me(e,e.ARRAY_BUFFER,t,t.length,4,e.STATIC_DRAW,i)}if(this._modelMatrixCol0.length>0){const t=!1;s.modelMatrixCol0Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),s.modelMatrixCol1Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),s.modelMatrixCol2Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){const t=!1;s.pickColorsBuf=new me(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,t),this._pickColors=[]}s.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Va[0]=t[0],Va[1]=t[1],Va[2]=t[2],this._state.colorsBuf.setData(Va,3*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&j),l=!!(t&V),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Zs.NOT_RENDERED:s?Zs.COLOR_TRANSPARENT:Zs.COLOR_OPAQUE,h=!n||c?Zs.NOT_RENDERED:r?Zs.SILHOUETTE_SELECTED:a?Zs.SILHOUETTE_HIGHLIGHTED:i?Zs.SILHOUETTE_XRAYED:Zs.NOT_RENDERED;let p=0;p=!n||c?Zs.NOT_RENDERED:r?Zs.EDGES_SELECTED:a?Zs.EDGES_HIGHLIGHTED:i?Zs.EDGES_XRAYED:l?s?Zs.EDGES_COLOR_TRANSPARENT:Zs.EDGES_COLOR_OPAQUE:Zs.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Zs.PICK:Zs.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,ka[0]=A,this._state.flagsBuf.setData(ka,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(za[0]=t[0],za[1]=t[1],za[2]=t[2],this._state.offsetsBuf.setData(za,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawEdgesXRayed(e,t){}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Zs.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Zs.PICK)}drawPickNormals(e,t){}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}class Ya{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class Xa{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const qa={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class Ja{constructor(e,t,s){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,s=this.handlers.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==er[e])return void er[e].push({onLoad:t,onProgress:s,onError:n});er[e]=[],er[e].push({onLoad:t,onProgress:s,onError:n});const a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),r=this.mimeType,l=this.responseType;fetch(a).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const s=er[e],n=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,r=0!==a;let l=0;const o=new ReadableStream({start(e){!function t(){n.read().then((({done:n,value:i})=>{if(n)e.close();else{l+=i.byteLength;const n=new ProgressEvent("progress",{lengthComputable:r,loaded:l,total:a});for(let e=0,t=s.length;e{switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,r)));case"json":return e.json();default:if(void 0===r)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(r),s=t&&t[1]?t[1].toLowerCase():void 0,n=new TextDecoder(s);return e.arrayBuffer().then((e=>n.decode(e)))}}})).then((t=>{qa.add(e,t);const s=er[e];delete er[e];for(let e=0,n=s.length;e{const s=er[e];if(void 0===s)throw this.manager.itemError(e),t;delete er[e];for(let e=0,n=s.length;e{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class sr{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e{const n=this._getIdleWorker();-1!==n?(this._initWorker(n),this.workerStatus|=1<e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let nr=0;class ir{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new sr,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const n=e.capabilities;this._workerConfig={astcSupported:n.astcSupported,etc1Supported:n.etc1Supported,etc2Supported:n.etc2Supported,dxtSupported:n.dxtSupported,bptcSupported:n.bptcSupported,pvrtcSupported:n.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new tr;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new tr;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const n=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,n]).then((([e,t])=>{const s=ir.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(ir.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(ir.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(ir.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([n])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),nr>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),nr++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((n,i)=>{const a=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e))).then((e=>{const s=e.data,{mipmaps:a,width:r,height:l,format:o,type:c,error:u,dfdTransferFn:h,dfdFlags:p}=s;if("error"===c)return i(u);t.setCompressedData({mipmaps:a,props:{format:o,minFilter:1===a.length?1006:1008,magFilter:1===a.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&p)}}),n()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),nr--}}ir.BasisFormat={ETC1S:0,UASTC_4x4:1},ir.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},ir.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},ir.BasisWorker=function(){let e,t,s;const n=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(r){const u=r.data;switch(u.type){case"init":e=u.config,h=u.transcoderBinary,t=new Promise((e=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:r,hasAlpha:h,mipmaps:p,format:A,dfdTransferFn:d,dfdFlags:f}=function(t){const r=new s.KTX2File(new Uint8Array(t));function u(){r.close(),r.delete()}if(!r.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=r.isUASTC()?a.UASTC_4x4:a.ETC1S,p=r.getWidth(),A=r.getHeight(),d=r.getLevels(),f=r.getHasAlpha(),I=r.getDFDTransferFunc(),y=r.getDFDFlags(),{transcoderFormat:m,engineFormat:v}=function(t,s,r,u){let h,p;const A=t===a.ETC1S?l:o;for(let n=0;n{delete ar[t],s.destroy()}))),s} +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let r=!0,l=r?Float64Array:Float32Array;const o=new l(16),c=new l(16),u=new l(4),h={setDoublePrecisionEnabled(e){r=e,l=r?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>r,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new l(e||2),vec3:e=>new l(e||3),vec4:e=>new l(e||4),mat3:e=>new l(e||9),mat3ToMat4:(e,t=new l(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new l(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new l(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new l(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>h.dotVec4(e,e),lenVec4:e=>Math.sqrt(h.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>h.dotVec3(e,e),sqLenVec2:e=>h.dotVec2(e,e),lenVec3:e=>Math.sqrt(h.sqLenVec3(e)),distVec3:(()=>{const e=new l(3);return(t,s)=>h.lenVec3(h.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(h.sqLenVec2(e)),distVec2:(()=>{const e=new l(2);return(t,s)=>h.lenVec2(h.subVec2(t,s,e))})(),rcpVec3:(e,t)=>h.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/h.lenVec4(e);return h.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/h.lenVec3(e);return h.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/h.lenVec2(e);return h.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=h.dotVec3(e,t)/Math.sqrt(h.sqLenVec3(e)*h.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new l(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=h.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=h.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=h.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||h.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>h.m4s(0),setMat4ToOnes:()=>h.m4s(1),diagonalMat4v:e=>new l([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>h.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>h.diagonalMat4c(e,e,e,e),identityMat4:(e=new l(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new l(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>h.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new l(9));const n=e[0],i=e[3],a=e[6],r=e[1],o=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+o*I+c*v,s[4]=r*d+o*y+c*w,s[7]=r*f+o*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=h.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||h.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||h.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.translationMat4v(e,i))})(),translationMat4s:(e,t)=>h.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>h.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=h.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,p,A,d,f,I;return u=l*o,p=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||h.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*p+d,s[7]=0,s[8]=r*A+f,s[9]=r*p-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>h.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=h.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=h.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>h.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=h.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,p=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=p+v,s[2]=A-m,s[3]=0,s[4]=p-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=h.vec4()){const n=h.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],p=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(p,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(p,-1,1)),Math.abs(p)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(p,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(p,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=h.mat4())=>(h.quaternionToRotationMat4(t,n),h.scaleMat4v(s,n),h.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new l(3),t=new l(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=h.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=h.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=h.lenVec3(e);h.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,p=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=p,t[9]*=p,t[10]*=p,h.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=h.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],p=t[1],A=t[2];if(i===u&&a===p&&r===A)return h.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-p,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>h.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=h.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];h.addVec4(i,n,o),h.subVec4(i,n,c);const a=2*n[2],r=c[0],l=c[1],u=c[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=o[0]/r,s[9]=o[1]/l,s[10]=-o[2]/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/u,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],h.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=h.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new l(16),t=new l(16),s=new l(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||h.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||h.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=h.vec4()){const n=e[0]*h.DEGTORAD/2,i=e[1]*h.DEGTORAD/2,a=e[2]*h.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),p=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"YXZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"ZXY"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"ZYX"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"YZX"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o-c*u*p):"XZY"===t&&(s[0]=c*l*o-r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o+c*u*p),s},mat4ToQuaternion(e,t=h.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let p;const A=s+r+u;return A>0?(p=.5/Math.sqrt(A+1),t[3]=.25/p,t[0]=(c-l)*p,t[1]=(i-o)*p,t[2]=(a-n)*p):s>r&&s>u?(p=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/p,t[0]=.25*p,t[1]=(n+a)/p,t[2]=(i+o)/p):r>u?(p=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/p,t[0]=(n+a)/p,t[1]=.25*p,t[2]=(l+c)/p):(p=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/p,t[0]=(i+o)/p,t[1]=(l+c)/p,t[2]=.25*p),t},vec3PairToQuaternion(e,t,s=h.vec4()){const n=Math.sqrt(h.dotVec3(e,e)*h.dotVec3(t,t));let i=n+h.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):h.cross3Vec3(e,t,s),s[3]=i,h.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=h.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new l(16);return(t,s,n)=>(n=n||h.vec3(),h.quaternionToRotationMat4(t,e),h.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=h.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,p=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+p*-o-A*-l,s[1]=p*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-p*-r,s},quaternionToMat4(e,t){t=h.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,p=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+p,t[2]=f-u,t[4]=d-p,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=h.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>h.normalizeQuaternion(h.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=h.vec4()){const s=(e=h.normalizeQuaternion(e,u))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new l(e||6),AABB2:e=>new l(e||4),OBB3:e=>new l(e||32),OBB2:e=>new l(e||16),Sphere3:(e,t,s,n)=>new l([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new l(3),t=new l(3),s=new l(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],h.subVec3(t,e,s),Math.abs(h.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=h.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],p=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>p?u:p,Math.abs(h.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||h.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||h.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=h.AABB3())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MAX_DOUBLE,e[3]=h.MIN_DOUBLE,e[4]=h.MIN_DOUBLE,e[5]=h.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=h.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new l(3);return(t,s,n)=>{s=s||h.AABB3();let i,a,r,l=h.MAX_DOUBLE,o=h.MAX_DOUBLE,c=h.MAX_DOUBLE,u=h.MIN_DOUBLE,p=h.MIN_DOUBLE,A=h.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>p&&(p=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=p,s[5]=A,s}})(),OBB3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new l(3);return(t,s)=>{s=s||h.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=p);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ip&&(p=u);return n[3]=p,n}})(),getSphere3Center:(e,t=h.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=h.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MIN_DOUBLE,e[3]=h.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=h.AABB2()){let s,n,i,a,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=h.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,p=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+p*p+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=p/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3);return(a,r,l,o,c,u)=>{u=u||h.vec3();const p=h.subVec3(o,l,e),A=h.subVec3(c,l,t),d=h.cross3Vec3(r,A,s),f=h.dotVec3(p,d);if(f<1e-6)return null;const I=h.subVec3(a,l,n),y=h.dotVec3(I,d);if(y<0||y>f)return null;const m=h.cross3Vec3(I,p,i),v=h.dotVec3(r,m);if(v<0||y+v>f)return null;const w=h.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3);return(i,a,r,l,o,c)=>{c=c||h.vec3(),a=h.normalizeVec3(a,e);const u=h.subVec3(l,r,t),p=h.subVec3(o,r,s),A=h.cross3Vec3(u,p,n);h.normalizeVec3(A,A);const d=-h.dotVec3(r,A),f=-(h.dotVec3(i,A)+d)/h.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i,a,r,l)=>{const o=h.subVec3(r,i,e),c=h.subVec3(a,i,t),u=h.subVec3(n,i,s),p=h.dotVec3(o,o),A=h.dotVec3(o,c),d=h.dotVec3(o,u),f=h.dotVec3(c,c),I=h.dotVec3(c,u),y=p*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(p*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=h.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3);return(r,l,o)=>{let c,u;const p=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3),r=new l(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let p=0;p>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,p;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new l(4),t=new l(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,h.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],h.transformVec3(s,e,t),h.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new l(16),t=new l(16),s=new l(4),n=new l(4),i=new l(4),a=new l(4);return(r,l,o,c,u,p)=>{const A=h.mulMat4(o,l,e),d=h.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,h.transformVec4(d,s,n),h.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,h.transformVec4(d,i,a),h.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],h.subVec3(a,n,p),h.normalizeVec3(p)}})(),canvasPosToLocalRay:(()=>{const e=new l(3),t=new l(3);return(s,n,i,a,r,l,o)=>{h.canvasPosToWorldRay(s,n,i,r,e,t),h.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new l(16),t=new l(4),s=new l(4);return(n,i,a,r,l)=>{const o=h.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,h.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],h.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new l(6),o={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return o.triangles=s,o.leaf=!0,o;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),o.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};h.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class p{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const A={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var d=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{v.removeItem(e.id),delete P.scenes[e.id],delete m[e.id],A.components.scenes--}))},this.clear=function(){let e;for(const t in P.scenes)P.scenes.hasOwnProperty(t)&&(e=P.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete P.scenes[e.id]))},this.scheduleTask=function(e,t){w.push(e),w.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;w.length>0&&(e<0||n0&&E>0){var t=1e3/E;D+=t,T.push(t),T.length>=30&&(D-=T.shift()),A.frame.fps=Math.round(D/T.length)}!function(e){const t=P.runTasks(e+10),s=P.getNumTasks();A.frame.tasksRun=t,A.frame.tasksScheduled=s,A.frame.tasksBudget=10}(e),function(e){for(var t in g.time=e,P.scenes)if(P.scenes.hasOwnProperty(t)){var s=P.scenes[t];g.sceneId=t,g.startTime=s.startTime,g.deltaTime=null!=g.prevTime?g.time-g.prevTime:0,s.fire("tick",g,!0)}g.prevTime=e}(e),function(){const e=P.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=m[r],n||(n=m[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),b=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R);class C{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof C))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+y.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(y.isNumeric(s)||y.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+y.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+y.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+y.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():P.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(h.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){K.set(this._viewPos),K[3]=1,h.transformPoint4(this.scene.camera.projMatrix,K,Y);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+Y[0]/Y[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-Y[1]/Y[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof z?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),O(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class q{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class J{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class Z{constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var $=h.vec3(),ee=h.vec3();class te extends C{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new X(s,t.origin),this._cornerMarker=new X(s,t.corner),this._targetMarker=new X(s,t.target),this._originWorld=h.vec3(),this._cornerWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new J(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new J(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new J(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new q(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new q(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new Z(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(h.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,p=t.length;u1?i.other:i.one,i?(i=ie(i,[t]),s&&(i=ie(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const a=this._events[t];return void 0!==a&&s(a),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function ne(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),a=this.getPoint(n),r=h.subVec3(a,i,[]);return h.normalizeVec3(r,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),a=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),a+=h.lenVec3(h.subVec3(t,i,[])),n.push(a),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,a=n.length;s=t||e*n[a-1];for(var r,l=0,o=a-1;l<=o;)if((r=n[i=Math.floor(l+(o-l)/2)]-s)<0)l=i+1;else{if(!(r>0)){o=i;break}o=i-1}if(n[i=o]===s)return i/(a-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(a-1)}}class re extends ae{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,a=t[0===n?n:n-1],r=t[n],l=t[n>t.length-2?t.length-1:n+1],o=t[n>t.length-3?t.length-1:n+2],c=h.vec3();return c[0]=h.catmullRomInterpolate(a[0],r[0],l[0],o[0],i),c[1]=h.catmullRomInterpolate(a[1],r[1],l[1],o[1],i),c[2]=h.catmullRomInterpolate(a[2],r[2],l[2],o[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const le=h.vec3();const oe=h.vec3(),ce=h.vec3(),ue=h.vec3(),he=h.vec3(),pe=h.vec3();class Ae extends C{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.vec3(),this._orthoScale1=1,this._orthoScale2=1,this._flying=!1,this._flyEyeLookUp=!1,this._flyingEye=!1,this._flyingLook=!1,this._callback=null,this._callbackScope=null,this._time1=null,this._time2=null,this.easing=!1!==t.easing,this.duration=t.duration,this.fit=t.fit,this.fitFOV=t.fitFOV,this.trail=t.trail}flyTo(e,t,s){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=s;const n=this.scene.camera,i=!!e.projection&&e.projection!==n.projection;let a,r,l,o,c;if(this._eye1[0]=n.eye[0],this._eye1[1]=n.eye[1],this._eye1[2]=n.eye[2],this._look1[0]=n.look[0],this._look1[1]=n.look[1],this._look1[2]=n.look[2],this._up1[0]=n.up[0],this._up1[1]=n.up[1],this._up1[2]=n.up[2],this._orthoScale1=n.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)a=e.aabb;else if(6===e.length)a=e;else if(e.eye&&e.look||e.up)r=e.eye,l=e.look,o=e.up;else if(e.eye)r=e.eye;else if(e.look)l=e.look;else{let n=e;if((y.isNumeric(n)||y.isString(n))&&(c=n,n=this.scene.components[c],!n))return this.error("Component not found: "+y.inQuotes(c)),void(t&&(s?t.call(s):t()));i||(a=n.aabb||this.scene.aabb)}const u=e.poi;if(a){if(a[3]=1;e>1&&(e=1);const s=this.easing?Ae._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(n.eye,n.look,pe),n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,ue),n.look=h.subVec3(ue,pe,ce)):this._flyingLook&&(n.look=h.lerpVec3(s,0,1,this._look1,this._look2,ce),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,he)):this._flyingEyeLookUp&&(n.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,ue),n.look=h.lerpVec3(s,0,1,this._look1,this._look2,ce),n.up=h.lerpVec3(s,0,1,this._up1,this._up2,he)),this._projection2){const t="ortho"===this._projection2?Ae._easeOutExpo(e,0,1,1):Ae._easeInCubic(e,0,1,1);n.customProjection.matrix=h.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();P.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class de extends C{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Ae(this),this._t=0,this.state=de.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case de.SCRUBBING:return;case de.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=de.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case de.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=de.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=de.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=de.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=de.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=de.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=de.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=de.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}de.STOPPED=0,de.SCRUBBING=1,de.PLAYING=2,de.PLAYING_TO=3;class fe extends C{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),A.memory.meshes++}destroy(){super.destroy(),A.memory.meshes--}}const Ie=new e({});class ye{constructor(e){this.id=Ie.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Ie.removeItem(this.id)}}class me{constructor(e,t,s,n,i,a,r,l,o){switch(this._gl=e,this.type=t,this.allocated=!1,s.constructor){case Uint8Array:this.itemType=e.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=e.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=e.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=e.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=e.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=e.INT,this.itemByteSize=4;break;default:this.itemType=e.FLOAT,this.itemByteSize=4}this.usage=a,this.length=0,this.dataLength=n,this.numItems=0,this.itemSize=i,this.normalized=!!r,this.stride=l||0,this.offset=o||0,this._allocate(s)}_allocate(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}var ve=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();const we=function(){const e=h.mat4(),t=h.mat4();return function(s,n){n=n||h.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return h.identityMat4(e),h.translationMat4v(s,e),h.identityMat4(t),h.scalingMat4v([l/u,o/u,c/u],t),h.mulMat4(e,t,n),n}}();var ge=function(){const e=h.mat4(),t=h.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function be(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function De(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const Pe={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=Ee(e,l,"floor","ceil"),n=be(s),a=De(e,l,n),a>r&&(i=s,r=a),s=Ee(e,l,"ceil","ceil"),n=be(s),a=De(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},Re=A.memory,Ce=h.AABB3();class _e extends fe{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new ye({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=Pe.getPositionsBounds(t.positions),n=Pe.compressPositions(t.positions,e.min,e.max);s.positions=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=Pe.getUVBounds(t.uv),n=Pe.compressUVs(t.uv,e.min,e.max);s.uv=n.quantized,s.uvDecodeMatrix=n.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);t.normals&&(this._state.compressGeometry?s.normals=Pe.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),Re.meshes++,this._buildVBOs()}_buildVBOs(){const e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),Re.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new me(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),Re.positions+=e.positionsBuf.numItems),e.normals){let s=e.compressGeometry;e.normalsBuf=new me(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,s),Re.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new me(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),Re.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new me(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),Re.uvs+=e.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=ve(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),Re.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=h.buildPickTriangles(e.positions,e.indices,e.compressGeometry),n=s.positions,i=s.colors;this._pickTrianglePositionsBuf=new me(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new me(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),Re.positions+=this._pickTrianglePositionsBuf.numItems,Re.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}_webglContextLost(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}_webglContextRestored(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),Pe.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=Pe.getPositionsBounds(e),n=Pe.compressPositions(e,s.min,s.max);e=n.quantized,t.positionsDecodeMatrix=n.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),Pe.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),Pe.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=h.AABB3()),h.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=h.OBB3()),h.positions3ToAABB3(this._state.positions,Ce,this._state.positionsDecodeMatrix),h.AABB3ToOBB3(Ce,this._obb),this._obbDirty=!1),this._obb}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),Re.meshes--}}const Be=A.memory,Oe=h.AABB3();class Se extends fe{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new ye({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=h.OBB3();const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var i;if(t.positionsDecodeMatrix);else{const e=Pe.getPositionsBounds(t.positions),a=Pe.compressPositions(t.positions,e.min,e.max);i=a.quantized,s.positionsDecodeMatrix=a.decodeMatrix,s.positionsBuf=new me(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),Be.positions+=s.positionsBuf.numItems,h.positions3ToAABB3(t.positions,this._aabb),h.positions3ToAABB3(i,Oe,s.positionsDecodeMatrix),h.AABB3ToOBB3(Oe,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new me(n,n.ARRAY_BUFFER,e,e.length,4,n.STATIC_DRAW),Be.colors+=s.colorsBuf.numItems}if(t.uv){const e=Pe.getUVBounds(t.uv),i=Pe.compressUVs(t.uv,e.min,e.max),a=i.quantized;s.uvDecodeMatrix=i.decodeMatrix,s.uvBuf=new me(n,n.ARRAY_BUFFER,a,a.length,2,n.STATIC_DRAW),Be.uvs+=s.uvBuf.numItems}if(t.normals){const e=Pe.compressNormals(t.normals);let i=s.compressGeometry;s.normalsBuf=new me(n,n.ARRAY_BUFFER,e,e.length,3,n.STATIC_DRAW,i),Be.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new me(n,n.ELEMENT_ARRAY_BUFFER,e,e.length,1,n.STATIC_DRAW),Be.indices+=s.indicesBuf.numItems;const a=ve(i,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new me(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),Be.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),Be.meshes--}}var Ne={};function xe(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return y.apply(e,{positions:[h,p,A,o,p,A,o,c,A,h,c,A,h,p,A,h,c,A,h,c,u,h,p,u,h,p,A,h,p,u,o,p,u,o,p,A,o,p,A,o,p,u,o,c,u,o,c,A,o,c,u,h,c,u,h,c,A,o,c,A,h,c,u,o,c,u,o,p,u,h,p,u],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function Le(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let n=e.height||1;n<0&&(console.error("negative height not allowed - will invert"),n*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);let a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);const r=!!e.openEnded;let l=e.center;const o=l?l[0]:0,c=l?l[1]:0,u=l?l[2]:0,h=n/2,p=n/a,A=2*Math.PI/i,d=1/i,f=(t-s)/a,I=[],m=[],v=[],w=[];let g,T,E,b,D,P,R,C,_,B,O;const S=(90-180*Math.atan(n/(s-t))/Math.PI)/90;for(g=0;g<=a;g++)for(D=t-g*f,P=h-g*p,T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),m.push(D*E),m.push(S),m.push(D*b),v.push(T*d),v.push(1*g/a),I.push(D*E+o),I.push(P+c),I.push(D*b+u);for(g=0;g0){for(_=I.length/3,m.push(0),m.push(1),m.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,m.push(t*E),m.push(1),m.push(t*b),v.push(B),v.push(O),I.push(t*E+o),I.push(h+c),I.push(t*b+u);for(T=0;T0){for(_=I.length/3,m.push(0),m.push(-1),m.push(0),v.push(.5),v.push(.5),I.push(0+o),I.push(0-h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,m.push(s*E),m.push(-1),m.push(s*b),v.push(B),v.push(O),I.push(s*E+o),I.push(0-h+c),I.push(s*b+u);for(T=0;T65535?Uint32Array:Uint16Array)(h*p*6);for(g=0;g360&&(a=360);const r=e.center;let l=r?r[0]:0,o=r?r[1]:0;const c=r?r[2]:0,u=[],p=[],A=[],d=[];let f,I,m,v,w,g,T,E,b,D,P,R;for(E=0;E<=i;E++)for(T=0;T<=n;T++)f=T/n*a,I=.785398+E/i*Math.PI*2,l=t*Math.cos(f),o=t*Math.sin(f),m=(t+s*Math.cos(I))*Math.cos(f),v=(t+s*Math.cos(I))*Math.sin(f),w=s*Math.sin(I),u.push(m+l),u.push(v+o),u.push(w+c),A.push(1-T/n),A.push(E/i),g=h.normalizeVec3(h.subVec3([m,v,w],[l,o,c],[]),[]),p.push(g[0]),p.push(g[1]),p.push(g[2]);for(E=1;E<=i;E++)for(T=1;T<=n;T++)b=(n+1)*E+T-1,D=(n+1)*(E-1)+T-1,P=(n+1)*(E-1)+T,R=(n+1)*E+T,d.push(b),d.push(D),d.push(P),d.push(P),d.push(R),d.push(b);return y.apply(e,{positions:u,normals:p,uv:A,indices:d})}Ne.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},Ne.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(Ne.parse._buffToStr(e));window.location.href=s},Ne.clone=function(e){return JSON.parse(JSON.stringify(e))},Ne.bin={},Ne.bin.f=new Float32Array(1),Ne.bin.fb=new Uint8Array(Ne.bin.f.buffer),Ne.bin.rf=function(e,t){for(var s=Ne.bin.f,n=Ne.bin.fb,i=0;i<4;i++)n[i]=e[t+i];return s[0]},Ne.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Ne.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Ne.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},Ne.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},Ne.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},Ne.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},Ne.parse={},Ne.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",n=0;ni&&(i=o),ca&&(a=c),ur&&(r=u)}return{min:{x:t,y:s,z:n},max:{x:i,y:a,z:r}}};const Ge={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function je(e={}){var t=e.origin||[0,0,0],s=t[0],n=t[1],i=t[2],a=e.size||1,r=[],l=[],o=e.text;y.isNumeric(o)&&(o=""+o);for(var c,u,h,p,A,d,f,I,m,v=(o||"").split("\n"),w=0,g=0,T=.04,E=0;E0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice();let t;for(let s=0,n=e.length;s0,o=!!i.compressGeometry,c=[];c.push("#version 300 es"),c.push("// Lambertian drawing vertex shader"),c.push("in vec3 position;"),c.push("uniform mat4 modelMatrix;"),c.push("uniform mat4 viewMatrix;"),c.push("uniform mat4 projMatrix;"),c.push("uniform vec4 colorize;"),c.push("uniform vec3 offset;"),o&&c.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(c.push("uniform float logDepthBufFC;"),c.push("out float vFragDepth;"),c.push("bool isPerspectiveMatrix(mat4 m) {"),c.push(" return (m[2][3] == - 1.0);"),c.push("}"),c.push("out float isPerspective;"));l&&c.push("out vec4 vWorldPosition;");if(c.push("uniform vec4 lightAmbient;"),c.push("uniform vec4 materialColor;"),c.push("uniform vec3 materialEmissive;"),i.normalsBuf){c.push("in vec3 normal;"),c.push("uniform mat4 modelNormalMatrix;"),c.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),c.push(" }"),c.push(" return normalize(v);"),c.push("}"))}c.push("out vec4 vColor;"),"points"===i.primitiveName&&c.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(c.push("void billboard(inout mat4 mat) {"),c.push(" mat[0][0] = 1.0;"),c.push(" mat[0][1] = 0.0;"),c.push(" mat[0][2] = 0.0;"),"spherical"===a&&(c.push(" mat[1][0] = 0.0;"),c.push(" mat[1][1] = 1.0;"),c.push(" mat[1][2] = 0.0;")),c.push(" mat[2][0] = 0.0;"),c.push(" mat[2][1] = 0.0;"),c.push(" mat[2][2] =1.0;"),c.push("}"));c.push("void main(void) {"),c.push("vec4 localPosition = vec4(position, 1.0); "),c.push("vec4 worldPosition;"),o&&c.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(o?c.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):c.push("vec4 localNormal = vec4(normal, 0.0); "),c.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),c.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));c.push("mat4 viewMatrix2 = viewMatrix;"),c.push("mat4 modelMatrix2 = modelMatrix;"),r&&c.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(c.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),c.push("billboard(modelMatrix2);"),c.push("billboard(viewMatrix2);"),c.push("billboard(modelViewMatrix);"),i.normalsBuf&&(c.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),c.push("billboard(modelNormalMatrix2);"),c.push("billboard(viewNormalMatrix2);"),c.push("billboard(modelViewNormalMatrix);")),c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&c.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(c.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),c.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),c.push("float lambertian = 1.0;"),i.normalsBuf)for(let e=0,t=n.lights.length;e0,a=t.gammaOutput,r=[];r.push("#version 300 es"),r.push("// Lambertian drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(i){r.push("in vec4 vWorldPosition;"),r.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),r.push("}")}"points"===n.primitiveName&&(r.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),r.push("float r = dot(cxy, cxy);"),r.push("if (r > 1.0) {"),r.push(" discard;"),r.push("}"));t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?r.push("outColor = linearToGamma(vColor, gammaFactor);"):r.push("outColor = vColor;");return r.push("}"),r}(e)):(this.vertex=function(e){const t=e.scene;e._material;const s=e._state,n=t._sectionPlanesState,i=e._geometry._state,a=t._lightsState;let r;const l=s.billboard,o=s.background,c=s.stationary,u=function(e){if(!e._geometry._state.uvBuf)return!1;const t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),h=tt(e),p=n.sectionPlanes.length>0,A=et(e),d=!!i.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),d&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),p&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));a.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(h){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(let e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}u&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),d&&f.push("uniform mat3 uvDecodeMatrix;"));i.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===i.primitiveName&&f.push("uniform float pointSize;");"spherical"!==l&&"cylindrical"!==l||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===l&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(A){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(let e=0,t=a.lights.length;e0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(let e=0,t=a.lights.length;e0,o=tt(e),c=n.uvBuf,u="PhongMaterial"===r.type,h="MetallicMaterial"===r.type,p="SpecularMaterial"===r.type,A=et(e);t.gammaInput;const d=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));A&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),d&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(l){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var I=0;I0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),u&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = "+$e[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(h||p)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),a.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+$e[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),n.colors&&f.push("in vec4 vColor;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._occlusionMap||s._alphaMap)&&f.push("in vec2 vUV;");o&&(a.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));r.ambient&&f.push("uniform vec3 materialAmbient;");r.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==r.alpha&&null!==r.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");r.emissive&&f.push("uniform vec3 materialEmissive;");r.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==r.glossiness&&null!==r.glossiness&&f.push("uniform float materialGlossiness;");void 0!==r.shininess&&null!==r.shininess&&f.push("uniform float materialShininess;");r.specular&&f.push("uniform vec3 materialSpecular;");void 0!==r.metallic&&null!==r.metallic&&f.push("uniform float materialMetallic;");void 0!==r.roughness&&null!==r.roughness&&f.push("uniform float materialRoughness;");void 0!==r.specularF0&&null!==r.specularF0&&f.push("uniform float materialSpecularF0;");c&&s._ambientMap&&(f.push("uniform sampler2D ambientMap;"),s._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));c&&s._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),s._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));c&&s._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),s._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));c&&s._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),s._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));o&&c&&s._metallicMap&&(f.push("uniform sampler2D metallicMap;"),s._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));o&&c&&s._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),s._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));o&&c&&s._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),s._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));o&&s._normalMap&&(f.push("uniform sampler2D normalMap;"),s._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));c&&s._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),s._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));c&&s._alphaMap&&(f.push("uniform sampler2D alphaMap;"),s._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));o&&c&&s._specularMap&&(f.push("uniform sampler2D specularMap;"),s._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));o&&c&&s._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),s._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));o&&c&&s._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),s._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));o&&(s._diffuseFresnel||s._specularFresnel||s._alphaFresnel||s._emissiveFresnel||s._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),s._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),s._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),s._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),s._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),s._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),o)for(let e=0,t=a.lights.length;e 0.0) { discard; }"),f.push("}")}"points"===n.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),r.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");r.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):r.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");n.colors&&f.push("diffuseColor *= vColor.rgb;");r.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");r.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==r.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");n.colors&&f.push("alpha *= vColor.a;");void 0!==r.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==r.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==r.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==r.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._occlusionMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));c&&s._ambientMap&&(s._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+$e[s._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));c&&s._diffuseMap&&(s._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+$e[s._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));c&&s._baseColorMap&&(s._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+$e[s._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));c&&s._emissiveMap&&(s._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+$e[s._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));c&&s._alphaMap&&(s._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));c&&s._occlusionMap&&(s._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(o&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){c&&s._normalMap?(s._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),c&&s._specularMap&&(s._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),c&&s._glossinessMap&&(s._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),c&&s._specularGlossinessMap&&(s._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),c&&s._metallicMap&&(s._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),c&&s._roughnessMap&&(s._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),c&&s._metallicRoughnessMap&&(s._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),s._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),s._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),s._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),s._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),u&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),p&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),h&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),u&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||h)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(let e=0,t=a.lights.length;e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function lt(e){console.error(e.join("\n"))}class ot{constructor(e,t){this.id=at.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new st(e,e.VERTEX_SHADER,rt(this.source.vertex)),this._fragmentShader=new st(e,e.FRAGMENT_SHADER,rt(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void lt(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void lt(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void lt(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void lt(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void lt(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;s0?ct.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?ct.FS_MAX_FLOAT_PRECISION="mediump":ct.FS_MAX_FLOAT_PRECISION="lowp":ct.FS_MAX_FLOAT_PRECISION="mediump",ct.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),ct.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),ct.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),ct.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),ct.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),ct.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),ct.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),ct.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),ct.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),ct.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){ct.SUPPORTED_EXTENSIONS[e]=!0})))}const ht=h.vec3(),pt=new e({}),At=function(e,t){this.id=pt.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ze(t),this._allocate(t)},dt={};At.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,(t.gammaInput?"gi;":";")+(t.gammaOutput?"go":""),t._lightsState.getHash(),t._sectionPlanesState.getHash(),e._geometry._state.hash,e._material._state.hash,e._state.drawHash].join(";");let n=dt[s];if(!n){if(n=new At(s,e),n.errors)return console.log(n.errors.join("\n")),null;dt[s]=n,A.memory.programs++}return n._useCount++,n},At.prototype.put=function(){0==--this._useCount&&(pt.removeItem(this.id),this._program&&this._program.destroy(),delete dt[this._hash],A.memory.programs--)},At.prototype.webglContextRestored=function(){this._program=null},At.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=ct.MAX_TEXTURE_UNITS,n=t.scene,i=t._material,a=n.canvas.gl,r=this._program,l=t._state,o=t._material._state,c=t._geometry._state,u=n.camera,h=t.origin,p=l.background;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,p&&a.depthFunc(a.LEQUAL),this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,h?e.getRTCViewMatrix(l.originHash,h):u.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,u.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(u=0,h=a.sectionPlanes.length;u0&&i.lightMaps[0].texture&&this._uLightMap&&(l.bindTexture(this._uLightMap,i.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),i.reflectionMaps.length>0&&i.reflectionMaps[0].texture&&this._uReflectionMap&&(l.bindTexture(this._uReflectionMap,i.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),this._uGammaFactor&&n.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};class ft{constructor(e){this.vertex=function(e){const t=e.scene,s=t._lightsState,n=function(e){const t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,r=e._state.billboard,l=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// EmphasisFillShaderSource vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 colorize;"),o.push("uniform vec3 offset;"),a&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");if(o.push("uniform vec4 lightAmbient;"),o.push("uniform vec4 fillColor;"),n){o.push("in vec3 normal;"),o.push("uniform mat4 modelNormalMatrix;"),o.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"))}o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),a&&o.push("localPosition = positionsDecodeMatrix * localPosition;");n&&(a?o.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):o.push("vec4 localNormal = vec4(normal, 0.0); "),o.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),o.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),l&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),n&&(o.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),o.push("billboard(modelNormalMatrix2);"),o.push("billboard(viewNormalMatrix2);"),o.push("billboard(modelViewNormalMatrix);")),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&o.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),n)for(let e=0,t=s.lights.length;e0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const It=new e({}),yt=h.vec3(),mt=function(e,t){this.id=It.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new ft(t),this._allocate(t)},vt={};mt.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=vt[t];return s||(s=new mt(t,e),vt[t]=s,A.memory.programs++),s._useCount++,s},mt.prototype.put=function(){0==--this._useCount&&(It.removeItem(this.id),this._program&&this._program.destroy(),delete vt[this._hash],A.memory.programs--)},mt.prototype.webglContextRestored=function(){this._program=null},mt.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl,r=0===s?t._xrayMaterial._state:1===s?t._highlightMaterial._state:t._selectedMaterial._state,l=t._state,o=t._geometry._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Edges drawing vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec4 edgeColor;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));s&&r.push("out vec4 vWorldPosition;");r.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.push("vColor = edgeColor;"),s&&r.push("vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=e.scene._sectionPlanesState,n=e.scene.gammaOutput,i=s.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const gt=new e({}),Tt=h.vec3(),Et=function(e,t){this.id=gt.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new wt(t),this._allocate(t)},bt={};Et.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=bt[t];return s||(s=new Et(t,e),bt[t]=s,A.memory.programs++),s._useCount++,s},Et.prototype.put=function(){0==--this._useCount&&(gt.removeItem(this.id),this._program&&this._program.destroy(),delete bt[this._hash],A.memory.programs--)},Et.prototype.webglContextRestored=function(){this._program=null},Et.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl;let r;const l=t._state,o=t._geometry,c=o._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(l.originHash,u):i.viewMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh picking vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("out vec4 vViewPosition;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("uniform vec2 pickClipPos;"),r.push("vec4 remapClipPos(vec4 clipPos) {"),r.push(" clipPos.xy /= clipPos.w;"),r.push(" clipPos.xy -= pickClipPos;"),r.push(" clipPos.xy *= clipPos.w;"),r.push(" return clipPos;"),r.push("}"),r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"));r.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = remapClipPos(clipPos);"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(e)}}const Pt=h.vec3(),Rt=function(e,t){this._hash=e,this._shaderSource=new Dt(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Ct={};Rt.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let s=Ct[t];if(!s){if(s=new Rt(t,e),s.errors)return console.log(s.errors.join("\n")),null;Ct[t]=s,A.memory.programs++}return s._useCount++,s},Rt.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Ct[this._hash],A.memory.programs--)},Rt.prototype.webglContextRestored=function(){this._program=null},Rt.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t>24&255,u=o>>16&255,h=o>>8&255,p=255&o;n.uniform4f(this._uPickColor,p/255,h/255,u/255,c/255),n.uniform2fv(this._uPickClipPos,e.pickClipPos),r.indicesBuf?(n.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&n.drawArrays(n.TRIANGLES,0,r.positions.numItems)},Rt.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new ot(s,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0,n=!!e._geometry._state.compressGeometry,i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),s&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("uniform vec2 pickClipPos;"),i.push("vec4 remapClipPos(vec4 clipPos) {"),i.push(" clipPos.xy /= clipPos.w;"),i.push(" clipPos.xy -= pickClipPos;"),i.push(" clipPos.xy *= clipPos.w;"),i.push(" return clipPos;"),i.push("}"),i.push("out vec4 vColor;"),n&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),n&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),s&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(e)}}const Bt=h.vec3(),Ot=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new _t(t),this._allocate(t)},St={};Ot.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=St[t];if(!s){if(s=new Ot(t,e),s.errors)return console.log(s.errors.join("\n")),null;St[t]=s,A.memory.programs++}return s._useCount++,s},Ot.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete St[this._hash],A.memory.programs--)},Ot.prototype.webglContextRestored=function(){this._program=null},Ot.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry,l=t._geometry._state,o=t.origin,c=a.backfaces,u=a.frontface,h=s.camera.project,p=r._getPickTrianglePositions(),A=r._getPickTriangleColors();if(this._program.bind(),e.useProgram++,s.logarithmicDepthBufferEnabled){const e=2/(Math.log(h.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,e)}if(n.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(e)}}const xt=h.vec3(),Lt=function(e,t){this._hash=e,this._shaderSource=new Nt(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Mt={};Lt.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";");let s=Mt[t];if(!s){if(s=new Lt(t,e),s.errors)return console.log(s.errors.join("\n")),null;Mt[t]=s,A.memory.programs++}return s._useCount++,s},Lt.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Mt[this._hash],A.memory.programs--)},Lt.prototype.webglContextRestored=function(){this._program=null},Lt.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._material._state,a=t._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){const t=i.backfaces;e.backfaces!==t&&(t?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=t);const s=i.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),this._lastMaterialId=i.id}const o=s.camera;if(n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCViewMatrix(a.originHash,l):o.viewMatrix),a.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,s=!!e._geometry._state.compressGeometry,n=[];n.push("// Mesh shadow vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),n.push("uniform vec3 offset;"),s&&n.push("uniform mat4 positionsDecodeMatrix;");t&&n.push("out vec4 vWorldPosition;");n.push("void main(void) {"),n.push("vec4 localPosition = vec4(position, 1.0); "),n.push("vec4 worldPosition;"),s&&n.push("localPosition = positionsDecodeMatrix * localPosition;");n.push("worldPosition = modelMatrix * localPosition;"),n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&n.push("vWorldPosition = worldPosition;");return n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n}(e),this.fragment=function(e){const t=e.scene;t.canvas.gl;const s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(e)}}const Ht=function(e,t){this._hash=e,this._shaderSource=new Ft(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Ut={};Ht.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let n=Ut[s];if(!n){if(n=new Ht(s,e),n.errors)return console.log(n.errors.join("\n")),null;Ut[s]=n,A.memory.programs++}return n._useCount++,n},Ht.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Ut[this._hash],A.memory.programs--)},Ht.prototype.webglContextRestored=function(){this._program=null},Ht.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene.canvas.gl,n=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.id!==this._lastMaterialId){const t=n.backfaces;e.backfaces!==t&&(t?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=t);const i=n.frontface;e.frontface!==i&&(i?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=i),e.lineWidth!==n.lineWidth&&(s.lineWidth(n.lineWidth),e.lineWidth=n.lineWidth),this._uPointSize&&s.uniform1i(this._uPointSize,n.pointSize),this._lastMaterialId=n.id}if(s.uniformMatrix4fv(this._uModelMatrix,s.FALSE,t.worldMatrix),i.combineGeometry){const n=t.vertexBufs;n.id!==this._lastVertexBufsId&&(n.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(n.positionsBuf,n.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),this._lastVertexBufsId=n.id)}this._uClippable&&s.uniform1i(this._uClippable,t._state.clippable),s.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(s.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(s.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(s.drawArrays(s.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},Ht.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new ot(s,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uShadowViewMatrix=n.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=n.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0){let e,t,i,a,r;for(let l=0,o=this._uSectionPlanes.length;l0)for(let s=0;s0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const Zt=function(){const e=h.vec3(),t=h.vec3(),s=h.vec3(),n=h.vec3(),i=h.vec3(),a=h.vec3(),r=h.vec4(),l=h.vec3(),o=h.vec3(),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3(),y=h.vec4(),m=h.vec4(),v=h.vec4(),w=h.vec3(),g=h.vec3(),T=h.vec3(),E=h.vec3(),b=h.vec3(),D=h.vec3(),P=h.vec3(),R=h.vec3(),C=h.vec3(),_=h.vec3(),O=h.vec3();return function(S,N,x,L){var M=L.primIndex;if(null!=M&&M>-1){const G=S.geometry._state,j=S.scene,V=j.camera,k=j.canvas;if("triangles"===G.primitiveName){L.primitive="triangle";const j=M,Q=G.indices,W=G.positions;let z,K,Y;if(Q){var F=Q[j+0],H=Q[j+1],U=Q[j+2];a[0]=F,a[1]=H,a[2]=U,L.indices=a,z=3*F,K=3*H,Y=3*U}else z=3*j,K=z+3,Y=K+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],n[0]=W[K+0],n[1]=W[K+1],n[2]=W[K+2],i[0]=W[Y+0],i[1]=W[Y+1],i[2]=W[Y+2],G.compressGeometry){const e=G.positionsDecodeMatrix;e&&(Pe.decompressPosition(s,e,s),Pe.decompressPosition(n,e,n),Pe.decompressPosition(i,e,i))}L.canvasPos?h.canvasPosToLocalRay(k.canvas,S.origin?B(N,S.origin):N,x,S.worldMatrix,L.canvasPos,e,t):L.origin&&L.direction&&h.worldRayToLocalRay(S.worldMatrix,L.origin,L.direction,e,t),h.normalizeVec3(t),h.rayPlaneIntersect(e,t,s,n,i,r),L.localPos=r,L.position=r,y[0]=r[0],y[1]=r[1],y[2]=r[2],y[3]=1,h.transformVec4(S.worldMatrix,y,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],L.canvasPos&&S.origin&&(l[0]+=S.origin[0],l[1]+=S.origin[1],l[2]+=S.origin[2]),L.worldPos=l,h.transformVec4(V.matrix,m,v),o[0]=v[0],o[1]=v[1],o[2]=v[2],L.viewPos=o,h.cartesianToBarycentric(r,s,n,i,c),L.bary=c;const X=G.normals;if(X){if(G.compressGeometry){const e=3*F,t=3*H,s=3*U;Pe.decompressNormal(X.subarray(e,e+2),u),Pe.decompressNormal(X.subarray(t,t+2),p),Pe.decompressNormal(X.subarray(s,s+2),A)}else u[0]=X[z],u[1]=X[z+1],u[2]=X[z+2],p[0]=X[K],p[1]=X[K+1],p[2]=X[K+2],A[0]=X[Y],A[1]=X[Y+1],A[2]=X[Y+2];const e=h.addVec3(h.addVec3(h.mulVec3Scalar(u,c[0],w),h.mulVec3Scalar(p,c[1],g),T),h.mulVec3Scalar(A,c[2],E),b);L.worldNormal=h.normalizeVec3(h.transformVec3(S.worldNormalMatrix,e,D))}const q=G.uv;if(q){if(d[0]=q[2*F],d[1]=q[2*F+1],f[0]=q[2*H],f[1]=q[2*H+1],I[0]=q[2*U],I[1]=q[2*U+1],G.compressGeometry){const e=G.uvDecodeMatrix;e&&(Pe.decompressUV(d,e,d),Pe.decompressUV(f,e,f),Pe.decompressUV(I,e,I))}L.uv=h.addVec3(h.addVec3(h.mulVec2Scalar(d,c[0],P),h.mulVec2Scalar(f,c[1],R),C),h.mulVec2Scalar(I,c[2],_),O)}}}}}();class $t extends C{get type(){return"Material"}constructor(e,t={}){super(e,t),A.memory.materials++}destroy(){super.destroy(),A.memory.materials--}}const es={opaque:0,mask:1,blend:2},ts=["opaque","mask","blend"];class ss extends $t{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new ye({type:"PhongMaterial",ambient:h.vec3([1,1,1]),diffuse:h.vec3([1,1,1]),specular:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=es[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return ts[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}function ns(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];let s;switch(t){case"WEBGL_depth_texture":s=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":s=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":s=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=e.getExtension(t)}return e._cachedExtensions[t]=s,s}function is(e,t,s=null){let n;const i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===s){const t=ns(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===i)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(n=ns(e,"WEBGL_compressed_texture_s3tc"),null===n)return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){const t=ns(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===i)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){const t=ns(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){const t=ns(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===i)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){const t=ns(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){const t=ns(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===i)return 3001===s?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}const as=new Uint8Array([0,0,0,1]);class rs{constructor({gl:e,target:t,format:s,type:n,wrapS:i,wrapT:a,wrapR:r,encoding:l,preloadColor:o,premultiplyAlpha:c,flipY:u}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=s||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!u,this.unpackAlignment=4,this.wrapS=i||1e3,this.wrapT=a||1e3,this.wrapR=r||1e3,this.encoding=l||3001,this.texture=e.createTexture(),o&&this.setPreloadColor(o),this.allocated=!0}setPreloadColor(e){e?(as[0]=Math.floor(255*e[0]),as[1]=Math.floor(255*e[1]),as[2]=Math.floor(255*e[2]),as[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(as[0]=0,as[1]=0,as[2]=0,as[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let s=0,n=e.length;s1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=is(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=is(s,this.wrapT);if(r&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,r),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=is(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}i?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,os(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,os(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,is(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,is(s,this.magFilter)));const l=is(s,this.format,this.encoding),o=is(s,this.type),c=ls(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t>t;return e+1}class ps extends C{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new ye({texture:new rs({gl:this.scene.canvas.gl}),matrix:h.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=h.vec2([0,0]),this._scale=h.vec2([1,1]),this._rotate=h.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),A.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this._state.texture=new rs({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}_update(){const e=this._state;if(this._matrixDirty){let t,s;0===this._translate[0]&&0===this._translate[1]||(t=h.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=h.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?h.mulMat4(t,s):s),0!==this._rotate&&(s=h.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?h.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=cs(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let s=new Image;s.onload=function(){s=cs(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),A.memory.textures--}}const As=h.vec3(),ds=h.vec3();h.vec3();const fs=h.vec3([0,-1,0]),Is=h.vec4([0,0,0,1]);class ys extends $t{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new ye({type:"LambertMaterial",ambient:h.vec3([1,1,1]),color:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),this.ambient=t.ambient,this.color=t.color,this.emissive=t.emissive,this.alpha=t.alpha,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this.backfaces=t.backfaces,this.frontface=t.frontface}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set color(e){let t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get color(){return this._state.color}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}get alpha(){return this._state.alpha}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}const ms={opaque:0,mask:1,blend:2},vs=["opaque","mask","blend"];class ws extends $t{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new ye({type:"MetallicMaterial",baseColor:h.vec4([1,1,1]),emissive:h.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.baseColor=t.baseColor,this.metallic=t.metallic,this.roughness=t.roughness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.baseColorMap&&(this._baseColorMap=this._checkComponent("Texture",t.baseColorMap)),t.metallicMap&&(this._metallicMap=this._checkComponent("Texture",t.metallicMap)),t.roughnessMap&&(this._roughnessMap=this._checkComponent("Texture",t.roughnessMap)),t.metallicRoughnessMap&&(this._metallicRoughnessMap=this._checkComponent("Texture",t.metallicRoughnessMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set baseColor(e){let t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get baseColor(){return this._state.baseColor}get baseColorMap(){return this._baseColorMap}set metallic(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}get metallic(){return this._state.metallic}get metallicMap(){return this._attached.metallicMap}set roughness(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}get roughness(){return this._state.roughness}get roughnessMap(){return this._attached.roughnessMap}get metallicRoughnessMap(){return this._attached.metallicRoughnessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._attached.emissiveMap}get occlusionMap(){return this._attached.occlusionMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._attached.alphaMap}get normalMap(){return this._attached.normalMap}set alphaMode(e){let t=ms[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return vs[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const gs={opaque:0,mask:1,blend:2},Ts=["opaque","mask","blend"];class Es extends $t{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new ye({type:"SpecularMaterial",diffuse:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),specular:h.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.diffuse=t.diffuse,this.specular=t.specular,this.glossiness=t.glossiness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.glossinessMap&&(this._glossinessMap=this._checkComponent("Texture",t.glossinessMap)),t.specularGlossinessMap&&(this._specularGlossinessMap=this._checkComponent("Texture",t.specularGlossinessMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}get diffuseMap(){return this._diffuseMap}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}get specularMap(){return this._specularMap}get specularGlossinessMap(){return this._specularGlossinessMap}set glossiness(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}get glossiness(){return this._state.glossiness}get glossinessMap(){return this._glossinessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._emissiveMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._alphaMap}get normalMap(){return this._normalMap}get occlusionMap(){return this._occlusionMap}set alphaMode(e){let t=gs[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Ts[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const bs={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class Ds extends $t{get type(){return"EmphasisMaterial"}get presets(){return bs}constructor(e,t={}){super(e,t),this._state=new ye({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(e=e||"default",this._preset===e)return;const t=bs[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(bs).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Ps={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class Rs extends $t{get type(){return"EdgeMaterial"}get presets(){return Ps}constructor(e,t={}){super(e,t),this._state=new ye({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Ps[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ps).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class Cs extends C{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=h.vec3(t.pos||[0,0,0]),this._up=h.vec3(t.up||[0,1,0]),this._normal=h.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=h.vec3(),this._rtcPos=h.vec3(),this._imageSize=h.vec2(),this._texture=new ps(this),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new Je(this,{matrix:h.inverseMat4(h.lookAtMat4v(this._pos,h.subVec3(this._pos,this._normal,h.mat4()),this._up,h.mat4())),children:[this._bitmapMesh=new Jt(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new _e(this,Fe({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new ss(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}class _s extends C{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],this._origin=h.vec3(t.origin||[0,0,0]),t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=n.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new ye({type:"dir",dir:h.vec3([1,1,1]),color:h.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=h.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,n=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],i=[0,1,0];h.lookAtMat4v(n,s,i,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=h.identityMat4()),h.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new Ss(this.scene.canvas.canvas,this.scene.canvas.gl,{size:[1024,1024]})),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function xs(e){if(!Ls(e.width)||!Ls(e.height)){const t=document.createElement("canvas");t.width=Ms(e.width),t.height=Ms(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Ls(e){return 0==(e&e-1)}function Ms(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Fs extends C{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new ye({texture:new rs({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),A.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let a=0;a=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class Vs{constructor(){this.planes=[new js,new js,new js,new js,new js,new js]}}function ks(e,t,s){const n=h.mulMat4(s,t,Gs),i=n[0],a=n[1],r=n[2],l=n[3],o=n[4],c=n[5],u=n[6],p=n[7],A=n[8],d=n[9],f=n[10],I=n[11],y=n[12],m=n[13],v=n[14],w=n[15];e.planes[0].set(l-i,p-o,I-A,w-y),e.planes[1].set(l+i,p+o,I+A,w+y),e.planes[2].set(l-a,p-c,I-d,w-m),e.planes[3].set(l+a,p+c,I+d,w+m),e.planes[4].set(l-r,p-u,I-f,w-v),e.planes[5].set(l+r,p+u,I+f,w+v)}function Qs(e,t){let s=Vs.INSIDE;const n=Hs,i=Us;n[0]=t[0],n[1]=t[1],n[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];const a=[n,i];for(let t=0;t<6;++t){const n=e.planes[t];if(n.normal[0]*a[n.testVertex[0]][0]+n.normal[1]*a[n.testVertex[1]][1]+n.normal[2]*a[n.testVertex[2]][2]+n.offset<0)return Vs.OUTSIDE;n.normal[0]*a[1-n.testVertex[0]][0]+n.normal[1]*a[1-n.testVertex[1]][1]+n.normal[2]*a[1-n.testVertex[2]][2]+n.offset<0&&(s=Vs.INTERSECT)}return s}Vs.INSIDE=0,Vs.INTERSECT=1,Vs.OUTSIDE=2;class Ws{constructor(e){this._eye=h.vec3(),this._look=h.vec3(),this._up=h.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,s=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,n=this._projection;function i(){switch(n.type){case"perspective":s.perspective.fov=n.fov,s.perspective.fovAxis=n.fovAxis,s.perspective.near=n.near,s.perspective.far=n.far;break;case"ortho":s.ortho.scale=n.scale,s.ortho.near=n.near,s.ortho.far=n.far;break;case"frustum":s.frustum.left=n.left,s.frustum.right=n.right,s.frustum.top=n.top,s.frustum.bottom=n.bottom,s.frustum.near=n.near,s.frustum.far=n.far;break;case"custom":s.customProjection.matrix=n.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:n.scale,projection:n.projection},(()=>{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const zs=h.vec3();const Ks=h.vec3();class Ys{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?y.apply(t,{}):null;const s=e.objects,n=!t||t.visible,i=!t||t.edges,a=!t||t.xrayed,r=!t||t.highlighted,l=!t||t.selected,o=!t||t.clippable,c=!t||t.pickable,u=!t||t.colorize,h=!t||t.opacity;for(let e in s)if(s.hasOwnProperty(e)){const t=s[e],p=this.numObjects;if(n&&(this.objectsVisible[p]=t.visible),i&&(this.objectsEdges[p]=t.edges),a&&(this.objectsXrayed[p]=t.xrayed),r&&(this.objectsHighlighted[p]=t.highlighted),l&&(this.objectsSelected[p]=t.selected),o&&(this.objectsClippable[p]=t.clippable),c&&(this.objectsPickable[p]=t.pickable),u){const e=t.colorize;e?(this.objectsColorize[3*p+0]=e[0],this.objectsColorize[3*p+1]=e[1],this.objectsColorize[3*p+2]=e[2],this.objectsHasColorize[p]=!0):this.objectsHasColorize[p]=!1}h&&(this.objectsOpacity[p]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,s=!t||t.visible,n=!t||t.edges,i=!t||t.xrayed,a=!t||t.highlighted,r=!t||t.selected,l=!t||t.clippable,o=!t||t.pickable,c=!t||t.colorize,u=!t||t.opacity;var h=0;const p=e.objects;for(let e in p)if(p.hasOwnProperty(e)){const t=p[e];s&&(t.visible=this.objectsVisible[h]),n&&(t.edges=this.objectsEdges[h]),i&&(t.xrayed=this.objectsXrayed[h]),a&&(t.highlighted=this.objectsHighlighted[h]),r&&(t.selected=this.objectsSelected[h]),l&&(t.clippable=this.objectsClippable[h]),o&&(t.pickable=this.objectsPickable[h]),c&&(this.objectsHasColorize[h]?(Ks[0]=this.objectsColorize[3*h+0],Ks[1]=this.objectsColorize[3*h+1],Ks[2]=this.objectsColorize[3*h+2],t.colorize=Ks):t.colorize=null),u&&(t.opacity=this.objectsOpacity[h]),h++}}}class Xs{constructor(e,t,s,n,i=null,a=0){this.model=e,this.object=null,this.parent=null,this.id=t,this._aabb=null,this.layer=i,this.portionId=a,this._color=[s[0],s[1],s[2],n],this._colorize=[s[0],s[1],s[2],n],this._colorizing=!1,this._transparent=n<255,this.numTriangles=0,this.origin=null}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const s=e<255,n=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),n&&this.layer.setTransparent(this.portionId,t,s)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,s,n){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,s,n)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex(this.portionId,e)}set aabb(e){this._aabb=e}get aabb(){return this._aabb}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const qs=new class{constructor(){this._uint8Arrays={},this._float32Arrays={}}_clear(){this._uint8Arrays={},this._float32Arrays={}}getUInt8Array(e){let t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}getFloat32Array(e){let t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}};let Js=0;const Zs={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},$s=new Float32Array([1,1,1,1]),en=new Float32Array([0,0,0,1]),tn=h.vec4(),sn=h.vec3(),nn=h.vec3(),an=h.mat4();class rn{constructor(e,t=!1,{instancing:s=!1,edges:n=!1}={}){this._scene=e,this._withSAO=t,this._instancing=s,this._edges=n,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}_getHash(){return this._scene._sectionPlanesState.getHash()}_buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}_buildVertexShader(){return[""]}_buildFragmentShader(){return[""]}_addMatricesUniformBlockLines(e,t=!1){return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}_addRemapClipPosLines(e){return e.push("uniform vec2 pickClipPos;"),e.push("vec4 remapClipPos(vec4 clipPos) {"),e.push(" clipPos.xy /= clipPos.w;"),e.push(" clipPos.xy -= pickClipPos;"),e.push(" clipPos.xy *= clipPos.w;"),e.push(" return clipPos;"),e.push("}"),e}getValid(){return this._hash===this._getHash()}setSectionPlanesStateUniforms(e){const t=this._scene,{gl:s}=t.canvas,{model:n,layerIndex:i}=e,a=t._sectionPlanesState.sectionPlanes.length;if(a>0){const r=t._sectionPlanesState.sectionPlanes,l=i*a,o=n.renderFlags;for(let t=0;t0&&(this._uReflectionMap="reflectionMap"),s.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(let t=0,s=e._sectionPlanesState.sectionPlanes.length;t0&&d.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,d.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),d.lightMaps.length>0&&d.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,d.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),this._withSAO){const t=r.sao;if(t.possible){const s=l.drawingBufferWidth,n=l.drawingBufferHeight;tn[0]=s,tn[1]=n,tn[2]=t.blendCutoff,tn[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,tn),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++}}if(n){const e=this._edges?"edgeColor":"fillColor",t=this._edges?"edgeAlpha":"fillAlpha";if(s===Zs[(this._edges?"EDGES":"SILHOUETTE")+"_XRAYED"]){const s=r.xrayMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===Zs[(this._edges?"EDGES":"SILHOUETTE")+"_HIGHLIGHTED"]){const s=r.highlightMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===Zs[(this._edges?"EDGES":"SILHOUETTE")+"_SELECTED"]){const s=r.selectedMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else l.uniform4fv(this._uColor,this._edges?en:$s)}this._draw({state:o,frameCtx:e,incrementDrawState:i}),l.bindVertexArray(null)}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null,A.memory.programs--}}class ln extends rn{constructor(e,t,{instancing:s=!1,edges:n=!1}={}){super(e,t,{instancing:s,edges:n})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;if(this._edges)t.drawElements(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0);else{const e=n.pickElementsCount||s.indicesBuf.numItems,a=n.pickElementsOffset?n.pickElementsOffset*s.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,e,s.indicesBuf.itemType,a),i&&n.drawElements++}}}class on extends ln{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class cn extends rn{constructor(e,t,{edges:s=!1}={}){super(e,t,{instancing:!0,edges:s})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;this._edges?t.drawElementsInstanced(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances):(t.drawElementsInstanced(t.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++)}}class un extends cn{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class hn extends rn{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArrays(t.POINTS,0,s.positionsBuf.numItems),i&&n.drawArrays++}}class pn extends rn{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArraysInstanced(t.POINTS,0,s.positionsBuf.numItems,s.numInstances),i&&n.drawArrays++}}class An extends rn{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElements(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0),i&&n.drawElements++}}class dn extends rn{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElementsInstanced(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++}}class fn extends ln{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i;const a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class In extends ln{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching flat-shading draw vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._lightsState,s=e._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),n){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,s=t.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}class mn extends on{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class vn extends on{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class wn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),this._addRemapClipPosLines(s),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class gn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),this._addRemapClipPosLines(s),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Tn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec3 worldNormal = octDecode(normal.xy); "),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}}class En extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching occlusion fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}class bn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching depth fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}class Dn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Pn extends ln{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry shadow vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push(" int colorFlag = int(flags) & 0xF;"),s.push(" bool visible = (colorFlag > 0);"),s.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push(" if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry shadow fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = encodeFloat( gl_FragCoord.z); "),s.push("}"),s}}class Rn extends ln{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Triangles batching quality draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),r.push("uniform sampler2D uAOMap;"),r.push("in vec4 vViewPosition;"),r.push("in vec3 vViewNormal;"),r.push("in vec4 vColor;"),r.push("in vec2 vUV;"),r.push("in vec2 vMetallicRoughness;"),n.lightMaps.length>0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick flat normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out float vFlags;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags = flags;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick flat normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}}class _n extends ln{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching color texture vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._lightsState,n=e._sectionPlanesState,i=n.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(let e=0,t=n.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(let e=0,t=n.sectionPlanes.length;e 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,t=s.lights.length;e5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]}}const Nn=h.mat4(),xn=h.mat4();function Ln(e,t,s){const n=e.length,i=new Uint16Array(n),a=t[0],r=t[1],l=t[2],o=t[3]-a,c=t[4]-r,u=t[5]-l,p=65525,A=p/o,d=p/c,f=p/u,I=e=>e>=0?e:0;for(let t=0;t=0?1:-1),t=(1-Math.abs(n))*(i>=0?1:-1),n=e,i=t}return new Int8Array([Math[t](127.5*n+(n<0?-1:0)),Math[s](127.5*i+(i<0?-1:0))])}function Hn(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}const Un=h.vec3(),Gn=h.vec3(),jn=h.vec3(),Vn=h.vec3(),kn=h.mat4();class Qn extends rn{drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:p}=n,A=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Un;let I,y;if(f[0]=h.safeInv(A[3]-A[0])*h.MAX_INT,f[1]=h.safeInv(A[4]-A[1])*h.MAX_INT,f[2]=h.safeInv(A[5]-A[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(f[0]),e.snapPickCoordinateScale[1]=h.safeInv(f[1]),e.snapPickCoordinateScale[2]=h.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=Gn;if(o){const e=jn;h.transformPoint3(u,o,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=B(d,t,kn),y=Vn,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(p,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),l.indicesBuf.bind(),r.drawElements(r.TRIANGLES,l.indicesBuf.numItems,l.indicesBuf.itemType,0),l.indicesBuf.unbind()}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Wn=h.vec3(),zn=h.vec3(),Kn=h.vec3(),Yn=h.vec3(),Xn=h.mat4();class qn extends rn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:p}=n,A=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Wn;let I,y;if(f[0]=h.safeInv(A[3]-A[0])*h.MAX_INT,f[1]=h.safeInv(A[4]-A[1])*h.MAX_INT,f[2]=h.safeInv(A[5]-A[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(f[0]),e.snapPickCoordinateScale[1]=h.safeInv(f[1]),e.snapPickCoordinateScale[2]=h.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=zn;if(o){const e=Kn;h.transformPoint3(u,o,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=B(d,t,Xn),y=Yn,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(p,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(l.edgeIndicesBuf.bind(),r.drawElements(r.LINES,l.edgeIndicesBuf.numItems,l.edgeIndicesBuf.itemType,0),l.edgeIndicesBuf.unbind()):r.drawArrays(r.POINTS,0,l.positionsBuf.numItems)}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0;e.pointsMaterial._state;const s=[];return s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class Jn{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Qn(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new qn(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Zn={};const $n=h.mat4(),ei=h.mat4(),ti=h.vec4([0,0,0,1]),si=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]),h.OBB3();const ni=h.vec3(),ii=h.vec3(),ai=h.vec3(),ri=h.vec3(),li=h.vec3(),oi=h.vec3(),ci=h.vec3();class ui{constructor(e){console.info("Creating TrianglesBatchingLayer"),this.model=e.model,this.sortId="TrianglesBatchingLayer"+(e.solid?"-solid":"-surface")+(e.autoNormals?"-autonormals":"-normals")+(e.textureSet&&e.textureSet.colorTexture?"-colorTexture":"")+(e.textureSet&&e.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=On[t];return s||(s=new Bn(e),On[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete On[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=Zn[t];return s||(s=new Jn(e),Zn[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Zn[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Sn(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ye({origin:h.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:e.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=h.mat4(e.positionsDecodeMatrix)),e.uvDecodeMatrix?(this._state.uvDecodeMatrix=h.mat3(e.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,e.origin&&this._state.origin.set(e.origin),this.aabb=h.collapseAABB3(),this.solid=!!e.solid}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(let e=0,t=i.length;e0){const e=$n;I?h.inverseMat4(h.transposeMat4(I,ei),e):h.identityMat4(e,e),function(e,t,s,n,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let r,l,o,c,u,p,A=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(p=0;pu&&(o=r,u=c),r=Fn(d,"floor","ceil"),l=Hn(r),c=a(d,l),c>u&&(o=r,u=c),r=Fn(d,"ceil","ceil"),l=Hn(r),c=a(d,l),c>u&&(o=r,u=c),n[i+p+0]=o[0],n[i+p+1]=o[1],n[i+p+2]=0}(e,n,n.length,w.normals,w.normals.length)}if(l)for(let e=0,t=l.length;e0)for(let e=0,t=a.length;e0)for(let e=0,t=r.length;e0){const n=this._state.positionsDecodeMatrix?new Uint16Array(s.positions):Ln(s.positions,this._modelAABB,this._state.positionsDecodeMatrix=h.mat4());if(e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(let e=0,t=this._portions.length;e0){const n=new Int8Array(s.normals);let i=!0;e.normalsBuf=new me(t,t.ARRAY_BUFFER,n,s.normals.length,3,t.STATIC_DRAW,i)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new me(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.uv.length>0)if(e.uvDecodeMatrix){let n=!1;e.uvBuf=new me(t,t.ARRAY_BUFFER,s.uv,s.uv.length,2,t.STATIC_DRAW,n)}else{const n=Pe.getUVBounds(s.uv),i=Pe.compressUVs(s.uv,n.min,n.max),a=i.quantized;let r=!1;e.uvDecodeMatrix=h.mat3(i.decodeMatrix),e.uvBuf=new me(t,t.ARRAY_BUFFER,a,a.length,2,t.STATIC_DRAW,r)}if(s.metallicRoughness.length>0){const n=new Uint8Array(s.metallicRoughness);let i=!1;e.metallicRoughnessBuf=new me(t,t.ARRAY_BUFFER,n,s.metallicRoughness.length,2,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n),a=!1;e.flagsBuf=new me(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new me(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new me(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}if(s.edgeIndices.length>0){const n=new Uint32Array(s.edgeIndices);e.edgeIndicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,n,s.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}isEmpty(){return!this._state.indicesBuf}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=e,n=this._portions[s],i=4*n.vertsBaseIndex,a=4*n.numVerts,r=this._scratchMemory.getUInt8Array(a),l=t[0],o=t[1],c=t[2],u=t[3];for(let e=0;em)&&(m=e,n.set(v),i&&h.triangleNormal(d,f,I,i),y=!0)}}return y&&i&&(h.transformVec3(this.model.worldNormalMatrix,i,i),h.normalizeVec3(i)),y}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}class hi extends cn{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i,a,r;const l=[];for(l.push("#version 300 es"),l.push("// Instancing geometry drawing vertex shader"),l.push("uniform int renderPass;"),l.push("in vec3 position;"),l.push("in vec2 normal;"),l.push("in vec4 color;"),l.push("in float flags;"),e.entityOffsetsEnabled&&l.push("in vec3 offset;"),l.push("in vec4 modelMatrixCol0;"),l.push("in vec4 modelMatrixCol1;"),l.push("in vec4 modelMatrixCol2;"),l.push("in vec4 modelNormalMatrixCol0;"),l.push("in vec4 modelNormalMatrixCol1;"),l.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(l,!0),e.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;")),l.push("uniform vec4 lightAmbient;"),i=0,a=s.lights.length;i= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"),n&&(l.push("out vec4 vWorldPosition;"),l.push("out float vFlags;")),l.push("out vec4 vColor;"),l.push("void main(void) {"),l.push("int colorFlag = int(flags) & 0xF;"),l.push("if (colorFlag != renderPass) {"),l.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),l.push("} else {"),l.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),l.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix * worldPosition; "),l.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),l.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),l.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),i=0,a=s.lights.length;i0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class pi extends cn{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState;let n,i;const a=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry flat-shading drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),a){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}for(r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),n=0,i=s.lights.length;n0,s=[];return s.push("#version 300 es"),s.push("// Instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing fill fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class di extends un{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class fi extends un{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Ii extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class yi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class mi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec2 normal;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("in vec4 modelNormalMatrixCol0;"),s.push("in vec4 modelNormalMatrixCol1;"),s.push("in vec4 modelNormalMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}}class vi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// TrianglesInstancingOcclusionRenderer vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesInstancingOcclusionRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}class wi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}class gi extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Ti extends cn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}const Ei={3e3:"linearToLinear",3001:"sRGBToLinear"};class bi extends cn{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Instancing geometry quality drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),r.push("#define PI 3.14159265359"),r.push("#define RECIPROCAL_PI 0.31830988618"),r.push("#define RECIPROCAL_PI2 0.15915494"),r.push("#define EPSILON 1e-6"),r.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),r.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),r.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),r.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),r.push(" return normalize(surf_norm );"),r.push(" }"),r.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),r.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),r.push(" vec2 st0 = dFdx( uv.st );"),r.push(" vec2 st1 = dFdy( uv.st );"),r.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),r.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),r.push(" vec3 N = normalize( surf_norm );"),r.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),r.push(" mat3 tsn = mat3( S, T, N );"),r.push(" return normalize( tsn * mapN );"),r.push("}"),r.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),r.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),r.push("}"),r.push("struct IncidentLight {"),r.push(" vec3 color;"),r.push(" vec3 direction;"),r.push("};"),r.push("struct ReflectedLight {"),r.push(" vec3 diffuse;"),r.push(" vec3 specular;"),r.push("};"),r.push("struct Geometry {"),r.push(" vec3 position;"),r.push(" vec3 viewNormal;"),r.push(" vec3 worldNormal;"),r.push(" vec3 viewEyeDir;"),r.push("};"),r.push("struct Material {"),r.push(" vec3 diffuseColor;"),r.push(" float specularRoughness;"),r.push(" vec3 specularColor;"),r.push(" float shine;"),r.push("};"),r.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),r.push(" float r = ggxRoughness + 0.0001;"),r.push(" return (2.0 / (r * r) - 2.0);"),r.push("}"),r.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),r.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),r.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),r.push("}"),n.reflectionMaps.length>0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = "+Ei[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = "+Ei[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&s.push("out float vFlags;"),s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&s.push("vFlags = flags;"),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}}class Pi extends cn{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState;let i,a;const r=s.sectionPlanes.length>0,l=[];if(l.push("#version 300 es"),l.push("// Instancing geometry drawing fragment shader"),l.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),l.push("precision highp float;"),l.push("precision highp int;"),l.push("#else"),l.push("precision mediump float;"),l.push("precision mediump int;"),l.push("#endif"),e.logarithmicDepthBufferEnabled&&(l.push("in float isPerspective;"),l.push("uniform float logDepthBufFC;"),l.push("in float vFragDepth;")),l.push("uniform sampler2D uColorMap;"),this._withSAO&&(l.push("uniform sampler2D uOcclusionTexture;"),l.push("uniform vec4 uSAOParams;"),l.push("const float packUpscale = 256. / 255.;"),l.push("const float unpackDownScale = 255. / 256.;"),l.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),l.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),l.push("float unpackRGBToFloat( const in vec4 v ) {"),l.push(" return dot( v, unPackFactors );"),l.push("}")),l.push("uniform float gammaFactor;"),l.push("vec4 linearToLinear( in vec4 value ) {"),l.push(" return value;"),l.push("}"),l.push("vec4 sRGBToLinear( in vec4 value ) {"),l.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),l.push("}"),l.push("vec4 gammaToLinear( in vec4 value) {"),l.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),l.push("}"),t&&(l.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),l.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),l.push("}")),r){l.push("in vec4 vWorldPosition;"),l.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),l.push(" if (clippable) {"),l.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),l.push(" discard;"),l.push(" }"),l.push("}")}for(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),l.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),l.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),l.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),i=0,a=n.lights.length;i0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Li=h.vec3(),Mi=h.vec3(),Fi=h.vec3(),Hi=h.vec3(),Ui=h.mat4();class Gi extends rn{constructor(e){super(e,!1,{instancing:!0})}drawLayer(e,t,s){if(!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:p}=n,A=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Li;let I,y;if(f[0]=h.safeInv(A[3]-A[0])*h.MAX_INT,f[1]=h.safeInv(A[4]-A[1])*h.MAX_INT,f[2]=h.safeInv(A[5]-A[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(f[0]),e.snapPickCoordinateScale[1]=h.safeInv(f[1]),e.snapPickCoordinateScale[2]=h.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=Mi;if(o){const e=h.transformPoint3(u,o,Fi);t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=B(d,t,Ui),y=Hi,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(p,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(l.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(l.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(l.modelMatrixCol2Buf),r.vertexAttribDivisor(this._aModelMatrixCol0.location,1),r.vertexAttribDivisor(this._aModelMatrixCol1.location,1),r.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(l.flagsBuf),r.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(l.edgeIndicesBuf.bind(),r.drawElementsInstanced(r.LINES,l.edgeIndicesBuf.numItems,l.edgeIndicesBuf.itemType,0,l.numInstances),l.edgeIndicesBuf.unbind()):r.drawArraysInstanced(r.POINTS,0,l.positionsBuf.numItems,l.numInstances),r.vertexAttribDivisor(this._aModelMatrixCol0.location,0),r.vertexAttribDivisor(this._aModelMatrixCol1.location,0),r.vertexAttribDivisor(this._aModelMatrixCol2.location,0),r.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&r.vertexAttribDivisor(this._aOffset.location,0)}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class ji{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new xi(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Gi(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Vi={};const ki=new Uint8Array(4),Qi=new Float32Array(1),Wi=h.vec4([0,0,0,1]),zi=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]);const Ki=new Float32Array(3),Yi=h.vec3(),Xi=h.vec3(),qi=h.vec3(),Ji=h.vec3(),Zi=h.vec3(),$i=h.vec3(),ea=h.vec3();class ta{constructor(e){console.info("Creating TrianglesInstancingLayer"),this.model=e.model,this.sortId="TrianglesInstancingLayer"+(e.solid?"-solid":"-surface")+(e.normals?"-normals":"-autoNormals"),this.layerIndex=e.layerIndex,this._instancingRenderers=function(e){const t=e.id;let s=Ci[t];return s||(s=new Ri(e),Ci[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Ci[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=Vi[t];return s||(s=new ji(e),Vi[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Vi[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new ye({numInstances:0,obb:h.OBB3(),origin:h.vec3(),geometry:e.geometry,textureSet:e.textureSet,pbrSupported:!1,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],e.origin&&this._state.origin.set(e.origin),this._finalized=!1,this.aabb=h.collapseAABB3(),this.solid=!!e.solid,this.numIndices=e.geometry.numIndices}createPortion(e){const t=e.color,s=e.metallic,n=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,r=e.aabb,l=e.pickColor;if(this._finalized)throw"Already finalized";const o=t[0],c=t[1],u=t[2];if(this._colors.push(o),this._colors.push(c),this._colors.push(u),this._colors.push(i),this._metallicRoughness.push(null!=s?s:0),this._metallicRoughness.push(null!=n?n:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){let e=h.transposeMat4(a,h.mat4()),t=h.inverseMat4(e);this._modelNormalMatrixCol0.push(t[0]),this._modelNormalMatrixCol0.push(t[4]),this._modelNormalMatrixCol0.push(t[8]),this._modelNormalMatrixCol0.push(t[12]),this._modelNormalMatrixCol1.push(t[1]),this._modelNormalMatrixCol1.push(t[5]),this._modelNormalMatrixCol1.push(t[9]),this._modelNormalMatrixCol1.push(t[13]),this._modelNormalMatrixCol2.push(t[2]),this._modelNormalMatrixCol2.push(t[6]),this._modelNormalMatrixCol2.push(t[10]),this._modelNormalMatrixCol2.push(t[14])}this._pickColors.push(l[0]),this._pickColors.push(l[1]),this._pickColors.push(l[2]),this._pickColors.push(l[3]);const p=this._state.geometry.positionsCompressed.length,A=this._state.geometry.positionsCompressed,d=this._state.geometry.positionsDecodeMatrix;for(let e=0;e0){let t=!1;e.colorsBuf=new me(n,n.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,n.DYNAMIC_DRAW,t),this._colors=[]}if(this._metallicRoughness.length>0){const t=new Uint8Array(this._metallicRoughness);let s=!1;e.metallicRoughnessBuf=new me(n,n.ARRAY_BUFFER,t,this._metallicRoughness.length,2,n.STATIC_DRAW,s)}if(a>0){let t=!1;e.flagsBuf=new me(n,n.ARRAY_BUFFER,new Float32Array(a),a,1,n.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;e.offsetsBuf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,n.DYNAMIC_DRAW,t),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){const s=!1;e.positionsBuf=new me(n,n.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,n.STATIC_DRAW,s),e.positionsDecodeMatrix=h.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){const s=new Uint8Array(t.colorsCompressed),i=!1;e.colorsBuf=new me(n,n.ARRAY_BUFFER,s,s.length,4,n.STATIC_DRAW,i)}if(t.uvCompressed&&t.uvCompressed.length>0){const s=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new me(n,n.ARRAY_BUFFER,s,s.length,2,n.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new me(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,n.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new me(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,n.STATIC_DRAW)),this._modelMatrixCol0.length>0){const t=!1;e.modelMatrixCol0Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelMatrixCol1Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelMatrixCol2Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol1Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol2Buf=new me(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){const t=!1;e.pickColorsBuf=new me(n,n.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,n.STATIC_DRAW,t),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&s&&s.colorTexture&&s.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!s&&!!s.colorTexture,this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";ki[0]=t[0],ki[1]=t[1],ki[2]=t[2],ki[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(ki,4*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&j),l=!!(t&V),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Zs.NOT_RENDERED:s?Zs.COLOR_TRANSPARENT:Zs.COLOR_OPAQUE,h=!n||c?Zs.NOT_RENDERED:r?Zs.SILHOUETTE_SELECTED:a?Zs.SILHOUETTE_HIGHLIGHTED:i?Zs.SILHOUETTE_XRAYED:Zs.NOT_RENDERED;let p=0;p=!n||c?Zs.NOT_RENDERED:r?Zs.EDGES_SELECTED:a?Zs.EDGES_HIGHLIGHTED:i?Zs.EDGES_XRAYED:l?s?Zs.EDGES_COLOR_TRANSPARENT:Zs.EDGES_COLOR_OPAQUE:Zs.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Zs.PICK:Zs.NOT_RENDERED)<<12,A|=(t&F?1:0)<<16,Qi[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Qi,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ki[0]=t[0],Ki[1]=t[1],Ki[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Ki,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}getEachVertex(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;const s=this._state,n=s.geometry,i=this._portions[e];if(!i)return void this.model.error("portion not found: "+e);const a=n.quantizedPositions,r=s.origin,l=i.offset,o=r[0]+l[0],c=r[1]+l[1],u=r[2]+l[2],p=Wi,A=i.matrix,d=this.model.sceneModelMatrix,f=s.positionsDecodeMatrix;for(let e=0,s=a.length;ev)&&(v=e,n.set(w),i&&h.triangleNormal(f,I,y,i),m=!0)}}return m&&i&&(h.transformVec3(l.normalMatrix,i,i),h.transformVec3(this.model.worldNormalMatrix,i,i),h.normalizeVec3(i)),m}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}class sa extends An{drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class na extends An{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class ia{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new sa(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new na(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const aa={};class ra{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const la=h.vec4([0,0,0,1]),oa=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]),h.OBB3();class ca{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=aa[t];return s||(s=new ia(e),aa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete aa[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new ra(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ye({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:h.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=h.vec3(e.origin)),this.aabb=h.collapseAABB3()}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Ln(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new me(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.colors.length>0){const n=s.colors.length/4,i=new Float32Array(n);let a=!1;e.flagsBuf=new me(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new me(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new me(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2],c=t[3];for(let e=0;e0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 lightAmbient;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class ha extends dn{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 color;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class pa{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new ua(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ha(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Aa={};const da=new Uint8Array(4),fa=new Float32Array(1),Ia=h.vec4([0,0,0,1]),ya=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]);const ma=new Float32Array(3);class va{constructor(e){this.model=e.model,this.material=e.material,this.sortId="LinesInstancingLayer",this.layerIndex=e.layerIndex,this._linesInstancingRenderers=function(e){const t=e.id;let s=Aa[t];return s||(s=new pa(e),Aa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Aa[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new ye({obb:h.OBB3(),numInstances:0,origin:null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],e.origin&&(this._state.origin=h.vec3(e.origin)),this._finalized=!1,this.aabb=h.collapseAABB3()}createPortion(e){const t=e.color,s=e.opacity,n=e.meshMatrix,i=e.aabb;if(this._finalized)throw"Already finalized";const a=t[0],r=t[1],l=t[2];t[3],this._colors.push(a),this._colors.push(r),this._colors.push(l),this._colors.push(s),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(n[0]),this._modelMatrixCol0.push(n[4]),this._modelMatrixCol0.push(n[8]),this._modelMatrixCol0.push(n[12]),this._modelMatrixCol1.push(n[1]),this._modelMatrixCol1.push(n[5]),this._modelMatrixCol1.push(n[9]),this._modelMatrixCol1.push(n[13]),this._modelMatrixCol2.push(n[2]),this._modelMatrixCol2.push(n[6]),this._modelMatrixCol2.push(n[10]),this._modelMatrixCol2.push(n[14]),h.collapseAABB3(i);const o=this._state.obb,c=o.length;for(let e=0;e0){let t=!1;this._state.colorsBuf=new me(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,t),this._colors=[]}if(s>0){let t=!1;this._state.flagsBuf=new me(e,e.ARRAY_BUFFER,new Float32Array(s),s,1,e.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";da[0]=t[0],da[1]=t[1],da[2]=t[2],da[3]=t[3],this._state.colorsBuf.setData(da,4*e,4)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&j),l=!!(t&V),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Zs.NOT_RENDERED:s?Zs.COLOR_TRANSPARENT:Zs.COLOR_OPAQUE,h=!n||c?Zs.NOT_RENDERED:r?Zs.SILHOUETTE_SELECTED:a?Zs.SILHOUETTE_HIGHLIGHTED:i?Zs.SILHOUETTE_XRAYED:Zs.NOT_RENDERED;let p=0;p=!n||c?Zs.NOT_RENDERED:r?Zs.EDGES_SELECTED:a?Zs.EDGES_HIGHLIGHTED:i?Zs.EDGES_XRAYED:l?s?Zs.EDGES_COLOR_TRANSPARENT:Zs.EDGES_COLOR_OPAQUE:Zs.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Zs.PICK:Zs.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,fa[0]=A,this._state.flagsBuf.setData(fa,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(ma[0]=t[0],ma[1]=t[1],ma[2]=t[2],this._state.offsetsBuf.setData(ma,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesXRayed(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawOcclusion(e,t){}drawShadow(e,t){}drawPickMesh(e,t){}drawPickDepths(e,t){}drawPickNormals(e,t){}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}class wa extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial,n=[];return n.push("#version 300 es"),n.push("// Points batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class ga extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}class Ta extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = remapClipPos(clipPos);"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class Ea extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batched pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = remapClipPos(clipPos);"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batched pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class ba extends hn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push(" gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class Da{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new wa(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ga(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Ta(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Ea(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new ba(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const Pa={};class Ra{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]}}const Ca=h.vec4(),_a=h.vec4(),Ba=h.vec4([0,0,0,1]),Oa=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]),h.OBB3();class Sa{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=Pa[t];return s||(s=new Da(e),Pa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Pa[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Ra(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ye({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:h.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=h.vec3(e.origin)),this.aabb=h.collapseAABB3()}canCreatePortion(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}createPortion(e){if(this._finalized)throw"Already finalized";const t=e.positions,s=e.positionsCompressed,n=e.color,i=e.colorsCompressed,a=e.colors,r=e.meshMatrix,l=e.worldAABB,o=e.pickColor,c=this._buffer,u=c.positions.length/3;let p;if(this._preCompressedPositionsExpected){if(!s)throw"positionsCompressed expected";for(let e=0,t=s.length;e0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Ln(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new me(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new me(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n);let a=!1;e.flagsBuf=new me(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new me(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new me(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized"}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2];for(let e=0;e0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class xa extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 silhouetteColor;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class La extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick mesh fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class Ma extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = remapClipPos(clipPos);"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Fa extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Ha extends pn{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class Ua extends pn{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("gl_PointSize = pointSize;"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }"),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Ga{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Na(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new xa(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Ha(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new La(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Ma(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Fa(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new Ua(this._scene)),this._shadowRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}const ja={};const Va=new Uint8Array(4),ka=new Float32Array(1),Qa=h.vec4([0,0,0,1]),Wa=h.vec4([0,0,0,1]);h.vec4([0,0,0,1]);const za=new Float32Array(3);class Ka{constructor(e){this.model=e.model,this.material=e.material,this.sortId="PointsInstancingLayer",this.layerIndex=e.layerIndex,this._pointsInstancingRenderers=function(e){const t=e.id;let s=ja[t];return s||(s=new Ga(e),ja[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete ja[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new ye({obb:h.OBB3(),numInstances:0,origin:e.origin?h.vec3(e.origin):null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=h.collapseAABB3()}createPortion(e){const t=e.meshMatrix,s=e.aabb,n=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(n[0]),this._pickColors.push(n[1]),this._pickColors.push(n[2]),this._pickColors.push(n[3]),h.collapseAABB3(s);const i=this._state.obb,a=i.length;for(let e=0;e0){let n=!1;s.flagsBuf=new me(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,n)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;s.offsetsBuf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(n.positionsCompressed&&n.positionsCompressed.length>0){const t=!1;s.positionsBuf=new me(e,e.ARRAY_BUFFER,n.positionsCompressed,n.positionsCompressed.length,3,e.STATIC_DRAW,t),s.positionsDecodeMatrix=h.mat4(n.positionsDecodeMatrix)}if(n.colorsCompressed&&n.colorsCompressed.length>0){const t=new Uint8Array(n.colorsCompressed),i=!1;s.colorsBuf=new me(e,e.ARRAY_BUFFER,t,t.length,4,e.STATIC_DRAW,i)}if(this._modelMatrixCol0.length>0){const t=!1;s.modelMatrixCol0Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),s.modelMatrixCol1Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),s.modelMatrixCol2Buf=new me(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){const t=!1;s.pickColorsBuf=new me(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,t),this._pickColors=[]}s.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Va[0]=t[0],Va[1]=t[1],Va[2]=t[2],this._state.colorsBuf.setData(Va,3*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&j),l=!!(t&V),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Zs.NOT_RENDERED:s?Zs.COLOR_TRANSPARENT:Zs.COLOR_OPAQUE,h=!n||c?Zs.NOT_RENDERED:r?Zs.SILHOUETTE_SELECTED:a?Zs.SILHOUETTE_HIGHLIGHTED:i?Zs.SILHOUETTE_XRAYED:Zs.NOT_RENDERED;let p=0;p=!n||c?Zs.NOT_RENDERED:r?Zs.EDGES_SELECTED:a?Zs.EDGES_HIGHLIGHTED:i?Zs.EDGES_XRAYED:l?s?Zs.EDGES_COLOR_TRANSPARENT:Zs.EDGES_COLOR_OPAQUE:Zs.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Zs.PICK:Zs.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,ka[0]=A,this._state.flagsBuf.setData(ka,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(za[0]=t[0],za[1]=t[1],za[2]=t[2],this._state.offsetsBuf.setData(za,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawEdgesXRayed(e,t){}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Zs.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Zs.PICK)}drawPickNormals(e,t){}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}class Ya{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class Xa{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const qa={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class Ja{constructor(e,t,s){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,s=this.handlers.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==er[e])return void er[e].push({onLoad:t,onProgress:s,onError:n});er[e]=[],er[e].push({onLoad:t,onProgress:s,onError:n});const a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),r=this.mimeType,l=this.responseType;fetch(a).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const s=er[e],n=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,r=0!==a;let l=0;const o=new ReadableStream({start(e){!function t(){n.read().then((({done:n,value:i})=>{if(n)e.close();else{l+=i.byteLength;const n=new ProgressEvent("progress",{lengthComputable:r,loaded:l,total:a});for(let e=0,t=s.length;e{switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,r)));case"json":return e.json();default:if(void 0===r)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(r),s=t&&t[1]?t[1].toLowerCase():void 0,n=new TextDecoder(s);return e.arrayBuffer().then((e=>n.decode(e)))}}})).then((t=>{qa.add(e,t);const s=er[e];delete er[e];for(let e=0,n=s.length;e{const s=er[e];if(void 0===s)throw this.manager.itemError(e),t;delete er[e];for(let e=0,n=s.length;e{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class sr{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e{const n=this._getIdleWorker();-1!==n?(this._initWorker(n),this.workerStatus|=1<e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let nr=0;class ir{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new sr,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const n=e.capabilities;this._workerConfig={astcSupported:n.astcSupported,etc1Supported:n.etc1Supported,etc2Supported:n.etc2Supported,dxtSupported:n.dxtSupported,bptcSupported:n.bptcSupported,pvrtcSupported:n.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new tr;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new tr;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const n=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,n]).then((([e,t])=>{const s=ir.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(ir.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(ir.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(ir.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([n])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),nr>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),nr++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((n,i)=>{const a=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e))).then((e=>{const s=e.data,{mipmaps:a,width:r,height:l,format:o,type:c,error:u,dfdTransferFn:h,dfdFlags:p}=s;if("error"===c)return i(u);t.setCompressedData({mipmaps:a,props:{format:o,minFilter:1===a.length?1006:1008,magFilter:1===a.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&p)}}),n()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),nr--}}ir.BasisFormat={ETC1S:0,UASTC_4x4:1},ir.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},ir.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},ir.BasisWorker=function(){let e,t,s;const n=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(r){const u=r.data;switch(u.type){case"init":e=u.config,h=u.transcoderBinary,t=new Promise((e=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:r,hasAlpha:h,mipmaps:p,format:A,dfdTransferFn:d,dfdFlags:f}=function(t){const r=new s.KTX2File(new Uint8Array(t));function u(){r.close(),r.delete()}if(!r.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=r.isUASTC()?a.UASTC_4x4:a.ETC1S,p=r.getWidth(),A=r.getHeight(),d=r.getLevels(),f=r.getHasAlpha(),I=r.getDFDTransferFunc(),y=r.getDFDFlags(),{transcoderFormat:m,engineFormat:v}=function(t,s,r,u){let h,p;const A=t===a.ETC1S?l:o;for(let n=0;n{delete ar[t],s.destroy()}))),s} /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT @@ -14,7 +14,7 @@ /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT - **/let hr=null;function pr(e,t){const s=3*e,n=3*t;let i,a,r,l,o,c;const u=Math.min(i=hr[s],a=hr[s+1],r=hr[s+2]),h=Math.min(l=hr[n],o=hr[n+1],c=hr[n+2]);if(u!==h)return u-h;const p=Math.max(i,a,r),A=Math.max(l,o,c);return p!==A?p-A:0}let Ar=null;function dr(e,t){let s=Ar[2*e]-Ar[2*t];return 0!==s?s:Ar[2*e+1]-Ar[2*t+1]}function fr(e,t,s=!1){const n=e.positionsCompressed||[],i=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e>t;s.sort(pr);const n=new Int32Array(e.length);for(let t=0,i=s.length;te[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}Ar=new Int32Array(e),t.sort(dr);const s=new Int32Array(e.length);for(let n=0,i=t.length;nt){let s=e;e=t,t=s}function s(s,n){return s!==e?e-s:n!==t?t-n:0}let n=0,i=(a.length>>1)-1;for(;n<=i;){const e=i+n>>1,t=s(a[2*e],a[2*e+1]);if(t>0)n=e+1;else{if(!(t<0))return e;i=e-1}}return-n-1}const l=new Int32Array(a.length/2);l.fill(0);const o=n.length/3;if(o>8*(1<p.maxNumPositions&&(p=h()),p.bucketNumber>8)return[e];let d;-1===c[o]&&(c[o]=p.numPositions++,p.positionsCompressed.push(n[3*o]),p.positionsCompressed.push(n[3*o+1]),p.positionsCompressed.push(n[3*o+2])),-1===c[u]&&(c[u]=p.numPositions++,p.positionsCompressed.push(n[3*u]),p.positionsCompressed.push(n[3*u+1]),p.positionsCompressed.push(n[3*u+2])),-1===c[A]&&(c[A]=p.numPositions++,p.positionsCompressed.push(n[3*A]),p.positionsCompressed.push(n[3*A+1]),p.positionsCompressed.push(n[3*A+2])),p.indices.push(c[o]),p.indices.push(c[u]),p.indices.push(c[A]),(d=r(o,u))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]])),(d=r(o,A))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]])),(d=r(u,A))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]]))}const A=t/8*2,d=t/8,f=2*n.length+(i.length+a.length)*A;let I=0,y=-n.length/3;return u.forEach((e=>{I+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*d,y+=e.positionsCompressed.length/3})),I>f?[e]:(s&&function(e,t){const s={},n={};let i=0;e.forEach((e=>{const t=e.indices,a=e.edgeIndices,r=e.positionsCompressed;for(let e=0,n=t.length;e0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl,s=e._lightsState;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uLightAmbient=n.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];const i=s.lights;let a;for(let e=0,t=i.length;e0;let i;const a=[];a.push("#version 300 es"),a.push("// TrianglesDataTextureColorRenderer vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("uniform mat4 sceneModelWorldMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),a.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),a.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),a.push("uniform highp sampler2D uTextureModelMatrices;"),a.push("uniform vec3 uCameraEyeRtc;"),a.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("out float isPerspective;")),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e> 3) & 4095;"),a.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),a.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),a.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),a.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),a.push("if (int(flags.x) != renderPass) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("} else {"),a.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),a.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),a.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),a.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),a.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),a.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),a.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),a.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),a.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),a.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),a.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),a.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),a.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),a.push("if (color.a == 0u) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("};"),a.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),a.push("vec3 position;"),a.push("position = positions[gl_VertexID % 3];"),a.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),a.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("} else {"),a.push("if (viewNormal.z < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("}"),a.push("}"),a.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),a.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),a.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Er=new Float32Array([1,1,1]),br=h.vec3(),Dr=h.vec3(),Pr=h.vec3(),Rr=h.vec3(),Cr=h.mat4();class _r{constructor(e,t){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=this._scene,i=n.camera,a=t.model,r=n.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=a,d=i.viewMatrix;if(!this._program&&(this._allocate(),this.errors))return;let f,I;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,l)),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const e=br;if(c){const t=Dr;h.transformPoint3(p,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=B(d,e,Cr),I=Pr,I[0]=i.eye[0]-e[0],I[1]=i.eye[1]-e[1],I[2]=i.eye[2]-e[2]}else f=d,I=i.eye;if(r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s===Zs.SILHOUETTE_XRAYED){const e=n.xrayMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Zs.SILHOUETTE_HIGHLIGHTED){const e=n.highlightMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Zs.SILHOUETTE_SELECTED){const e=n.selectedMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else r.uniform4fv(this._uColor,Er);if(n.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const y=n._sectionPlanesState.sectionPlanes.length;if(y>0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uColor=s.getLocation("color"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture silhouette vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.y) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("viewNormal = -viewNormal;"),s.push("}"),s.push("} else {"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("viewNormal = -viewNormal;"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = color;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Br=new Float32Array([0,0,0,1]),Or=h.vec3(),Sr=h.vec3();h.vec3();const Nr=h.vec3(),xr=h.mat4();class Lr{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=Or;if(I){const t=Sr;h.transformPoint3(p,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=B(d,e,xr)}else f=d;if(r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),s===Zs.EDGES_XRAYED){const e=i.xrayMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Zs.EDGES_HIGHLIGHTED){const e=i.highlightMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Zs.EDGES_SELECTED){const e=i.selectedMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else r.uniform4fv(this._uColor,Br);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(r.LINES,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(r.LINES,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(r.LINES,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uColor=s.getLocation("color"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.z) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),e.logarithmicDepthBufferEnabled&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Mr=h.vec3(),Fr=h.vec3(),Hr=h.vec3(),Ur=h.mat4();class Gr{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=a.viewMatrix;if(!this._program&&(this._allocate(),this.errors))return;let f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=Mr;if(I){const t=Fr;h.transformPoint3(p,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=B(d,e,Ur)}else f=d;r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(r.LINES,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(r.LINES,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(r.LINES,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureEdgesColorRenderer"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled,s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.z) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push(" vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vec4 rgb = vec4(color.rgba);"),s.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureEdgesColorRenderer"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const jr=h.vec3(),Vr=h.vec3(),kr=h.vec3(),Qr=h.mat4();class Wr{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){if(!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n;let d,f;o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=jr;if(I){const t=h.transformPoint3(p,c,Vr);e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],d=B(a.viewMatrix,e,Qr),f=kr,f[0]=a.eye[0]-e[0],f[1]=a.eye[1]-e[1],f[2]=a.eye[2]-e[2]}else d=a.viewMatrix,f=a.eye;if(r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),r.uniform3fv(this._uCameraEyeRtc,f),r.uniform1i(this._uRenderPass,s),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("smooth out vec4 vWorldPosition;"),s.push("flat out uvec4 vFlags2;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uvec4 vFlags2;");for(var i=0;i 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outPickColor = vPickColor; "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const zr=h.vec3(),Kr=h.vec3(),Yr=h.vec3(),Xr=h.vec3(),qr=h.mat4();class Jr{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=e.pickViewMatrix||a.viewMatrix;let f,I;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const t=zr;if(c){const e=Kr;h.transformPoint3(p,c,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],f=B(d,t,qr),I=Yr,I[0]=a.eye[0]-t[0],I[1]=a.eye[1]-t[1],I[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else f=d,I=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform1f(this._uPickZNear,e.pickZNear),r.uniform1f(this._uPickZFar,e.pickZFar),r.uniformMatrix4fv(this._uWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick depth vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var i=0;i 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outPackedDepth = packDepth(zNormalizedDepth); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Zr=h.vec3(),$r=h.vec3(),el=h.vec3(),tl=h.vec3(),sl=h.vec3(),nl=h.mat4();class il{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=t.aabb,f=e.pickViewMatrix||a.viewMatrix,I=Zr;let y,m;I[0]=h.safeInv(d[3]-d[0])*h.MAX_INT,I[1]=h.safeInv(d[4]-d[1])*h.MAX_INT,I[2]=h.safeInv(d[5]-d[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(I[0]),e.snapPickCoordinateScale[1]=h.safeInv(I[1]),e.snapPickCoordinateScale[2]=h.safeInv(I[2]),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const v=0!==c[0]||0!==c[1]||0!==c[2],w=0!==u[0]||0!==u[1]||0!==u[2];if(v||w){const t=$r;if(v){const e=h.transformPoint3(p,c,el);t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],y=B(f,t,nl),m=tl,m[0]=a.eye[0]-t[0],m[1]=a.eye[1]-t[1],m[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else y=f,m=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,m),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,y),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const g=i._sectionPlanesState.sectionPlanes.length;if(g>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*g,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(T,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(T,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(T,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 uSnapVectorA;"),s.push("uniform vec2 uSnapInvVectorAB;"),s.push("vec3 positions[3];"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),s.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vViewPosition;"),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("{"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vViewPosition = clipPos;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles dataTexture pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int uLayerNumber;"),s.push("uniform vec3 uCoordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(let t=0,n=e.sectionPlanes.length;t 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, uLayerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const al=h.vec3(),rl=h.vec3(),ll=h.vec3(),ol=h.vec3(),cl=h.vec3(),ul=h.mat4();class hl{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=t.aabb,f=e.pickViewMatrix||a.viewMatrix,I=al;let y,m;I[0]=h.safeInv(d[3]-d[0])*h.MAX_INT,I[1]=h.safeInv(d[4]-d[1])*h.MAX_INT,I[2]=h.safeInv(d[5]-d[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(I[0]),e.snapPickCoordinateScale[1]=h.safeInv(I[1]),e.snapPickCoordinateScale[2]=h.safeInv(I[2]),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const v=0!==c[0]||0!==c[1]||0!==c[2],w=0!==u[0]||0!==u[1]||0!==u[2];if(v||w){const t=rl;if(v){const e=ll;h.transformPoint3(p,c,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],y=B(f,t,ul),m=ol,m[0]=a.eye[0]-t[0],m[1]=a.eye[1]-t[1],m[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else y=f,m=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,m),r.uniform2fv(this._uVectorA,e.snapVectorA),r.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,y),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const g=i._sectionPlanesState.sectionPlanes.length;if(g>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*g,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureSnapDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 uVectorAB;"),s.push("uniform vec2 uInverseVectorAB;"),s.push("vec3 positions[3];"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),s.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("{"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (solid != 1u) {"),s.push(" if (isPerspectiveMatrix(projMatrix)) {"),s.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" viewNormal = -viewNormal;"),s.push(" }"),s.push(" } else {"),s.push(" if (viewNormal.z < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" viewNormal = -viewNormal;"),s.push(" }"),s.push(" }"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureSnapDepthBufInitRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int uLayerNumber;"),s.push("uniform vec3 uCoordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(let t=0,n=e.sectionPlanes.length;t 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const pl=h.vec3();class Al{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);let u=a.eye;const h=[u[0]-c[0],u[1]-c[1],u[2]-c[2]];if(r.uniform3fv(this._uCameraEyeRtc,h),r.uniform1i(this._uRenderPass,s),r.uniform3fv(this._uCameraEyeRtc,h),r.uniform1i(this._uPickInvisible,e.pickInvisible),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const p=i._sectionPlanesState.sectionPlanes.length;if(p>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*p,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick normals vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureCameraMatrices;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));"),s.push("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));"),s.push("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("normal = -normal;"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("normal = -normal;"),s.push("}"),s.push("}"),s.push("}"),s.push("normal = -normal;"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vWorldNormal = normal.xyz;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.w;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var i=0;i 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const dl=h.vec3(),fl=h.vec3(),Il=h.vec3(),yl=h.vec3(),ml=h.mat4();class vl{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=e.pickViewMatrix||a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let f,I;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const e=dl;if(c){const t=fl;h.transformPoint3(p,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=B(d,e,ml),I=Il,I[0]=a.eye[0]-e[0],I[1]=a.eye[1]-e[1],I[2]=a.eye[2]-e[2]}else f=d,I=a.eye;r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out vec4 vFlags2;")),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.x) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push(" if (isPerspectiveMatrix(projMatrix)) {"),s.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix; * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" }"),s.push(" } else {"),s.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push(" if (viewNormal.z < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" }"),s.push(" }"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix; * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in vec4 vFlags2;");for(let t=0;t 0.0);"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const wl=h.vec3(),gl=h.vec3(),Tl=h.vec3(),El=h.vec3(),bl=h.mat4();class Dl{constructor(e){this._scene=e,this._allocate(),this._hash=this._getHash()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=this._scene,i=n.camera,a=t.model,r=n.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=a;if(!this._program&&(this._allocate(),this.errors))return;let d,f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,l)),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=wl;if(I){const t=h.transformPoint3(p,c,gl);e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],d=B(i.viewMatrix,e,bl),f=Tl,f[0]=i.eye[0]-e[0],f[1]=i.eye[1]-e[1],f[2]=i.eye[2]-e[2]}else d=i.viewMatrix,f=i.eye;if(r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),r.uniform3fv(this._uCameraEyeRtc,f),r.uniform1i(this._uRenderPass,s),n.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const m=n._sectionPlanesState.sectionPlanes.length;if(m>0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture draw vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out highp vec2 vHighPrecisionZW;"),s&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in highp vec2 vHighPrecisionZW;"),n.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Pl=h.vec3(),Rl=h.vec3(),Cl=h.vec3(),_l=h.vec3(),Bl=h.mat4();class Ol{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:p}=n,A=a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let d,f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(t));const I=0!==o[0]||0!==o[1]||0!==o[2],y=0!==c[0]||0!==c[1]||0!==c[2];if(I||y){const e=Pl;if(I){const t=Rl;h.transformPoint3(u,o,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=c[0],e[1]+=c[1],e[2]+=c[2],d=B(A,e,Bl),f=Cl,f[0]=a.eye[0]-e[0],f[1]=a.eye[1]-e[1],f[2]=a.eye[2]-e[2]}else d=A,f=a.eye;r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),r.uniformMatrix4fv(this._uViewNormalMatrix,!1,a.viewNormalMatrix),r.uniformMatrix4fv(this._uWorldNormalMatrix,!1,n.worldNormalMatrix);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0,s=[];return s.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&s.push("#extension GL_EXT_frag_depth : enable"),s.push("uniform int renderPass;"),s.push("attribute vec3 position;"),e.entityOffsetsEnabled&&s.push("attribute vec3 offset;"),s.push("attribute vec3 normal;"),s.push("attribute vec4 color;"),s.push("attribute vec4 flags;"),s.push("attribute vec4 flags2;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 worldNormalMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 viewNormalMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("varying float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out vec4 vFlags2;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("if (int(flags.x) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(ct.SUPPORTED_EXTENSIONS.EXT_frag_depth?s.push("vFragDepth = 1.0 + clipPos.w;"):(s.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),s.push("clipPos.z *= clipPos.w;")),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(let e=0;e 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Sl=h.vec3();class Nl{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerObjectIdPositionsDecodeMatrix),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},1),this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerVertexIdCoordinates),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},2),this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerObjectIdColorsAndFlags),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},3),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix);const c=e.pickViewMatrix||a.viewMatrix,u=o?B(c,o):c;if(r.uniformMatrix4fv(this._uViewMatrix,!1,u),r.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const h=i._sectionPlanesState.sectionPlanes.length;if(h>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*h,a=n.renderFlags;for(let t=0;t0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds8Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices8Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds16Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices16Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds32Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices32Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick flat normals vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in uvec3 packedVertexId;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform isampler2D uTexturePerPolygonIdNormals;"),s.push("uniform usampler2D uTexturePerPolygonIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out int vFlags2;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_normal_index = polygonIndex & 4095;"),s.push("int v_normal_index = polygonIndex >> 12;"),s.push("int h_packed_object_id_index = ((polygonIndex >> 3) / 2) & 4095;"),s.push("int v_packed_object_id_index = ((polygonIndex >> 3) / 2) >> 12;"),s.push("ivec3 packedObjectId = ivec3(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).rgb);"),s.push("int objectIndex;"),s.push("if (((polygonIndex >> 3) % 2) == 0) {"),s.push(" objectIndex = (packedObjectId.r << 4) + (packedObjectId.g >> 4);"),s.push("} else {"),s.push(" objectIndex = ((packedObjectId.g & 15) << 8) + packedObjectId.b;"),s.push("}"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("int h_index = polygonIndex & 4095;"),s.push("int v_index = polygonIndex >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position1 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("vec3 position2 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("vec3 position3 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(position3 - position1, position2 - position1));"),s.push("int vertexNumber = gl_VertexID % 3;"),s.push("vec3 position;"),s.push("if (vertexNumber == 0) position = position1;"),s.push("else if (vertexNumber == 1) position = position2;"),s.push("else position = position3;"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags2 = flags2.r;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick flat normals fragment shader"),n.push("#extension GL_OES_standard_derivatives : enable"),e.logarithmicDepthBufferEnabled&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in int vFlags2;");for(var i=0;i 0;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class xl{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._vertexDepthRenderer&&!this._vertexDepthRenderer.getValid()&&(this._vertexDepthRenderer.destroy(),this._vertexDepthRenderer=null),this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Tr(this._scene,!1)),this._colorRenderer}get colorRendererWithSAO(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new Tr(this._scene,!0)),this._colorRendererWithSAO}get colorQualityRendererWithSAO(){return this._colorQualityRendererWithSAO||(this._colorQualityRendererWithSAO=new TrianglesDataTextureColorQualityRenderer(this._scene,!0)),this._colorQualityRendererWithSAO}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new _r(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Dl(this._scene)),this._depthRenderer}get normalsRenderer(){return this._normalsRenderer||(this._normalsRenderer=new Ol(this._scene)),this._normalsRenderer}get edgesRenderer(){return this._edgesRenderer||(this._edgesRenderer=new Lr(this._scene)),this._edgesRenderer}get edgesColorRenderer(){return this._edgesColorRenderer||(this._edgesColorRenderer=new Gr(this._scene)),this._edgesColorRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Wr(this._scene)),this._pickMeshRenderer}get pickNormalsRenderer(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Al(this._scene)),this._pickNormalsRenderer}get pickNormalsFlatRenderer(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new Nl(this._scene)),this._pickNormalsFlatRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Jr(this._scene)),this._pickDepthRenderer}get vertexDepthRenderer(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new il(this._scene)),this._vertexDepthRenderer}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new hl(this._scene)),this._snapDepthBufInitRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new vl(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorQualityRendererWithSAO&&this._colorQualityRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._vertexDepthRenderer&&this._vertexDepthRenderer.destroy(),this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const Ll={};class Ml{constructor(){this.positionsCompressed=[],this.metallicRoughness=[],this.indices8Bits=[],this.indices16Bits=[],this.indices32Bits=[],this.edgeIndices8Bits=[],this.edgeIndices16Bits=[],this.edgeIndices32Bits=[],this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]}}class Fl{constructor(){this.texturePerObjectIdColorsAndFlags=null,this.texturePerObjectIdOffsets=null,this.texturePerObjectIdPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}finalize(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}bindCommonTextures(e,t,s,n,i,a){this.texturePerObjectIdPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,s,2),this.texturePerObjectIdColorsAndFlags.bindTexture(e,n,3),this.texturePerObjectIdOffsets.bindTexture(e,a,4)}bindTriangleIndicesTextures(e,t,s,n){this.indicesPortionIdsPerBitnessTextures[n].bindTexture(e,t,5),this.indicesPerBitnessTextures[n].bindTexture(e,s,6)}bindEdgeIndicesTextures(e,t,s,n){this.edgeIndicesPortionIdsPerBitnessTextures[n].bindTexture(e,t,5),this.edgeIndicesPerBitnessTextures[n].bindTexture(e,s,6)}}class Hl{constructor(e,t,s,n,i=null){this._gl=e,this._texture=t,this._textureWidth=s,this._textureHeight=n,this._textureData=i}bindTexture(e,t,s){return e.bindTexture(t,this,s)}bind(e){return this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,this._texture),!0}unbind(e){}}const Ul={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(Ul,null,4));let e=0;Object.keys(Ul).forEach((t=>{t.startsWith("size")&&(e+=Ul[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/Ul.totalPolygons).toFixed(2)}`);let t={};Object.keys(Ul).forEach((s=>{s.startsWith("size")&&(t[s]=`${(Ul[s]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};class Gl{disableBindedTextureFiltering(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}generateTextureForColorsAndFlags(e,t,s,n,i,a,r){const l=t.length;this.numPortions=l;const o=4096,c=Math.ceil(l/512);if(0===c)throw"texture height===0";const u=new Uint8Array(16384*c);Ul.sizeDataColorsAndFlags+=u.byteLength,Ul.numberOfTextures++;for(let e=0;e>24&255,n[e]>>16&255,n[e]>>8&255,255&n[e]],32*e+16),u.set([i[e]>>24&255,i[e]>>16&255,i[e]>>8&255,255&i[e]],32*e+20),u.set([a[e]>>24&255,a[e]>>16&255,a[e]>>8&255,255&a[e]],32*e+24),u.set([r[e]?1:0,0,0,0],32*e+28);const h=e.createTexture();return e.bindTexture(e.TEXTURE_2D,h),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,o,c),e.texSubImage2D(e.TEXTURE_2D,0,0,0,o,c,e.RGBA_INTEGER,e.UNSIGNED_BYTE,u,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new Hl(e,h,o,c,u)}generateTextureForObjectOffsets(e,t){const s=512,n=Math.ceil(t/s);if(0===n)throw"texture height===0";const i=new Float32Array(1536*n).fill(0);Ul.sizeDataTextureOffsets+=i.byteLength,Ul.numberOfTextures++;const a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,s,n),e.texSubImage2D(e.TEXTURE_2D,0,0,0,s,n,e.RGB,e.FLOAT,i,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new Hl(e,a,s,n,i)}generateTextureForPositionsDecodeMatrices(e,t,s){const n=t.length;if(0===n)throw"num decode+entity matrices===0";const i=2048,a=Math.ceil(n/512),r=new Float32Array(8192*a);Ul.sizeDataPositionDecodeMatrices+=r.byteLength,Ul.numberOfTextures++;const l=h.mat4();for(let e=0;e{s._compile()})),e.on("destroyed",(()=>{delete Ll[t],s._destroy()}))),s}(e.scene),this.model=e,this._buffer=new Ml,this._dataTextureState=new Fl,this._dataTextureGenerator=new Gl,this._state=new ye({origin:h.vec3(t.origin),metallicRoughnessBuf:null,positionsDecodeMatrix:h.mat4(),textureState:this._dataTextureState,numIndices8Bits:0,numIndices16Bits:0,numIndices32Bits:0,numEdgeIndices8Bits:0,numEdgeIndices16Bits:0,numEdgeIndices32Bits:0,numVertices:0}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._subPortions=[],this._portionToSubPortionsMap=[],this._bucketGeometries={},this.aabb=h.collapseAABB3(),this._numUpdatesInFrame=0,this._finalized=!1}canCreatePortion(e){if(this._finalized)throw"Already finalized";const t=e.buckets.length;this._numPortions+t>65536&&Ul.cannotCreatePortion.because10BitsObjectId++;let s=this._numPortions+t<=65536;const n=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#0`:`${e.id}#0`;if(!this._bucketGeometries[n]){const t=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits);let n=0,i=0;e.buckets.forEach((e=>{n+=e.positionsCompressed.length/3,i+=e.indices.length/3})),(this._state.numVertices+n>16777216||t+i>16777216)&&Ul.cannotCreatePortion.becauseTextureSize++,s&&=this._state.numVertices+n<=16777216&&t+i<=16777216}return s}createPortion(e){if(this._finalized)throw"Already finalized";const t=[],s=e.worldAABB;e.buckets.forEach(((n,i)=>{const a=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#${i}`:`${e.id}#${i}`;let r=this._bucketGeometries[a];r||(r=this._createBucketGeometry(e,n),this._bucketGeometries[a]=r);const l=h.collapseAABB3(Wl),o=this._createSubPortion(e,r,n,l);h.expandAABB3(s,l),t.push(o)}));const n=this._state.origin;0===n[0]&&0===n[1]&&0===n[2]||(s[0]+=n[0],s[1]+=n[1],s[2]+=n[2],s[3]+=n[0],s[4]+=n[1],s[5]+=n[2]),h.expandAABB3(this.aabb,s);const i=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(t),this.model.numPortions++,i}_createBucketGeometry(e,t){if(t.indices){const e=8*Math.ceil(t.indices.length/3/8)*3;Ul.overheadSizeAlignementIndices+=2*(e-t.indices.length);const s=new Uint32Array(e);s.fill(0),s.set(t.indices),t.indices=s}if(t.edgeIndices){const e=8*Math.ceil(t.edgeIndices.length/2/8)*2;Ul.overheadSizeAlignementEdgeIndices+=2*(e-t.edgeIndices.length);const s=new Uint32Array(e);s.fill(0),s.set(t.edgeIndices),t.edgeIndices=s}const s=t.positionsCompressed,n=t.indices,i=t.edgeIndices,a=this._buffer,r=a.positionsCompressed.length/3,l=s.length/3;for(let e=0,t=s.length;e0){let e,s=3*t.numTriangles;t.numVertices<=256?(e=c.perTriangleNumberPortionId8Bits,u.numIndices8Bits+=s,Ul.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(e=c.perTriangleNumberPortionId16Bits,u.numIndices16Bits+=s,Ul.totalPolygons16Bits+=t.numTriangles):(e=c.perTriangleNumberPortionId32Bits,u.numIndices32Bits+=s,Ul.totalPolygons32Bits+=t.numTriangles),Ul.totalPolygons+=t.numTriangles;for(let s=0;s0){let e,s=2*t.numEdges;t.numVertices<=256?(e=c.perEdgeNumberPortionId8Bits,u.numEdgeIndices8Bits+=s,Ul.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(e=c.perEdgeNumberPortionId16Bits,u.numEdgeIndices16Bits+=s,Ul.totalEdges16Bits+=t.numEdges):(e=c.perEdgeNumberPortionId32Bits,u.numEdgeIndices32Bits+=s,Ul.totalEdges32Bits+=t.numEdges),Ul.totalEdges+=t.numEdges;for(let s=0;s0&&(t.texturePerEdgeIdPortionIds8Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId8Bits)),n.perEdgeNumberPortionId16Bits.length>0&&(t.texturePerEdgeIdPortionIds16Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId16Bits)),n.perEdgeNumberPortionId32Bits.length>0&&(t.texturePerEdgeIdPortionIds32Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId32Bits)),n.indices8Bits.length>0&&(t.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(s,n.indices8Bits)),n.indices16Bits.length>0&&(t.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(s,n.indices16Bits)),n.indices32Bits.length>0&&(t.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(s,n.indices32Bits)),n.edgeIndices8Bits.length>0&&(t.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(s,n.edgeIndices8Bits)),n.edgeIndices16Bits.length>0&&(t.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(s,n.edgeIndices16Bits)),n.edgeIndices32Bits.length>0&&(t.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(s,n.edgeIndices32Bits)),t.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(()=>{this._deferredSetFlagsDirty&&this._uploadDeferredFlags(),this._numUpdatesInFrame=0}))}isEmpty(){return 0===this._numPortions}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,true),this._setFlags2(e,t,true)}flushInitFlags(){this._setDeferredFlags(),this._setDeferredFlags2()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}_beginDeferredFlags(){this._deferredSetFlagsActive=!0}_uploadDeferredFlags(){if(console.info("_uploadDeferredFlags"),this._deferredSetFlagsActive=!1,!this._deferredSetFlagsDirty)return;this._deferredSetFlagsDirty=!1;const e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdColorsAndFlags._textureWidth,t.texturePerObjectIdColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectIdColorsAndFlags._textureData),e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdOffsets._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdOffsets._textureWidth,t.texturePerObjectIdOffsets._textureHeight,e.RGB,e.FLOAT,t.texturePerObjectIdOffsets._textureData)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){const s=this._portionToSubPortionsMap[e];for(let e=0,n=s.length;e=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),n.bindTexture(n.TEXTURE_2D,s.texturePerObjectIdColorsAndFlags._texture),n.texSubImage2D(n.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,n.RGBA_INTEGER,n.UNSIGNED_BYTE,kl)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s,n=!1){const i=this._portionToSubPortionsMap[e];for(let e=0,a=i.length;e=10&&this._beginDeferredFlags(),d.bindTexture(d.TEXTURE_2D,A.texturePerObjectIdColorsAndFlags._texture),d.texSubImage2D(d.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,d.RGBA_INTEGER,d.UNSIGNED_BYTE,kl))}_setDeferredFlags(){}_setFlags2(e,t,s=!1){const n=this._portionToSubPortionsMap[e];for(let e=0,i=n.length;e=10&&this._beginDeferredFlags(),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectIdColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,kl))}_setDeferredFlags2(){}setOffset(e,t){const s=this._portionToSubPortionsMap[e];for(let e=0,n=s.length;e=10&&this._beginDeferredFlags(),n.bindTexture(n.TEXTURE_2D,s.texturePerObjectIdOffsets._texture),n.texSubImage2D(n.TEXTURE_2D,0,0,e,1,1,n.RGB,n.FLOAT,Ql))}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?this._dataTextureRenderers.colorRendererWithSAO&&this._dataTextureRenderers.colorRendererWithSAO.drawLayer(t,this,Zs.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}_updateBackfaceCull(e,t){const s=this.model.backfaces||e.sectioned;if(t.backfaces!==s){const e=t.gl;s?e.disable(e.CULL_FACE):e.enable(e.CULL_FACE),t.backfaces=s}}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_TRANSPARENT))}drawDepth(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.depthRenderer&&this._dataTextureRenderers.depthRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}drawNormals(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.normalsRenderer&&this._dataTextureRenderers.normalsRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_XRAYED))}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_HIGHLIGHTED))}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_SELECTED))}drawEdgesColorOpaque(e,t){this.model.scene.logarithmicDepthBufferEnabled?this.model.scene._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),this.model.scene._loggedWarning=!0):this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Zs.EDGES_COLOR_OPAQUE)}drawEdgesColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Zs.EDGES_COLOR_TRANSPARENT)}drawEdgesHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Zs.EDGES_HIGHLIGHTED)}drawEdgesSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Zs.EDGES_SELECTED)}drawEdgesXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Zs.EDGES_XRAYED)}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.occlusionRenderer&&this._dataTextureRenderers.occlusionRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}drawShadow(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.shadowRenderer&&this._dataTextureRenderers.shadowRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}setPickMatrices(e,t){}drawPickMesh(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickMeshRenderer&&this._dataTextureRenderers.pickMeshRenderer.drawLayer(t,this,Zs.PICK))}drawPickDepths(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,Zs.PICK))}drawSnapInitDepthBuf(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.snapDepthBufInitRenderer&&this._dataTextureRenderers.snapDepthBufInitRenderer.drawLayer(t,this,Zs.PICK))}drawSnapDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.vertexDepthRenderer&&this._dataTextureRenderers.vertexDepthRenderer.drawLayer(t,this,Zs.PICK))}drawPickNormals(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickNormalsRenderer&&this._dataTextureRenderers.pickNormalsRenderer.drawLayer(t,this,Zs.PICK))}destroy(){if(this._destroyed)return;const e=this._state;e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}const Xl=h.vec3();h.mat4();const ql=h.vec3([1,1,1]),Jl=h.vec3([0,0,0]),Zl=h.vec3([0,0,0]),$l=h.identityQuaternion(),eo=h.identityMat4(),to=new Uint8Array([255,255,255]);class so extends C{constructor(e,t={}){super(e,t),this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!0,this._vboBatchingLayerScratchMemory=(Js++,qs),this._textureTranscoder=t.textureTranscoder||rr(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize,this._aabb=h.collapseAABB3(),this._aabbDirty=!0,this._quantizationRanges={},this._vboInstancingLayers={},this._vboBatchingLayers={},this._dtxLayers={},this._meshList=[],this.layerList=[],this._entityList=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this._scheduledMeshes={},this.renderFlags=new Gt,this.numGeometries=0,this.numPortions=0,this.numVisibleLayerPortions=0,this.numTransparentLayerPortions=0,this.numXRayedLayerPortions=0,this.numHighlightedLayerPortions=0,this.numSelectedLayerPortions=0,this.numEdgesLayerPortions=0,this.numPickableLayerPortions=0,this.numClippableLayerPortions=0,this.numCulledLayerPortions=0,this.numEntities=0,this._numTriangles=0,this._numLines=0,this._numPoints=0,this._edgeThreshold=t.edgeThreshold||10,this._origin=h.vec3(t.origin||[0,0,0]),this._position=h.vec3(t.position||[0,0,0]),this._rotation=h.vec3(t.rotation||[0,0,0]),this._quaternion=h.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=h.vec4(t.quaternion||[0,0,0,1]),t.rotation&&h.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=h.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=h.mat4(),this._worldRotationMatrixConjugate=h.mat4(),this._matrix=h.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=h.mat4(),h.inverseMat4(this._matrix,this._worldNormalMatrix),h.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=h.mat4(),this._viewNormalMatrix=h.mat4(),this._viewMatrixDirty=!0,this._matrixNonIdentity=!0),this._opacity=1,this._colorize=[1,1,1],this._saoEnabled=!1!==t.saoEnabled,this._pbrEnabled=!1!==t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{this._viewMatrixDirty=!0})),this.scene.vfc.enabled&&(this._vfcManager=this.scene.vfc.getVFCManager(this)),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_createDefaultTextureSet(){const e=new Xa({id:"defaultColorTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Xa({id:"defaultMetalRoughTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new Xa({id:"defaultNormalsTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new Xa({id:"defaultEmissiveTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new Xa({id:"defaultOcclusionTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new Ya({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}get isPerformanceModel(){return!0}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),h.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),h.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||eo),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0}_setLocalAABBDirty(){for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,s=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,n=t.length;e{o.setImage(c,{minFilter:s,magFilter:n,wrapS:i,wrapT:a,wrapR:r,flipY:e.flipY,encoding:l}),this.glRedraw()},c.src=e.src;break;default:this._textureTranscoder?y.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],o).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,o).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new Xa({id:t,texture:o})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let s,n,i,a,r;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(a=this._textures[e.emissiveTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(r=this._textures[e.occlusionTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultOcclusionTexture;const l=new Ya({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:a,occlusionTexture:r});this._textureSets[t]=l}createMesh(e){if(void 0===e.id||null===e.id)return void this.error("[createMesh] SceneModel.createMesh() config missing: id");if(this._scheduledMeshes[e.id])return void this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`);if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return void this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`);if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),null;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),null;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),null;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),null;const t=!!this._dtxEnabled&&("triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive);if(e.origin=e.origin?h.addVec3(this._origin,e.origin,h.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||ql,s=e.position||Jl,n=e.rotation||Zl;h.eulerToQuaternion(n,"XYZ",$l),e.meshMatrix=h.composeMat4(s,$l,t,h.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Mn(e.positionsDecodeBoundary,h.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):to,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=h.vec3(),s=[];S(e.positions,s,t)&&(e.positions=s,e.origin=h.addVec3(e.origin,t,t))}if(e.positions){const t=h.collapseAABB3();e.positionsDecodeMatrix=h.mat4(),h.expandAABB3Points3(t,e.positions),e.positionsCompressed=Ln(e.positions,t,e.positionsDecodeMatrix)}e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=ve(e.positions,e.indices,null,2):e.edgeIndices=ve(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=no(e,this._enableVertexWelding&&this._enableIndexBucketing))}else{if(e.type=1,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):[255,255,255],e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.positions){const t=[];S(e.positions,t,Xl)&&(e.positions=t,e.origin=h.addVec3(e.origin,Xl,h.vec3()))}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=ve(e.positions,e.indices,null,2):e.edgeIndices=ve(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId],!e.textureSet))return void this.error(`[createMesh] Texture set not found: ${e.textureSetId} - ensure that you create it first with createTextureSet()`)}}else{if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return void this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)");if(e.geometry=this._geometries[e.geometryId],!e.geometry)return void this.error(`[createMesh] Geometry not found: ${e.geometryId} - ensure that you create it first with createGeometry()`);if(e.origin=e.origin?h.addVec3(this._origin,e.origin,h.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.matrix)e.meshMatrix=e.matrix.slice();else{const t=e.scale||ql,s=e.position||Jl,n=e.rotation||Zl;h.eulerToQuaternion(n,"XYZ",$l),e.meshMatrix=h.composeMat4(s,$l,t,h.mat4())}if(!!this._dtxEnabled&&("triangles"===e.geometry.primitive||"solid"===e.geometry.primitive||"surface"===e.geometry.primitive)){e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):to,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;let t=this._dtxBuckets[e.geometryId];t||(t=no(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=t),e.buckets=t}else e.type=0,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):to,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId]),function(e){if(e.obb=h.OBB3(),e.positionsCompressed&&e.positionsCompressed.length>0){const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positionsCompressed),Pe.decompressAABB(t,e.positionsDecodeMatrix),h.AABB3ToOBB3(t,e.obb)}else if(e.positions&&e.positions.length>0){const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positions),h.AABB3ToOBB3(t,e.obb)}}(e.geometry)}e.numPrimitives=this._getNumPrimitives(e),this._vfcManager&&!this._vfcManager.finalized?this._vfcManager.addMesh(e):this._createMesh(e)}_createMesh(e){const t=new Xs(this,e.id,e.color,e.opacity);t.pickId=this.scene._renderer.getPickID(t);const s=t.pickId,n=s>>24&255,i=s>>16&255,a=s>>8&255,r=255&s;switch(e.pickColor=new Uint8Array([r,a,i,n]),e.worldAABB=h.collapseAABB3(),e.aabb=e.worldAABB,e.solid="solid"===e.primitive,t.origin=h.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e);break;case 1:t.layer=this._getVBOBatchingLayer(e);break;case 0:t.layer=this._getVBOInstancingLayer(e)}t.portionId=t.layer.createPortion(e),t.aabb=e.worldAABB,t.numPrimitives=e.numPrimitives,h.expandAABB3(this._aabb,t.aabb),this._meshes[e.id]=t,this._meshList.push(t)}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,s=e.origin,n=e.textureSetId||"-",i=e.geometryId,a=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${n}.${i}`;let r=this._vboInstancingLayers[a];if(r)return r;let l=e.textureSet;const o=e.geometry;for(;!r;)switch(o.primitive){case"triangles":case"surface":console.info(`[SceneModel ${this.id}]: creating TrianglesInstancingLayer`),r=new ta({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0,solid:!1});break;case"solid":console.info(`[SceneModel ${this.id}]: creating TrianglesInstancingLayer`),r=new ta({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0,solid:!0});break;case"lines":console.info(`[SceneModel ${this.id}]: creating LinesInstancingLayer`),r=new va({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0});break;case"points":console.info(`[SceneModel ${this.id}]: creating PointsInstancingLayer`),r=new Ka({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0})}return this._vboInstancingLayers[a]=r,this.layerList.push(r),r}createEntity(e){if(void 0===e.id?e.id=h.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=h.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;if(this._visible&&!1!==e.visible&&(t|=x),this._pickable&&!1!==e.pickable&&(t|=M),this._culled&&!1!==e.culled&&(t|=L),this._clippable&&!1!==e.clippable&&(t|=F),this._collidable&&!1!==e.collidable&&(t|=H),this._edges&&!1!==e.edges&&(t|=V),this._xrayed&&!1!==e.xrayed&&(t|=U),this._highlighted&&!1!==e.highlighted&&(t|=G),this._selected&&!1!==e.selected&&(t|=j),e.flags=t,this._vfcManager&&!this._vfcManager.finalized){for(let t=0,s=e.meshIds.length;t{}));for(let e=0,t=this.layerList.length;ee.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,s=this.layerList.length;t0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s65536?16:8)}else r=[{positionsCompressed:n,indices:i,edgeIndices:a}];return r}class io extends C{get type(){return"SectionPlane"}constructor(e,t={}){super(e,t),this._state=new ye({active:!0,pos:h.vec3(),dir:h.vec3(),dist:0}),this.active=t.active,this.pos=t.pos,this.dir=t.dir,this.scene._sectionPlaneCreated(this)}set active(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}get active(){return this._state.active}set pos(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-h.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos)}get pos(){return this._state.pos}set dir(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-h.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir)}get dir(){return this._state.dir}get dist(){return this._state.dist}flipDir(){const e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-h.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}destroy(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),super.destroy()}}class ao extends C{constructor(e,t={}){super(e,t),this._skyboxMesh=new Jt(this,{geometry:new _e(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new ss(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new ps(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}class ro{constructor(e,t){this.primLODLevels=e,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=t,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}initializeLodState(e){const t=Object.values(e.objects);if(0===t.length)return;const s={},n={};for(let e=0,i=t.length;e=this.primLODLevels[r]);r++);const l=this.primLODLevels[r]||0;l in s||(s[l]=[]),s[l].push(i),l in n||(n[l]=0),n[l]+=i.numPrimitives}this.entitiesInLOD=s,this.primCountInLOD=n}}class lo{constructor(e,t,s,n){this.id=t.id,this.scene=e,this.sceneModel=t,this.lodState=new ro(s,n),this.lodState.initializeLodState(t)}_increaseLODLevelIndex(){const e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;const t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[];for(let e=0,s=t.length;e0&&(t.consecutiveFramesWithoutTargetFps=0,s=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,s=this._decreaseLODLevelIndex()),s}resetLodCulling(){let e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}class oo extends C{constructor(e,t={}){super(e,t),this._scene=e,this._lodLevels=[2e3,600,150,80,20],this._lodManagers={},this._lodManagerList=[],this.enabled=t.enabled,this.targetFPS=t.targetFPS,this._init()}_init(){const e=new Array(4);let t=0,s=-1,n=Date.now(),i=0,a=0,r=a;this._scene.on("rendering",(()=>{if(-1!==s)for(let e=0,t=this._lodManagerList.length;e{n=Date.now(),window.requestAnimationFrame((()=>{t++;const a=Date.now();i=a-n,n=a,e[t%4]=i;let r=0;if(t>4){for(let t=0;t<4;t++)r+=e[t];s=4/r*1e3}}))})),this._scene.camera.on("matrix",(()=>{r=a})),this._scene.on("tick",(()=>{if(a-r>3)for(let e=0,t=this._lodManagerList.length;e=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},s.boxRayIntersects=function(e,t,s,n,i,a,r){var l=(e.minX-t)*i,o=(e.maxX-t)*i,c=(e.minY-s)*a,u=(e.maxY-s)*a,h=(e.minZ-n)*r,p=(e.maxZ-n)*r,A=Math.min(h,p),d=Math.max(h,p),f=Math.min(c,u),I=Math.max(c,u),y=Math.min(l,o),m=Math.max(l,o),v=Math.max(0,y,f,A);return Math.min(m,I,d)>=v?v:1/0};var g=function(e,t,s,i,a){for(var r,l=[t,s];l.length;)(s=l.pop())-(t=l.pop())<=i||(r=t+Math.ceil((s-t)/i/2)*i,n(e,r,t,s,a),l.push(t,r,r,s))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var s=this.data,n=[];if(!e(s,h(s)))return n;for(var i=[];s;){for(var a=0,r=s.children.length;a1){for(d=0,f=(u=u[u.length-1]).length;d=t)break;var i=n+1;if(i0;){var n=s-1>>1;if(A[n].dist<=A[s].dist)break;d(s,n),s=n}},y=l;A.length&&A[0].dist=t;l--){o=e.children[l];f(a,o),r+=y(a)}return r},e.prototype.adjustParentBBoxes=function(e,t,s){for(var n=s;n>=0;n--)f(t[n],e)},e.prototype.condense=function(e){for(var t=e.length-1,s=void 0;t>=0;t--)0===e[t].children.length?t>0?((s=e[t-1].children).splice(s.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,s){var n=[],i=this.chooseSubtree(e,this.data,t,n);for(i.children.push(e),f(i,e);t>=0&&n[t].children.length>this.maxEntries;)this.split(n,t),t--;this.adjustParentBBoxes(e,n,t)},e.pool=[],e}();s.RBush3D=D},{quickselect:2}],2:[function(e,t,s){!function(e,n){"object"==typeof s&&void 0!==t?t.exports=n():e.quickselect=n()}(this,(function(){function e(s,n,i,a,r){for(;a>i;){if(a-i>600){var l=a-i+1,o=n-i+1,c=Math.log(l),u=.5*Math.exp(2*c/3),h=.5*Math.sqrt(c*u*(l-u)/l)*(o-l/2<0?-1:1);e(s,n,Math.max(i,Math.floor(n-o*u/l+h)),Math.min(a,Math.floor(n+(l-o)*u/l+h)),r)}var p=s[n],A=i,d=a;for(t(s,i,n),r(s[a],p)>0&&t(s,i,a);A0;)d--}0===r(s[i],p)?t(s,i,d):t(s,++d,a),d<=n&&(i=d+1),n<=d&&(a=d-1)}}function t(e,t,s){var n=e[t];e[t]=e[s],e[s]=n}function s(e,t){return et?1:0}return function(t,n,i,a,r){e(t,n,i||0,a||t.length-1,r||s)}}))},{}]},{},[1])(1)}));var ho=co.exports.RBush3D,po=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function s(e,t){var s={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function n(){(0==s.dir&&s.pos.x+1>=s.right||1==s.dir&&s.pos.y+1>=s.bottom||2==s.dir&&s.pos.x-1<=s.left-1||3==s.dir&&s.pos.y-1<=s.top-1)&&(s.dir=(s.dir+1)%4,0==s.dir&&s.left++,1==s.dir&&s.top++,2==s.dir&&s.right--,3==s.dir&&s.bottom--),0==s.dir&&s.pos.x++,1==s.dir&&s.pos.y++,2==s.dir&&s.pos.x--,3==s.dir&&s.pos.y--}for(var i=[],a=e*t;i.lengthp&&(u.push(h),h=[],p=l),h.push(d),p-=f}}while(Ap&&(u.push(A),A=[],p=l),A.push(e),p-=s})),A.length&&u.push(A);var d={};return u.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:u,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,n.maxPolygonsPerCluster),{clusters:{total:r.clusters.length},clusteringResult:r});l+=o.clusters.total,console.log("Total clusters: "+l);var c=[];return o.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){c.push(e.id)}))})),o.orderedEntityIds=c,o}; + **/let hr=null;function pr(e,t){const s=3*e,n=3*t;let i,a,r,l,o,c;const u=Math.min(i=hr[s],a=hr[s+1],r=hr[s+2]),h=Math.min(l=hr[n],o=hr[n+1],c=hr[n+2]);if(u!==h)return u-h;const p=Math.max(i,a,r),A=Math.max(l,o,c);return p!==A?p-A:0}let Ar=null;function dr(e,t){let s=Ar[2*e]-Ar[2*t];return 0!==s?s:Ar[2*e+1]-Ar[2*t+1]}function fr(e,t,s=!1){const n=e.positionsCompressed||[],i=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e>t;s.sort(pr);const n=new Int32Array(e.length);for(let t=0,i=s.length;te[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}Ar=new Int32Array(e),t.sort(dr);const s=new Int32Array(e.length);for(let n=0,i=t.length;nt){let s=e;e=t,t=s}function s(s,n){return s!==e?e-s:n!==t?t-n:0}let n=0,i=(a.length>>1)-1;for(;n<=i;){const e=i+n>>1,t=s(a[2*e],a[2*e+1]);if(t>0)n=e+1;else{if(!(t<0))return e;i=e-1}}return-n-1}const l=new Int32Array(a.length/2);l.fill(0);const o=n.length/3;if(o>8*(1<p.maxNumPositions&&(p=h()),p.bucketNumber>8)return[e];let d;-1===c[o]&&(c[o]=p.numPositions++,p.positionsCompressed.push(n[3*o]),p.positionsCompressed.push(n[3*o+1]),p.positionsCompressed.push(n[3*o+2])),-1===c[u]&&(c[u]=p.numPositions++,p.positionsCompressed.push(n[3*u]),p.positionsCompressed.push(n[3*u+1]),p.positionsCompressed.push(n[3*u+2])),-1===c[A]&&(c[A]=p.numPositions++,p.positionsCompressed.push(n[3*A]),p.positionsCompressed.push(n[3*A+1]),p.positionsCompressed.push(n[3*A+2])),p.indices.push(c[o]),p.indices.push(c[u]),p.indices.push(c[A]),(d=r(o,u))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]])),(d=r(o,A))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]])),(d=r(u,A))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]]))}const A=t/8*2,d=t/8,f=2*n.length+(i.length+a.length)*A;let I=0,y=-n.length/3;return u.forEach((e=>{I+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*d,y+=e.positionsCompressed.length/3})),I>f?[e]:(s&&function(e,t){const s={},n={};let i=0;e.forEach((e=>{const t=e.indices,a=e.edgeIndices,r=e.positionsCompressed;for(let e=0,n=t.length;e0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl,s=e._lightsState;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uLightAmbient=n.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];const i=s.lights;let a;for(let e=0,t=i.length;e0;let i;const a=[];a.push("#version 300 es"),a.push("// TrianglesDataTextureColorRenderer vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("uniform mat4 sceneModelWorldMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),a.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),a.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),a.push("uniform highp sampler2D uTextureModelMatrices;"),a.push("uniform vec3 uCameraEyeRtc;"),a.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("out float isPerspective;")),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e> 3) & 4095;"),a.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),a.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),a.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),a.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),a.push("if (int(flags.x) != renderPass) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("} else {"),a.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),a.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),a.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),a.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),a.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),a.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),a.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),a.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),a.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),a.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),a.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),a.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),a.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),a.push("if (color.a == 0u) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("};"),a.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),a.push("vec3 position;"),a.push("position = positions[gl_VertexID % 3];"),a.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),a.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("} else {"),a.push("if (viewNormal.z < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("}"),a.push("}"),a.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),a.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),a.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Er=new Float32Array([1,1,1]),br=h.vec3(),Dr=h.vec3(),Pr=h.vec3(),Rr=h.vec3(),Cr=h.mat4();class _r{constructor(e,t){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=this._scene,i=n.camera,a=t.model,r=n.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=a,d=i.viewMatrix;if(!this._program&&(this._allocate(),this.errors))return;let f,I;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,l)),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const e=br;if(c){const t=Dr;h.transformPoint3(p,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=B(d,e,Cr),I=Pr,I[0]=i.eye[0]-e[0],I[1]=i.eye[1]-e[1],I[2]=i.eye[2]-e[2]}else f=d,I=i.eye;if(r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s===Zs.SILHOUETTE_XRAYED){const e=n.xrayMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Zs.SILHOUETTE_HIGHLIGHTED){const e=n.highlightMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Zs.SILHOUETTE_SELECTED){const e=n.selectedMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else r.uniform4fv(this._uColor,Er);if(n.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const y=n._sectionPlanesState.sectionPlanes.length;if(y>0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uColor=s.getLocation("color"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture silhouette vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.y) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("viewNormal = -viewNormal;"),s.push("}"),s.push("} else {"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("viewNormal = -viewNormal;"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = color;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Br=new Float32Array([0,0,0,1]),Or=h.vec3(),Sr=h.vec3();h.vec3();const Nr=h.vec3(),xr=h.mat4();class Lr{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=Or;if(I){const t=Sr;h.transformPoint3(p,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=B(d,e,xr)}else f=d;if(r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),s===Zs.EDGES_XRAYED){const e=i.xrayMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Zs.EDGES_HIGHLIGHTED){const e=i.highlightMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Zs.EDGES_SELECTED){const e=i.selectedMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else r.uniform4fv(this._uColor,Br);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(r.LINES,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(r.LINES,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(r.LINES,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uColor=s.getLocation("color"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.z) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),e.logarithmicDepthBufferEnabled&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Mr=h.vec3(),Fr=h.vec3(),Hr=h.vec3(),Ur=h.mat4();class Gr{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=a.viewMatrix;if(!this._program&&(this._allocate(),this.errors))return;let f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=Mr;if(I){const t=Fr;h.transformPoint3(p,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=B(d,e,Ur)}else f=d;r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(r.LINES,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(r.LINES,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(r.LINES,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureEdgesColorRenderer"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled,s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.z) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push(" vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vec4 rgb = vec4(color.rgba);"),s.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureEdgesColorRenderer"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const jr=h.vec3(),Vr=h.vec3(),kr=h.vec3(),Qr=h.mat4();class Wr{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){if(!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n;let d,f;o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=jr;if(I){const t=h.transformPoint3(p,c,Vr);e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],d=B(a.viewMatrix,e,Qr),f=kr,f[0]=a.eye[0]-e[0],f[1]=a.eye[1]-e[1],f[2]=a.eye[2]-e[2]}else d=a.viewMatrix,f=a.eye;if(r.uniform2fv(this._uPickClipPos,e.pickClipPos),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),r.uniform3fv(this._uCameraEyeRtc,f),r.uniform1i(this._uRenderPass,s),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPickClipPos=s.getLocation("pickClipPos"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("uniform vec2 pickClipPos;"),s.push("vec4 remapClipPos(vec4 clipPos) {"),s.push(" clipPos.xy /= clipPos.w;"),s.push(" clipPos.xy -= pickClipPos;"),s.push(" clipPos.xy *= clipPos.w;"),s.push(" return clipPos;"),s.push("}"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("smooth out vec4 vWorldPosition;"),s.push("flat out uvec4 vFlags2;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uvec4 vFlags2;");for(var i=0;i 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outPickColor = vPickColor; "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const zr=h.vec3(),Kr=h.vec3(),Yr=h.vec3(),Xr=h.vec3(),qr=h.mat4();class Jr{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=e.pickViewMatrix||a.viewMatrix;let f,I;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const t=zr;if(c){const e=Kr;h.transformPoint3(p,c,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],f=B(d,t,qr),I=Yr,I[0]=a.eye[0]-t[0],I[1]=a.eye[1]-t[1],I[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else f=d,I=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform2fv(this._uPickClipPos,e.pickClipPos),r.uniform1f(this._uPickZNear,e.pickZNear),r.uniform1f(this._uPickZFar,e.pickZFar),r.uniformMatrix4fv(this._uWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPickClipPos=s.getLocation("pickClipPos"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick depth vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("uniform vec2 pickClipPos;"),s.push("vec4 remapClipPos(vec4 clipPos) {"),s.push(" clipPos.xy /= clipPos.w;"),s.push(" clipPos.xy -= pickClipPos;"),s.push(" clipPos.xy *= clipPos.w;"),s.push(" return clipPos;"),s.push("}"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var i=0;i 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outPackedDepth = packDepth(zNormalizedDepth); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Zr=h.vec3(),$r=h.vec3(),el=h.vec3(),tl=h.vec3(),sl=h.vec3(),nl=h.mat4();class il{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=t.aabb,f=e.pickViewMatrix||a.viewMatrix,I=Zr;let y,m;I[0]=h.safeInv(d[3]-d[0])*h.MAX_INT,I[1]=h.safeInv(d[4]-d[1])*h.MAX_INT,I[2]=h.safeInv(d[5]-d[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(I[0]),e.snapPickCoordinateScale[1]=h.safeInv(I[1]),e.snapPickCoordinateScale[2]=h.safeInv(I[2]),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const v=0!==c[0]||0!==c[1]||0!==c[2],w=0!==u[0]||0!==u[1]||0!==u[2];if(v||w){const t=$r;if(v){const e=h.transformPoint3(p,c,el);t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],y=B(f,t,nl),m=tl,m[0]=a.eye[0]-t[0],m[1]=a.eye[1]-t[1],m[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else y=f,m=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,m),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,y),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const g=i._sectionPlanesState.sectionPlanes.length;if(g>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*g,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(T,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(T,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(T,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 uSnapVectorA;"),s.push("uniform vec2 uSnapInvVectorAB;"),s.push("vec3 positions[3];"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),s.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vViewPosition;"),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("{"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vViewPosition = clipPos;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles dataTexture pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int uLayerNumber;"),s.push("uniform vec3 uCoordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(let t=0,n=e.sectionPlanes.length;t 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, uLayerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const al=h.vec3(),rl=h.vec3(),ll=h.vec3(),ol=h.vec3(),cl=h.vec3(),ul=h.mat4();class hl{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=t.aabb,f=e.pickViewMatrix||a.viewMatrix,I=al;let y,m;I[0]=h.safeInv(d[3]-d[0])*h.MAX_INT,I[1]=h.safeInv(d[4]-d[1])*h.MAX_INT,I[2]=h.safeInv(d[5]-d[2])*h.MAX_INT,e.snapPickCoordinateScale[0]=h.safeInv(I[0]),e.snapPickCoordinateScale[1]=h.safeInv(I[1]),e.snapPickCoordinateScale[2]=h.safeInv(I[2]),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const v=0!==c[0]||0!==c[1]||0!==c[2],w=0!==u[0]||0!==u[1]||0!==u[2];if(v||w){const t=rl;if(v){const e=ll;h.transformPoint3(p,c,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],y=B(f,t,ul),m=ol,m[0]=a.eye[0]-t[0],m[1]=a.eye[1]-t[1],m[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else y=f,m=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,m),r.uniform2fv(this._uVectorA,e.snapVectorA),r.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,y),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const g=i._sectionPlanesState.sectionPlanes.length;if(g>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*g,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureSnapDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 uVectorAB;"),s.push("uniform vec2 uInverseVectorAB;"),s.push("vec3 positions[3];"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),s.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("{"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (solid != 1u) {"),s.push(" if (isPerspectiveMatrix(projMatrix)) {"),s.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" viewNormal = -viewNormal;"),s.push(" }"),s.push(" } else {"),s.push(" if (viewNormal.z < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" viewNormal = -viewNormal;"),s.push(" }"),s.push(" }"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureSnapDepthBufInitRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int uLayerNumber;"),s.push("uniform vec3 uCoordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(let t=0,n=e.sectionPlanes.length;t 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const pl=h.vec3();class Al{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);let u=a.eye;const h=[u[0]-c[0],u[1]-c[1],u[2]-c[2]];if(r.uniform3fv(this._uCameraEyeRtc,h),r.uniform1i(this._uRenderPass,s),r.uniform3fv(this._uCameraEyeRtc,h),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform2fv(this._uPickClipPos,e.pickClipPos),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const p=i._sectionPlanesState.sectionPlanes.length;if(p>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*p,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPickClipPos=s.getLocation("pickClipPos"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick normals vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureCameraMatrices;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("uniform vec2 pickClipPos;"),s.push("vec4 remapClipPos(vec4 clipPos) {"),s.push(" clipPos.xy /= clipPos.w;"),s.push(" clipPos.xy -= pickClipPos;"),s.push(" clipPos.xy *= clipPos.w;"),s.push(" return clipPos;"),s.push("}"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));"),s.push("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));"),s.push("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("normal = -normal;"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("normal = -normal;"),s.push("}"),s.push("}"),s.push("}"),s.push("normal = -normal;"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vWorldNormal = normal.xyz;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.w;")),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var i=0;i 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const dl=h.vec3(),fl=h.vec3(),Il=h.vec3(),yl=h.vec3(),ml=h.mat4();class vl{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=n,d=e.pickViewMatrix||a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let f,I;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const e=dl;if(c){const t=fl;h.transformPoint3(p,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=B(d,e,ml),I=Il,I[0]=a.eye[0]-e[0],I[1]=a.eye[1]-e[1],I[2]=a.eye[2]-e[2]}else f=d,I=a.eye;r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out vec4 vFlags2;")),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.x) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push(" if (isPerspectiveMatrix(projMatrix)) {"),s.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix; * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" }"),s.push(" } else {"),s.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push(" if (viewNormal.z < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" }"),s.push(" }"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix; * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in vec4 vFlags2;");for(let t=0;t 0.0);"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const wl=h.vec3(),gl=h.vec3(),Tl=h.vec3(),El=h.vec3(),bl=h.mat4();class Dl{constructor(e){this._scene=e,this._allocate(),this._hash=this._getHash()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=this._scene,i=n.camera,a=t.model,r=n.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:p,rotationMatrixConjugate:A}=a;if(!this._program&&(this._allocate(),this.errors))return;let d,f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,l)),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=wl;if(I){const t=h.transformPoint3(p,c,gl);e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],d=B(i.viewMatrix,e,bl),f=Tl,f[0]=i.eye[0]-e[0],f[1]=i.eye[1]-e[1],f[2]=i.eye[2]-e[2]}else d=i.viewMatrix,f=i.eye;if(r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,A),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),r.uniform3fv(this._uCameraEyeRtc,f),r.uniform1i(this._uRenderPass,s),n.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const m=n._sectionPlanesState.sectionPlanes.length;if(m>0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture draw vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out highp vec2 vHighPrecisionZW;"),s&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in highp vec2 vHighPrecisionZW;"),n.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Pl=h.vec3(),Rl=h.vec3(),Cl=h.vec3(),_l=h.vec3(),Bl=h.mat4();class Ol{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:p}=n,A=a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let d,f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(t));const I=0!==o[0]||0!==o[1]||0!==o[2],y=0!==c[0]||0!==c[1]||0!==c[2];if(I||y){const e=Pl;if(I){const t=Rl;h.transformPoint3(u,o,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=c[0],e[1]+=c[1],e[2]+=c[2],d=B(A,e,Bl),f=Cl,f[0]=a.eye[0]-e[0],f[1]=a.eye[1]-e[1],f[2]=a.eye[2]-e[2]}else d=A,f=a.eye;r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),r.uniformMatrix4fv(this._uViewNormalMatrix,!1,a.viewNormalMatrix),r.uniformMatrix4fv(this._uWorldNormalMatrix,!1,n.worldNormalMatrix);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0,s=[];return s.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&s.push("#extension GL_EXT_frag_depth : enable"),s.push("uniform int renderPass;"),s.push("attribute vec3 position;"),e.entityOffsetsEnabled&&s.push("attribute vec3 offset;"),s.push("attribute vec3 normal;"),s.push("attribute vec4 color;"),s.push("attribute vec4 flags;"),s.push("attribute vec4 flags2;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 worldNormalMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 viewNormalMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("varying float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out vec4 vFlags2;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("if (int(flags.x) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(ct.SUPPORTED_EXTENSIONS.EXT_frag_depth?s.push("vFragDepth = 1.0 + clipPos.w;"):(s.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),s.push("clipPos.z *= clipPos.w;")),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(let e=0;e 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&ct.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Sl=h.vec3();class Nl{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerObjectIdPositionsDecodeMatrix),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},1),this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerVertexIdCoordinates),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},2),this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerObjectIdColorsAndFlags),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},3),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform2fv(this._uPickClipPos,e.pickClipPos),r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix);const c=e.pickViewMatrix||a.viewMatrix,u=o?B(c,o):c;if(r.uniformMatrix4fv(this._uViewMatrix,!1,u),r.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const h=i._sectionPlanesState.sectionPlanes.length;if(h>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*h,a=n.renderFlags;for(let t=0;t0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds8Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices8Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds16Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices16Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds32Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices32Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new ot(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPickClipPos=s.getLocation("pickClipPos"),this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick flat normals vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in uvec3 packedVertexId;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform isampler2D uTexturePerPolygonIdNormals;"),s.push("uniform usampler2D uTexturePerPolygonIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("uniform vec2 pickClipPos;"),s.push("vec4 remapClipPos(vec4 clipPos) {"),s.push(" clipPos.xy /= clipPos.w;"),s.push(" clipPos.xy -= pickClipPos;"),s.push(" clipPos.xy *= clipPos.w;"),s.push(" return clipPos;"),s.push("}"),s.push("out vec4 vWorldPosition;"),t&&s.push("out int vFlags2;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_normal_index = polygonIndex & 4095;"),s.push("int v_normal_index = polygonIndex >> 12;"),s.push("int h_packed_object_id_index = ((polygonIndex >> 3) / 2) & 4095;"),s.push("int v_packed_object_id_index = ((polygonIndex >> 3) / 2) >> 12;"),s.push("ivec3 packedObjectId = ivec3(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).rgb);"),s.push("int objectIndex;"),s.push("if (((polygonIndex >> 3) % 2) == 0) {"),s.push(" objectIndex = (packedObjectId.r << 4) + (packedObjectId.g >> 4);"),s.push("} else {"),s.push(" objectIndex = ((packedObjectId.g & 15) << 8) + packedObjectId.b;"),s.push("}"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("int h_index = polygonIndex & 4095;"),s.push("int v_index = polygonIndex >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position1 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("vec3 position2 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("vec3 position3 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(position3 - position1, position2 - position1));"),s.push("int vertexNumber = gl_VertexID % 3;"),s.push("vec3 position;"),s.push("if (vertexNumber == 0) position = position1;"),s.push("else if (vertexNumber == 1) position = position2;"),s.push("else position = position3;"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags2 = flags2.r;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick flat normals fragment shader"),n.push("#extension GL_OES_standard_derivatives : enable"),e.logarithmicDepthBufferEnabled&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in int vFlags2;");for(var i=0;i 0;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${h.MAX_INT}), 1.0);`),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class xl{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._vertexDepthRenderer&&!this._vertexDepthRenderer.getValid()&&(this._vertexDepthRenderer.destroy(),this._vertexDepthRenderer=null),this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Tr(this._scene,!1)),this._colorRenderer}get colorRendererWithSAO(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new Tr(this._scene,!0)),this._colorRendererWithSAO}get colorQualityRendererWithSAO(){return this._colorQualityRendererWithSAO||(this._colorQualityRendererWithSAO=new TrianglesDataTextureColorQualityRenderer(this._scene,!0)),this._colorQualityRendererWithSAO}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new _r(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Dl(this._scene)),this._depthRenderer}get normalsRenderer(){return this._normalsRenderer||(this._normalsRenderer=new Ol(this._scene)),this._normalsRenderer}get edgesRenderer(){return this._edgesRenderer||(this._edgesRenderer=new Lr(this._scene)),this._edgesRenderer}get edgesColorRenderer(){return this._edgesColorRenderer||(this._edgesColorRenderer=new Gr(this._scene)),this._edgesColorRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Wr(this._scene)),this._pickMeshRenderer}get pickNormalsRenderer(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Al(this._scene)),this._pickNormalsRenderer}get pickNormalsFlatRenderer(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new Nl(this._scene)),this._pickNormalsFlatRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Jr(this._scene)),this._pickDepthRenderer}get vertexDepthRenderer(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new il(this._scene)),this._vertexDepthRenderer}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new hl(this._scene)),this._snapDepthBufInitRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new vl(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorQualityRendererWithSAO&&this._colorQualityRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._vertexDepthRenderer&&this._vertexDepthRenderer.destroy(),this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const Ll={};class Ml{constructor(){this.positionsCompressed=[],this.metallicRoughness=[],this.indices8Bits=[],this.indices16Bits=[],this.indices32Bits=[],this.edgeIndices8Bits=[],this.edgeIndices16Bits=[],this.edgeIndices32Bits=[],this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]}}class Fl{constructor(){this.texturePerObjectIdColorsAndFlags=null,this.texturePerObjectIdOffsets=null,this.texturePerObjectIdPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}finalize(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}bindCommonTextures(e,t,s,n,i,a){this.texturePerObjectIdPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,s,2),this.texturePerObjectIdColorsAndFlags.bindTexture(e,n,3),this.texturePerObjectIdOffsets.bindTexture(e,a,4)}bindTriangleIndicesTextures(e,t,s,n){this.indicesPortionIdsPerBitnessTextures[n].bindTexture(e,t,5),this.indicesPerBitnessTextures[n].bindTexture(e,s,6)}bindEdgeIndicesTextures(e,t,s,n){this.edgeIndicesPortionIdsPerBitnessTextures[n].bindTexture(e,t,5),this.edgeIndicesPerBitnessTextures[n].bindTexture(e,s,6)}}class Hl{constructor(e,t,s,n,i=null){this._gl=e,this._texture=t,this._textureWidth=s,this._textureHeight=n,this._textureData=i}bindTexture(e,t,s){return e.bindTexture(t,this,s)}bind(e){return this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,this._texture),!0}unbind(e){}}const Ul={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(Ul,null,4));let e=0;Object.keys(Ul).forEach((t=>{t.startsWith("size")&&(e+=Ul[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/Ul.totalPolygons).toFixed(2)}`);let t={};Object.keys(Ul).forEach((s=>{s.startsWith("size")&&(t[s]=`${(Ul[s]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};class Gl{disableBindedTextureFiltering(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}generateTextureForColorsAndFlags(e,t,s,n,i,a,r){const l=t.length;this.numPortions=l;const o=4096,c=Math.ceil(l/512);if(0===c)throw"texture height===0";const u=new Uint8Array(16384*c);Ul.sizeDataColorsAndFlags+=u.byteLength,Ul.numberOfTextures++;for(let e=0;e>24&255,n[e]>>16&255,n[e]>>8&255,255&n[e]],32*e+16),u.set([i[e]>>24&255,i[e]>>16&255,i[e]>>8&255,255&i[e]],32*e+20),u.set([a[e]>>24&255,a[e]>>16&255,a[e]>>8&255,255&a[e]],32*e+24),u.set([r[e]?1:0,0,0,0],32*e+28);const h=e.createTexture();return e.bindTexture(e.TEXTURE_2D,h),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,o,c),e.texSubImage2D(e.TEXTURE_2D,0,0,0,o,c,e.RGBA_INTEGER,e.UNSIGNED_BYTE,u,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new Hl(e,h,o,c,u)}generateTextureForObjectOffsets(e,t){const s=512,n=Math.ceil(t/s);if(0===n)throw"texture height===0";const i=new Float32Array(1536*n).fill(0);Ul.sizeDataTextureOffsets+=i.byteLength,Ul.numberOfTextures++;const a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,s,n),e.texSubImage2D(e.TEXTURE_2D,0,0,0,s,n,e.RGB,e.FLOAT,i,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new Hl(e,a,s,n,i)}generateTextureForPositionsDecodeMatrices(e,t,s){const n=t.length;if(0===n)throw"num decode+entity matrices===0";const i=2048,a=Math.ceil(n/512),r=new Float32Array(8192*a);Ul.sizeDataPositionDecodeMatrices+=r.byteLength,Ul.numberOfTextures++;const l=h.mat4();for(let e=0;e{s._compile()})),e.on("destroyed",(()=>{delete Ll[t],s._destroy()}))),s}(e.scene),this.model=e,this._buffer=new Ml,this._dataTextureState=new Fl,this._dataTextureGenerator=new Gl,this._state=new ye({origin:h.vec3(t.origin),metallicRoughnessBuf:null,positionsDecodeMatrix:h.mat4(),textureState:this._dataTextureState,numIndices8Bits:0,numIndices16Bits:0,numIndices32Bits:0,numEdgeIndices8Bits:0,numEdgeIndices16Bits:0,numEdgeIndices32Bits:0,numVertices:0}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._subPortions=[],this._portionToSubPortionsMap=[],this._bucketGeometries={},this.aabb=h.collapseAABB3(),this._numUpdatesInFrame=0,this._finalized=!1}canCreatePortion(e){if(this._finalized)throw"Already finalized";const t=e.buckets.length;this._numPortions+t>65536&&Ul.cannotCreatePortion.because10BitsObjectId++;let s=this._numPortions+t<=65536;const n=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#0`:`${e.id}#0`;if(!this._bucketGeometries[n]){const t=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits);let n=0,i=0;e.buckets.forEach((e=>{n+=e.positionsCompressed.length/3,i+=e.indices.length/3})),(this._state.numVertices+n>16777216||t+i>16777216)&&Ul.cannotCreatePortion.becauseTextureSize++,s&&=this._state.numVertices+n<=16777216&&t+i<=16777216}return s}createPortion(e){if(this._finalized)throw"Already finalized";const t=[],s=e.worldAABB;e.buckets.forEach(((n,i)=>{const a=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#${i}`:`${e.id}#${i}`;let r=this._bucketGeometries[a];r||(r=this._createBucketGeometry(e,n),this._bucketGeometries[a]=r);const l=h.collapseAABB3(Wl),o=this._createSubPortion(e,r,n,l);h.expandAABB3(s,l),t.push(o)}));const n=this._state.origin;0===n[0]&&0===n[1]&&0===n[2]||(s[0]+=n[0],s[1]+=n[1],s[2]+=n[2],s[3]+=n[0],s[4]+=n[1],s[5]+=n[2]),h.expandAABB3(this.aabb,s);const i=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(t),this.model.numPortions++,i}_createBucketGeometry(e,t){if(t.indices){const e=8*Math.ceil(t.indices.length/3/8)*3;Ul.overheadSizeAlignementIndices+=2*(e-t.indices.length);const s=new Uint32Array(e);s.fill(0),s.set(t.indices),t.indices=s}if(t.edgeIndices){const e=8*Math.ceil(t.edgeIndices.length/2/8)*2;Ul.overheadSizeAlignementEdgeIndices+=2*(e-t.edgeIndices.length);const s=new Uint32Array(e);s.fill(0),s.set(t.edgeIndices),t.edgeIndices=s}const s=t.positionsCompressed,n=t.indices,i=t.edgeIndices,a=this._buffer,r=a.positionsCompressed.length/3,l=s.length/3;for(let e=0,t=s.length;e0){let e,s=3*t.numTriangles;t.numVertices<=256?(e=c.perTriangleNumberPortionId8Bits,u.numIndices8Bits+=s,Ul.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(e=c.perTriangleNumberPortionId16Bits,u.numIndices16Bits+=s,Ul.totalPolygons16Bits+=t.numTriangles):(e=c.perTriangleNumberPortionId32Bits,u.numIndices32Bits+=s,Ul.totalPolygons32Bits+=t.numTriangles),Ul.totalPolygons+=t.numTriangles;for(let s=0;s0){let e,s=2*t.numEdges;t.numVertices<=256?(e=c.perEdgeNumberPortionId8Bits,u.numEdgeIndices8Bits+=s,Ul.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(e=c.perEdgeNumberPortionId16Bits,u.numEdgeIndices16Bits+=s,Ul.totalEdges16Bits+=t.numEdges):(e=c.perEdgeNumberPortionId32Bits,u.numEdgeIndices32Bits+=s,Ul.totalEdges32Bits+=t.numEdges),Ul.totalEdges+=t.numEdges;for(let s=0;s0&&(t.texturePerEdgeIdPortionIds8Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId8Bits)),n.perEdgeNumberPortionId16Bits.length>0&&(t.texturePerEdgeIdPortionIds16Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId16Bits)),n.perEdgeNumberPortionId32Bits.length>0&&(t.texturePerEdgeIdPortionIds32Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId32Bits)),n.indices8Bits.length>0&&(t.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(s,n.indices8Bits)),n.indices16Bits.length>0&&(t.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(s,n.indices16Bits)),n.indices32Bits.length>0&&(t.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(s,n.indices32Bits)),n.edgeIndices8Bits.length>0&&(t.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(s,n.edgeIndices8Bits)),n.edgeIndices16Bits.length>0&&(t.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(s,n.edgeIndices16Bits)),n.edgeIndices32Bits.length>0&&(t.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(s,n.edgeIndices32Bits)),t.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(()=>{this._deferredSetFlagsDirty&&this._uploadDeferredFlags(),this._numUpdatesInFrame=0}))}isEmpty(){return 0===this._numPortions}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&j&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&V&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,true),this._setFlags2(e,t,true)}flushInitFlags(){this._setDeferredFlags(),this._setDeferredFlags2()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}_beginDeferredFlags(){this._deferredSetFlagsActive=!0}_uploadDeferredFlags(){if(console.info("_uploadDeferredFlags"),this._deferredSetFlagsActive=!1,!this._deferredSetFlagsDirty)return;this._deferredSetFlagsDirty=!1;const e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdColorsAndFlags._textureWidth,t.texturePerObjectIdColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectIdColorsAndFlags._textureData),e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdOffsets._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdOffsets._textureWidth,t.texturePerObjectIdOffsets._textureHeight,e.RGB,e.FLOAT,t.texturePerObjectIdOffsets._textureData)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){const s=this._portionToSubPortionsMap[e];for(let e=0,n=s.length;e=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),n.bindTexture(n.TEXTURE_2D,s.texturePerObjectIdColorsAndFlags._texture),n.texSubImage2D(n.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,n.RGBA_INTEGER,n.UNSIGNED_BYTE,kl)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s,n=!1){const i=this._portionToSubPortionsMap[e];for(let e=0,a=i.length;e=10&&this._beginDeferredFlags(),d.bindTexture(d.TEXTURE_2D,A.texturePerObjectIdColorsAndFlags._texture),d.texSubImage2D(d.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,d.RGBA_INTEGER,d.UNSIGNED_BYTE,kl))}_setDeferredFlags(){}_setFlags2(e,t,s=!1){const n=this._portionToSubPortionsMap[e];for(let e=0,i=n.length;e=10&&this._beginDeferredFlags(),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectIdColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,kl))}_setDeferredFlags2(){}setOffset(e,t){const s=this._portionToSubPortionsMap[e];for(let e=0,n=s.length;e=10&&this._beginDeferredFlags(),n.bindTexture(n.TEXTURE_2D,s.texturePerObjectIdOffsets._texture),n.texSubImage2D(n.TEXTURE_2D,0,0,e,1,1,n.RGB,n.FLOAT,Ql))}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?this._dataTextureRenderers.colorRendererWithSAO&&this._dataTextureRenderers.colorRendererWithSAO.drawLayer(t,this,Zs.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}_updateBackfaceCull(e,t){const s=this.model.backfaces||e.sectioned;if(t.backfaces!==s){const e=t.gl;s?e.disable(e.CULL_FACE):e.enable(e.CULL_FACE),t.backfaces=s}}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Zs.COLOR_TRANSPARENT))}drawDepth(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.depthRenderer&&this._dataTextureRenderers.depthRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}drawNormals(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.normalsRenderer&&this._dataTextureRenderers.normalsRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_XRAYED))}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_HIGHLIGHTED))}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Zs.SILHOUETTE_SELECTED))}drawEdgesColorOpaque(e,t){this.model.scene.logarithmicDepthBufferEnabled?this.model.scene._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),this.model.scene._loggedWarning=!0):this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Zs.EDGES_COLOR_OPAQUE)}drawEdgesColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Zs.EDGES_COLOR_TRANSPARENT)}drawEdgesHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Zs.EDGES_HIGHLIGHTED)}drawEdgesSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Zs.EDGES_SELECTED)}drawEdgesXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Zs.EDGES_XRAYED)}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.occlusionRenderer&&this._dataTextureRenderers.occlusionRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}drawShadow(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.shadowRenderer&&this._dataTextureRenderers.shadowRenderer.drawLayer(t,this,Zs.COLOR_OPAQUE))}setPickMatrices(e,t){}drawPickMesh(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickMeshRenderer&&this._dataTextureRenderers.pickMeshRenderer.drawLayer(t,this,Zs.PICK))}drawPickDepths(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,Zs.PICK))}drawSnapInitDepthBuf(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.snapDepthBufInitRenderer&&this._dataTextureRenderers.snapDepthBufInitRenderer.drawLayer(t,this,Zs.PICK))}drawSnapDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.vertexDepthRenderer&&this._dataTextureRenderers.vertexDepthRenderer.drawLayer(t,this,Zs.PICK))}drawPickNormals(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickNormalsRenderer&&this._dataTextureRenderers.pickNormalsRenderer.drawLayer(t,this,Zs.PICK))}destroy(){if(this._destroyed)return;const e=this._state;e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}const Xl=h.vec3();h.mat4();const ql=h.vec3([1,1,1]),Jl=h.vec3([0,0,0]),Zl=h.vec3([0,0,0]),$l=h.identityQuaternion(),eo=h.identityMat4(),to=new Uint8Array([255,255,255]);class so extends C{constructor(e,t={}){super(e,t),this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!0,this._vboBatchingLayerScratchMemory=(Js++,qs),this._textureTranscoder=t.textureTranscoder||rr(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize,this._aabb=h.collapseAABB3(),this._aabbDirty=!0,this._quantizationRanges={},this._vboInstancingLayers={},this._vboBatchingLayers={},this._dtxLayers={},this._meshList=[],this.layerList=[],this._entityList=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this._scheduledMeshes={},this.renderFlags=new Gt,this.numGeometries=0,this.numPortions=0,this.numVisibleLayerPortions=0,this.numTransparentLayerPortions=0,this.numXRayedLayerPortions=0,this.numHighlightedLayerPortions=0,this.numSelectedLayerPortions=0,this.numEdgesLayerPortions=0,this.numPickableLayerPortions=0,this.numClippableLayerPortions=0,this.numCulledLayerPortions=0,this.numEntities=0,this._numTriangles=0,this._numLines=0,this._numPoints=0,this._edgeThreshold=t.edgeThreshold||10,this._origin=h.vec3(t.origin||[0,0,0]),this._position=h.vec3(t.position||[0,0,0]),this._rotation=h.vec3(t.rotation||[0,0,0]),this._quaternion=h.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=h.vec4(t.quaternion||[0,0,0,1]),t.rotation&&h.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=h.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=h.mat4(),this._worldRotationMatrixConjugate=h.mat4(),this._matrix=h.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=h.mat4(),h.inverseMat4(this._matrix,this._worldNormalMatrix),h.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=h.mat4(),this._viewNormalMatrix=h.mat4(),this._viewMatrixDirty=!0,this._matrixNonIdentity=!0),this._opacity=1,this._colorize=[1,1,1],this._saoEnabled=!1!==t.saoEnabled,this._pbrEnabled=!1!==t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{this._viewMatrixDirty=!0})),this.scene.vfc.enabled&&(this._vfcManager=this.scene.vfc.getVFCManager(this)),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_createDefaultTextureSet(){const e=new Xa({id:"defaultColorTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Xa({id:"defaultMetalRoughTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new Xa({id:"defaultNormalsTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new Xa({id:"defaultEmissiveTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new Xa({id:"defaultOcclusionTexture",texture:new rs({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new Ya({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}get isPerformanceModel(){return!0}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),h.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),h.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||eo),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),h.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),h.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),h.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0}_setLocalAABBDirty(){for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,s=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,n=t.length;e{o.setImage(c,{minFilter:s,magFilter:n,wrapS:i,wrapT:a,wrapR:r,flipY:e.flipY,encoding:l}),this.glRedraw()},c.src=e.src;break;default:this._textureTranscoder?y.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],o).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,o).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new Xa({id:t,texture:o})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let s,n,i,a,r;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(a=this._textures[e.emissiveTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(r=this._textures[e.occlusionTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultOcclusionTexture;const l=new Ya({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:a,occlusionTexture:r});this._textureSets[t]=l}createMesh(e){if(void 0===e.id||null===e.id)return void this.error("[createMesh] SceneModel.createMesh() config missing: id");if(this._scheduledMeshes[e.id])return void this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`);if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return void this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`);if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),null;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),null;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),null;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),null;const t=!!this._dtxEnabled&&("triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive);if(e.origin=e.origin?h.addVec3(this._origin,e.origin,h.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||ql,s=e.position||Jl,n=e.rotation||Zl;h.eulerToQuaternion(n,"XYZ",$l),e.meshMatrix=h.composeMat4(s,$l,t,h.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Mn(e.positionsDecodeBoundary,h.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):to,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=h.vec3(),s=[];S(e.positions,s,t)&&(e.positions=s,e.origin=h.addVec3(e.origin,t,t))}if(e.positions){const t=h.collapseAABB3();e.positionsDecodeMatrix=h.mat4(),h.expandAABB3Points3(t,e.positions),e.positionsCompressed=Ln(e.positions,t,e.positionsDecodeMatrix)}e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=ve(e.positions,e.indices,null,2):e.edgeIndices=ve(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=no(e,this._enableVertexWelding&&this._enableIndexBucketing))}else{if(e.type=1,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):[255,255,255],e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.positions){const t=[];S(e.positions,t,Xl)&&(e.positions=t,e.origin=h.addVec3(e.origin,Xl,h.vec3()))}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=ve(e.positions,e.indices,null,2):e.edgeIndices=ve(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId],!e.textureSet))return void this.error(`[createMesh] Texture set not found: ${e.textureSetId} - ensure that you create it first with createTextureSet()`)}}else{if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return void this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)");if(e.geometry=this._geometries[e.geometryId],!e.geometry)return void this.error(`[createMesh] Geometry not found: ${e.geometryId} - ensure that you create it first with createGeometry()`);if(e.origin=e.origin?h.addVec3(this._origin,e.origin,h.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.matrix)e.meshMatrix=e.matrix.slice();else{const t=e.scale||ql,s=e.position||Jl,n=e.rotation||Zl;h.eulerToQuaternion(n,"XYZ",$l),e.meshMatrix=h.composeMat4(s,$l,t,h.mat4())}if(!!this._dtxEnabled&&("triangles"===e.geometry.primitive||"solid"===e.geometry.primitive||"surface"===e.geometry.primitive)){e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):to,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;let t=this._dtxBuckets[e.geometryId];t||(t=no(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=t),e.buckets=t}else e.type=0,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):to,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId]),function(e){if(e.obb=h.OBB3(),e.positionsCompressed&&e.positionsCompressed.length>0){const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positionsCompressed),Pe.decompressAABB(t,e.positionsDecodeMatrix),h.AABB3ToOBB3(t,e.obb)}else if(e.positions&&e.positions.length>0){const t=h.collapseAABB3();h.expandAABB3Points3(t,e.positions),h.AABB3ToOBB3(t,e.obb)}}(e.geometry)}e.numPrimitives=this._getNumPrimitives(e),this._vfcManager&&!this._vfcManager.finalized?this._vfcManager.addMesh(e):this._createMesh(e)}_createMesh(e){const t=new Xs(this,e.id,e.color,e.opacity);t.pickId=this.scene._renderer.getPickID(t);const s=t.pickId,n=s>>24&255,i=s>>16&255,a=s>>8&255,r=255&s;switch(e.pickColor=new Uint8Array([r,a,i,n]),e.worldAABB=h.collapseAABB3(),e.aabb=e.worldAABB,e.solid="solid"===e.primitive,t.origin=h.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e);break;case 1:t.layer=this._getVBOBatchingLayer(e);break;case 0:t.layer=this._getVBOInstancingLayer(e)}t.portionId=t.layer.createPortion(e),t.aabb=e.worldAABB,t.numPrimitives=e.numPrimitives,h.expandAABB3(this._aabb,t.aabb),this._meshes[e.id]=t,this._meshList.push(t)}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,s=e.origin,n=e.textureSetId||"-",i=e.geometryId,a=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${n}.${i}`;let r=this._vboInstancingLayers[a];if(r)return r;let l=e.textureSet;const o=e.geometry;for(;!r;)switch(o.primitive){case"triangles":case"surface":console.info(`[SceneModel ${this.id}]: creating TrianglesInstancingLayer`),r=new ta({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0,solid:!1});break;case"solid":console.info(`[SceneModel ${this.id}]: creating TrianglesInstancingLayer`),r=new ta({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0,solid:!0});break;case"lines":console.info(`[SceneModel ${this.id}]: creating LinesInstancingLayer`),r=new va({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0});break;case"points":console.info(`[SceneModel ${this.id}]: creating PointsInstancingLayer`),r=new Ka({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0})}return this._vboInstancingLayers[a]=r,this.layerList.push(r),r}createEntity(e){if(void 0===e.id?e.id=h.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=h.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;if(this._visible&&!1!==e.visible&&(t|=x),this._pickable&&!1!==e.pickable&&(t|=M),this._culled&&!1!==e.culled&&(t|=L),this._clippable&&!1!==e.clippable&&(t|=F),this._collidable&&!1!==e.collidable&&(t|=H),this._edges&&!1!==e.edges&&(t|=V),this._xrayed&&!1!==e.xrayed&&(t|=U),this._highlighted&&!1!==e.highlighted&&(t|=G),this._selected&&!1!==e.selected&&(t|=j),e.flags=t,this._vfcManager&&!this._vfcManager.finalized){for(let t=0,s=e.meshIds.length;t{}));for(let e=0,t=this.layerList.length;ee.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,s=this.layerList.length;t0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s65536?16:8)}else r=[{positionsCompressed:n,indices:i,edgeIndices:a}];return r}class io extends C{get type(){return"SectionPlane"}constructor(e,t={}){super(e,t),this._state=new ye({active:!0,pos:h.vec3(),dir:h.vec3(),dist:0}),this.active=t.active,this.pos=t.pos,this.dir=t.dir,this.scene._sectionPlaneCreated(this)}set active(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}get active(){return this._state.active}set pos(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-h.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos)}get pos(){return this._state.pos}set dir(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-h.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir)}get dir(){return this._state.dir}get dist(){return this._state.dist}flipDir(){const e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-h.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}destroy(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),super.destroy()}}class ao extends C{constructor(e,t={}){super(e,t),this._skyboxMesh=new Jt(this,{geometry:new _e(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new ss(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new ps(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}class ro{constructor(e,t){this.primLODLevels=e,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=t,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}initializeLodState(e){const t=Object.values(e.objects);if(0===t.length)return;const s={},n={};for(let e=0,i=t.length;e=this.primLODLevels[r]);r++);const l=this.primLODLevels[r]||0;l in s||(s[l]=[]),s[l].push(i),l in n||(n[l]=0),n[l]+=i.numPrimitives}this.entitiesInLOD=s,this.primCountInLOD=n}}class lo{constructor(e,t,s,n){this.id=t.id,this.scene=e,this.sceneModel=t,this.lodState=new ro(s,n),this.lodState.initializeLodState(t)}_increaseLODLevelIndex(){const e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;const t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[];for(let e=0,s=t.length;e0&&(t.consecutiveFramesWithoutTargetFps=0,s=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,s=this._decreaseLODLevelIndex()),s}resetLodCulling(){let e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}class oo extends C{constructor(e,t={}){super(e,t),this._scene=e,this._lodLevels=[2e3,600,150,80,20],this._lodManagers={},this._lodManagerList=[],this.enabled=t.enabled,this.targetFPS=t.targetFPS,this._init()}_init(){const e=new Array(4);let t=0,s=-1,n=Date.now(),i=0,a=0,r=a;this._scene.on("rendering",(()=>{if(-1!==s)for(let e=0,t=this._lodManagerList.length;e{n=Date.now(),window.requestAnimationFrame((()=>{t++;const a=Date.now();i=a-n,n=a,e[t%4]=i;let r=0;if(t>4){for(let t=0;t<4;t++)r+=e[t];s=4/r*1e3}}))})),this._scene.camera.on("matrix",(()=>{r=a})),this._scene.on("tick",(()=>{if(a-r>3)for(let e=0,t=this._lodManagerList.length;e=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},s.boxRayIntersects=function(e,t,s,n,i,a,r){var l=(e.minX-t)*i,o=(e.maxX-t)*i,c=(e.minY-s)*a,u=(e.maxY-s)*a,h=(e.minZ-n)*r,p=(e.maxZ-n)*r,A=Math.min(h,p),d=Math.max(h,p),f=Math.min(c,u),I=Math.max(c,u),y=Math.min(l,o),m=Math.max(l,o),v=Math.max(0,y,f,A);return Math.min(m,I,d)>=v?v:1/0};var g=function(e,t,s,i,a){for(var r,l=[t,s];l.length;)(s=l.pop())-(t=l.pop())<=i||(r=t+Math.ceil((s-t)/i/2)*i,n(e,r,t,s,a),l.push(t,r,r,s))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var s=this.data,n=[];if(!e(s,h(s)))return n;for(var i=[];s;){for(var a=0,r=s.children.length;a1){for(d=0,f=(u=u[u.length-1]).length;d=t)break;var i=n+1;if(i0;){var n=s-1>>1;if(A[n].dist<=A[s].dist)break;d(s,n),s=n}},y=l;A.length&&A[0].dist=t;l--){o=e.children[l];f(a,o),r+=y(a)}return r},e.prototype.adjustParentBBoxes=function(e,t,s){for(var n=s;n>=0;n--)f(t[n],e)},e.prototype.condense=function(e){for(var t=e.length-1,s=void 0;t>=0;t--)0===e[t].children.length?t>0?((s=e[t-1].children).splice(s.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,s){var n=[],i=this.chooseSubtree(e,this.data,t,n);for(i.children.push(e),f(i,e);t>=0&&n[t].children.length>this.maxEntries;)this.split(n,t),t--;this.adjustParentBBoxes(e,n,t)},e.pool=[],e}();s.RBush3D=D},{quickselect:2}],2:[function(e,t,s){!function(e,n){"object"==typeof s&&void 0!==t?t.exports=n():e.quickselect=n()}(this,(function(){function e(s,n,i,a,r){for(;a>i;){if(a-i>600){var l=a-i+1,o=n-i+1,c=Math.log(l),u=.5*Math.exp(2*c/3),h=.5*Math.sqrt(c*u*(l-u)/l)*(o-l/2<0?-1:1);e(s,n,Math.max(i,Math.floor(n-o*u/l+h)),Math.min(a,Math.floor(n+(l-o)*u/l+h)),r)}var p=s[n],A=i,d=a;for(t(s,i,n),r(s[a],p)>0&&t(s,i,a);A0;)d--}0===r(s[i],p)?t(s,i,d):t(s,++d,a),d<=n&&(i=d+1),n<=d&&(a=d-1)}}function t(e,t,s){var n=e[t];e[t]=e[s],e[s]=n}function s(e,t){return et?1:0}return function(t,n,i,a,r){e(t,n,i||0,a||t.length-1,r||s)}}))},{}]},{},[1])(1)}));var ho=co.exports.RBush3D,po=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function s(e,t){var s={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function n(){(0==s.dir&&s.pos.x+1>=s.right||1==s.dir&&s.pos.y+1>=s.bottom||2==s.dir&&s.pos.x-1<=s.left-1||3==s.dir&&s.pos.y-1<=s.top-1)&&(s.dir=(s.dir+1)%4,0==s.dir&&s.left++,1==s.dir&&s.top++,2==s.dir&&s.right--,3==s.dir&&s.bottom--),0==s.dir&&s.pos.x++,1==s.dir&&s.pos.y++,2==s.dir&&s.pos.x--,3==s.dir&&s.pos.y--}for(var i=[],a=e*t;i.lengthp&&(u.push(h),h=[],p=l),h.push(d),p-=f}}while(Ap&&(u.push(A),A=[],p=l),A.push(e),p-=s})),A.length&&u.push(A);var d={};return u.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:u,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,n.maxPolygonsPerCluster),{clusters:{total:r.clusters.length},clusteringResult:r});l+=o.clusters.total,console.log("Total clusters: "+l);var c=[];return o.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){c.push(e.id)}))})),o.orderedEntityIds=c,o}; /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT @@ -23,7 +23,7 @@ * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT */ -function Ao(e,t){t.length;const s=e.length,n=[],i=[],a=e=>{for(let s=0,n=e.meshIds.length;s{const s=t[e];let n,i;if(s.positionsCompressed){const e=Pe.getPositionsBounds(s.positionsCompressed);n=Pe.decompressPosition(e.min,s.positionsDecodeMatrix,[]),i=Pe.decompressPosition(e.max,s.positionsDecodeMatrix,[])}else{const e=Pe.getPositionsBounds(s.positions);n=e.min,i=e.max}n[0]+=s.origin[0],n[1]+=s.origin[1],n[2]+=s.origin[2],i[0]+=s.origin[0],i[1]+=s.origin[1],i[2]+=s.origin[2],h.expandAABB3Point3(l,n),h.expandAABB3Point3(l,i),o+=s.numPrimitives})),n[r]={aabb:l,numPrimitives:o,entityId:s.id}}let r,l=[],o={};if(Object.keys(n).length>0){r=function(e){const t=[];for(let s=0,n=e.length;s{s=Math.max(s,e.entity.id)}));const n=new Array(s+1);t.forEach((t=>{n[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=n,this._lastVisibleFrameOfNodes=new Array(n.length),this._lastVisibleFrameOfNodes.fill(0)}_searchVisibleNodesWithFrustumCulling(){return this._aabbTree.searchCustom(((e,t)=>this._aabbIntersectsCameraFrustum(e,t)),(e=>this._aabbContainedInCameraFrustum(e)))}_markVisibleFrameOfVisibleNodes(e,t){const s=this._lastVisibleFrameOfNodes;for(let n=0,i=e.length;nthis._frustumProps.CAM_FACTOR_1?(s|=r<0?64:128,s&=-17):s&=-33;const l=mo(h.dotVec3(i,this._frustumProps.up),a);Math.abs(l)>this._frustumProps.CAM_FACTOR_2?(s|=l<0?1024:2048,s&=-257):s&=-513}return 4&s&&8&s&&(s|=4096),64&s&&128&s&&(s|=8192),1024&s&&2048&s&&(s|=16384),e._check=s,s}}class wo{constructor(e,t){this.sceneModel=t,this.entities=[],this.meshes=[],this.finalized=!1}addEntity(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}addMesh(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}finalize(e){if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new vo,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(()=>this.applyViewFrustumCulling.call(this)))}applyViewFrustumCulling(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}destroy(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}class go extends C{constructor(e,t={}){super(e,t),this._scene=e,this._vfcManagers={},this._vfcManagerList=[],this.enabled=t.enabled,this._init()}_init(){this._scene.on("rendering",(()=>{for(let e=0,t=this._vfcManagerList.length;e
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const Eo=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class bo extends C{constructor(e,t={}){super(e,t),this._backgroundColor=h.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new To(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+h.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Ro(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Ro(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new ot(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,p=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Oo[0]=a,Oo[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,p),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Oo),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new ot(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new me(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new me(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new me(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const No=new Float32Array(Uo(17,[0,1])),xo=new Float32Array(Uo(17,[1,0])),Lo=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Ho(n,t));return s}(17,4)),Mo=new Float32Array(2);class Fo{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new ot(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new me(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new me(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new me(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Mo[0]=r,Mo[1]=l,n.uniform2fv(this._uViewport,Mo),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,xo):n.uniform2fv(this._uSampleOffsets,No),n.uniform1fv(this._uSampleWeights,Lo);const p=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,p,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Ho(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function Uo(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Go{constructor(e){this.scene=e,this._renderBuffersBasic={},this._renderBuffersScaled={}}getRenderBuffer(e,t){const s=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled;let n=s[e];return n||(n=new Ss(this.scene.canvas.canvas,this.scene.canvas.gl,t),s[e]=n),n}destroy(){for(let e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(let e in this._renderBuffersScaled)this._renderBuffersScaled[e].destroy()}}const jo=function(t,s){s=s||{};const n=new Do(t),i=t.canvas.canvas,a=t.canvas.gl,r=!!s.transparent,l=s.alphaDepthMask,o=new e({});let c={},u={},p=!0,d=!0,f=!0,I=!0,y=!0,m=!0,v=!0,w=!0;const g=new Go(t);let T=!1;const E=new So(t),b=new Fo(t);function D(){p&&(!function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e],s=t.drawableMap,n=t.drawableListPreCull;let i=0;for(let e in s)s.hasOwnProperty(e)&&(n[i++]=s[e]);n.length=i}}(),p=!1,d=!0),d&&(!function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),d=!1,f=!0),f&&function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e],s=t.drawableListPreCull,n=t.drawableList;let i=0;for(let e=0,t=s.length;e0)for(n.withSAO=!0,S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||k>0||H>0||U>0){if(a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):(a.blendEquation(a.FUNC_ADD),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,l||a.depthMask(!1),(H>0||U>0)&&a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),U>0)for(S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||W>0){if(n.lastProgramId=null,t.highlightMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),W>0)for(S=0;S0)for(S=0;S0||K>0||Q>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.enable(a.CULL_FACE),K>0)for(S=0;S0)for(S=0;S0||X>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),X>0)for(S=0;S0)for(S=0;S0||J>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),J>0)for(S=0;S0)for(S=0;S0){const t=Math.floor(e/4),s=l.size[0],n=t%s-Math.floor(s/2),a=Math.floor(t/s)-Math.floor(s/2),o=Math.sqrt(Math.pow(n,2)+Math.pow(a,2));v.push({x:n,y:a,dist:o,isVertex:i&&r?f[e+3]>d.length/2:i,result:[f[e+0],f[e+1],f[e+2],f[e+3]]})}let w=null,T=null;if(v.length>0){v.sort(((e,t)=>e.isVertex!==t.isVertex?e.isVertex?-1:1:e.dist-t.dist)),T=v[0].isVertex?"vertex":"edge",v=v[0].result;const e=d[v[3]],t=e.origin,s=e.coordinateScale;w=[v[0]*s[0]+t[0],v[1]*s[1]+t[1],v[2]*s[2]+t[2]]}if(null===I&&null==w)return null;let E=null;return null!==w&&(E=t.camera.projectWorldPos(w)),{snapType:T,snappedToVertex:"vertex"===T,snappedToEdge:"edge"===T,worldPos:I,snappedWorldPos:w,snappedCanvasPos:E}},this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new Bo(t,g),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){D(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight),a.clearColor(0,0,0,0),a.enable(a.DEPTH_TEST),a.disable(a.CULL_FACE),a.disable(a.BLEND),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT);for(let e in c)if(c.hasOwnProperty(e)){const t=c[e].drawableList;for(let e=0,s=t.length;e{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("mousemove",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=(e,t)=>{if(!this.enabled)return;const s=Math.max(-1,Math.min(1,40*-e.deltaY));this.fire("mousewheel",s,!0)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(n=>{e>=n[0]-s&&e<=n[0]+s&&t>=n[1]-s&&t<=n[1]+s&&this.fire("mouseclicked",n,!0)}))}this._eventsBound=!0}}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getMouseCanvasPos(e){if(e){let t=e.target,s=0,n=0;for(;t.offsetParent;)s+=t.offsetLeft,n+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-s,this.mouseCanvasPos[1]=e.pageY-n}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}class ko extends C{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new ye({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class Qo extends C{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ye({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.canvas.boundary,t=e[2]/e[3],s=this._fovAxis;let n=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(n/=t),n=Math.min(n,120),h.perspectiveMat4(n*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class Wo extends C{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ye({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.canvas.boundary,n=s[2],i=s[3],a=n/i;let r,l,o,c;n>i?(r=-t,l=t,o=t/a,c=-t/a):(r=-t*a,l=t*a,o=t,c=-t),h.orthoMat4c(r,l,c,o,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class zo extends C{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ye({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){h.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class Ko extends C{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ye({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy()}}const Yo=h.vec3(),Xo=h.vec3(),qo=h.vec3(),Jo=h.vec3(),Zo=h.vec3(),$o=h.vec3(),ec=h.vec4(),tc=h.vec4(),sc=h.vec4(),nc=h.mat4(),ic=h.mat4(),ac=h.vec3(),rc=h.vec3(),lc=h.vec3(),oc=h.vec3();class cc extends C{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new ye({deviceMatrix:h.mat4(),hasDeviceMatrix:!1,matrix:h.mat4(),normalMatrix:h.mat4(),inverseMatrix:h.mat4()}),this._perspective=new Qo(this),this._ortho=new Wo(this),this._frustum=new zo(this),this._customProjection=new Ko(this),this._project=this._perspective,this._eye=h.vec3([0,0,10]),this._look=h.vec3([0,0,0]),this._up=h.vec3([0,1,0]),this._worldUp=h.vec3([0,1,0]),this._worldRight=h.vec3([1,0,0]),this._worldForward=h.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection?(h.subVec3(this._eye,this._look,ac),h.normalizeVec3(ac,rc),h.mulVec3Scalar(rc,1e3,lc),h.addVec3(this._look,lc,oc),t=oc):t=this._eye,e.hasDeviceMatrix?(h.lookAtMat4v(t,this._look,this._up,ic),h.mulMat4(e.deviceMatrix,ic,e.matrix)):h.lookAtMat4v(t,this._look,this._up,e.matrix),h.inverseMat4(this._state.matrix,this._state.inverseMatrix),h.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=h.subVec3(this._eye,this._look,Yo);h.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,nc),t=h.transformPoint3(nc,t,Xo),this.eye=h.addVec3(this._look,t,qo),this.up=h.transformPoint3(nc,this._up,Jo)}orbitPitch(e){if(this._constrainPitch&&(e=h.dotVec3(this._up,this._worldUp)/h.DEGTORAD)<1)return;let t=h.subVec3(this._eye,this._look,Yo);const s=h.cross3Vec3(h.normalizeVec3(t,Xo),h.normalizeVec3(this._up,qo));h.rotationMat4v(.0174532925*e,s,nc),t=h.transformPoint3(nc,t,Jo),this.up=h.transformPoint3(nc,this._up,Zo),this.eye=h.addVec3(t,this._look,$o)}yaw(e){let t=h.subVec3(this._look,this._eye,Yo);h.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,nc),t=h.transformPoint3(nc,t,Xo),this.look=h.addVec3(t,this._eye,qo),this._gimbalLock&&(this.up=h.transformPoint3(nc,this._up,Jo))}pitch(e){if(this._constrainPitch&&(e=h.dotVec3(this._up,this._worldUp)/h.DEGTORAD)<1)return;let t=h.subVec3(this._look,this._eye,Yo);const s=h.cross3Vec3(h.normalizeVec3(t,Xo),h.normalizeVec3(this._up,qo));h.rotationMat4v(.0174532925*e,s,nc),this.up=h.transformPoint3(nc,this._up,$o),t=h.transformPoint3(nc,t,Jo),this.look=h.addVec3(t,this._eye,Zo)}pan(e){const t=h.subVec3(this._eye,this._look,Yo),s=[0,0,0];let n;if(0!==e[0]){const i=h.cross3Vec3(h.normalizeVec3(t,[]),h.normalizeVec3(this._up,Xo));n=h.mulVec3Scalar(i,e[0]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]}0!==e[1]&&(n=h.mulVec3Scalar(h.normalizeVec3(this._up,qo),e[1]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),0!==e[2]&&(n=h.mulVec3Scalar(h.normalizeVec3(t,Jo),e[2]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),this.eye=h.addVec3(this._eye,s,Zo),this.look=h.addVec3(this._look,s,$o)}zoom(e){const t=h.subVec3(this._eye,this._look,Yo),s=Math.abs(h.lenVec3(t,Xo)),n=Math.abs(s+e);if(n<.5)return;const i=h.normalizeVec3(t,qo);this.eye=h.addVec3(this._look,h.mulVec3Scalar(i,n),Jo)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=h.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return h.lenVec3(h.subVec3(this._look,this._eye,Yo))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}projectWorldPos(e){const t=ec,s=tc,n=sc;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,h.mulMat4v4(this.viewMatrix,t,s),h.mulMat4v4(this.projMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1;const i=this.scene.canvas.canvas,a=i.offsetWidth/2,r=i.offsetHeight/2;return[n[0]*a+a,n[1]*r+r]}destroy(){super.destroy(),this._state.destroy()}}const uc={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class hc extends C{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=h.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return uc}set units(e){e||(e="meters");uc[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=h.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=h.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class pc extends C{constructor(e,t={}){super(e,t),this._supported=ct.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}const Ac={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class dc extends $t{get type(){return"PointsMaterial"}get presets(){return Ac}constructor(e,t={}){super(e,t),this._state=new ye({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=Ac[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ac).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const fc={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class Ic extends $t{get type(){return"LinesMaterial"}get presets(){return fc}constructor(e,t={}){super(e,t),this._state=new ye({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=fc[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(fc).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}function yc(e,t){const s={};let n,i;for(let a=0,r=t.length;a{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new jo(this,{transparent:n,alphaDepthMask:i}),this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;let e=null;this.getHash=function(){if(e)return e;const t=this.sectionPlanes;if(0===t.length)return this.hash=";";const s=[];for(let e=0,n=t.length;e0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),n=null,s=null},this.removeLight=function(e){for(let t=0,i=this.lights.length;t{this._renderer.imageDirty()})),this.lod=new oo(this,{enabled:t.lodEnabled}),this.vfc=new go(this,{enabled:t.vfcEnabled})}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+y.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=h.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const n=this.types[s];n&&(delete n[t],y.isEmptyObject(n)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_objectHighlightedUpdated(e,t=!0){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_webglContextLost(){this.canvas.spinner.processes++;for(const e in this.components)if(this.components.hasOwnProperty(e)){const t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}_webglContextRestored(){const e=this.canvas.gl;for(const t in this.components)if(this.components.hasOwnProperty(t)){const s=this.components[t];s._webglContextRestored&&s._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get pickSurfacePrecisionEnabled(){return!1}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&P.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),!e&&!this._renderer.needsRender())return;t.sceneId=this.id;const s=this._passes,n=this._clearEachPass;let i,a;for(i=0;ii&&(i=e[3]),e[4]>a&&(a=e[4]),e[5]>r&&(r=e[5]),c=!0}c||(t=-100,s=-100,n=-100,i=100,a=100,r=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=n,this._aabb[3]=i,this._aabb[4]=a,this._aabb[5]=r,this._aabbDirty=!1}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=yc(this,s));const n=e.excludeEntities||e.exclude;return n&&(e.excludeEntityIds=yc(this,n)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}snapPick(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge)}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t{if(e.collidable){const o=e.aabb;o[0]a&&(a=o[3]),o[4]>r&&(r=o[4]),o[5]>l&&(l=o[5]),t=!0}})),t){const e=h.AABB3();return e[0]=s,e[1]=n,e[2]=i,e[3]=a,e[4]=r,e[5]=l,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){y.isString(e)&&(e=[e]);let s=!1;for(let n=0,i=e.length;n{this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=h.vec3();h.decomposeMat4(h.inverseMat4(this._scene.viewer.camera.viewMatrix,h.mat4()),t,h.vec4(),h.vec3());const s=h.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),O(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Se(this._scene,He({radius:n})),this._pivotSphere=new Jt(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){h.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,h.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let a=t._lastBoundingClientRect;if(!a||t._canvasSizeChanged){const e=t.canvas;a=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(a.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(a.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(O(this.getPivotPos(),this._rtcCenter,this._rtcPos),h.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new ss(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=h.lookAtMat4v(e.eye,e.look,e.worldUp);h.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=h.distVec3(e.eye,s),t=h.inverseMat4(t);const n=h.transformVec3(t,this._cameraOffset),i=h.vec3();if(h.subVec3(e.eye,s,i),h.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=h.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=h.normalizeVec3(h.subVec3(e.look,e.eye,Cc)),s=h.cross3Vec3(t,e.worldUp,_c);return h.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(h.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),a=n.subarray(12),r=[0,0,-1,1],l=h.dotVec4(r,i)/h.dotVec4(r,a),o=Oc;t.project.unproject(e,l,Sc,Nc,o);const c=h.normalizeVec3(h.subVec3(o,t.eye,Cc)),u=h.addVec3(t.eye,h.mulVec3Scalar(c,s,_c),Bc);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=h.clamp(this._polar,.001,Math.PI-.001);const a=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===s.worldUp[2]){const e=a[1];a[1]=a[2],a[2]=e}const r=h.lenVec3(h.subVec3(s.look,s.eye,h.vec3())),l=this.getPivotPos();h.addVec3(a,l);let o=h.lookAtMat4v(a,l,s.worldUp);o=h.inverseMat4(o);const c=h.transformVec3(o,this._cameraOffset);o[12]-=c[0],o[13]-=c[1],o[14]-=c[2];const u=[o[8],o[9],o[10]];s.eye=[o[12],o[13],o[14]],h.subVec3(s.eye,h.mulVec3Scalar(u,r),s.look),s.up=[o[4],o[5],o[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class Lc{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=h.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._needFireEvents=!1}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1,this._needFireEvents=!1;const e=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.snapPick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&e.snappedWorldPos?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents=!0):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const t=this.pickResult.canvasPos;if(t[0]===this.pickCursorPos[0]&&t[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents=e,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents=!0):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents=!0)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!0)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,cursorPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new Po;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.snappedWorldPos,e.cursorPos=this.pickCursorPos,e.canvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=!1}}destroy(){}}const Mc=h.vec2();class Fc{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController;let r,l,o,c=0,u=0,p=0,A=0,d=!1;const f=h.vec3();let I=!0;const y=this._scene.canvas.canvas,m=[];function v(e=!0){y.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],p=n.pointerCanvasPos[0],A=n.pointerCanvasPos[1],e&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.picked&&a.pickedSurface&&a.pickResult&&a.pickResult.worldPos?(d=!0,f.set(a.pickResult.worldPos)):d=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;m[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;m[n]=!1}),y.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:m[e.input.KEY_SHIFT]||s.planView?(r=!0,v()):(r=!0,v(!1));break;case 2:l=!0,v();break;case 3:o=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!r&&!l&&!o)return;const t=e.canvas.boundary,a=t[2],p=t[3],A=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(m[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&l||s.panRightClick&&o){const t=A-c,s=I-u,n=e.camera;if("perspective"===n.projection){const a=Math.abs(d?h.lenVec3(h.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*a/p,i.panDeltaY+=1.5*s*a/p}else i.panDeltaX+=.5*n.ortho.scale*(t/p),i.panDeltaY+=.5*n.ortho.scale*(s/p)}else!r||l||o||s.planView||(s.firstPerson?(i.rotateDeltaY-=(A-c)/a*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/p*(s.dragRotationRate/4)):(i.rotateDeltaY-=(A-c)/a*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/p*(1.5*s.dragRotationRate)));c=A,u=I}),y.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:r=!1,l=!1,o=!1}}),y.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,a=0,r=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,a+=s.scrollLeft,r+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+a-n,t[1]=e.pageY+r-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Mc);const s=Mc[0],n=Mc[1];Math.abs(s-p)<3&&Math.abs(n-A)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Mc,event:e},!0)}y.style.removeProperty("cursor")}}),y.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;y.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var a=null!==g?t-g:0;g=t,a>.05&&(a=.05),a{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const r=i._isKeyDownForAction(i.AXIS_VIEW_RIGHT),l=i._isKeyDownForAction(i.AXIS_VIEW_BACK),o=i._isKeyDownForAction(i.AXIS_VIEW_LEFT),c=i._isKeyDownForAction(i.AXIS_VIEW_FRONT),u=i._isKeyDownForAction(i.AXIS_VIEW_TOP),p=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(r||l||o||c||u||p))return;const A=e.aabb,d=h.getAABB3Diag(A);h.getAABB3Center(A,Hc);const f=Math.abs(d/Math.tan(t.cameraFlight.fitFOV*h.DEGTORAD)),I=1.1*d;kc.orthoScale=I,r?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldRight,f,Uc),Vc)),kc.look.set(Hc),kc.up.set(a.worldUp)):l?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldForward,f,Uc),Vc)),kc.look.set(Hc),kc.up.set(a.worldUp)):o?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldRight,-f,Uc),Vc)),kc.look.set(Hc),kc.up.set(a.worldUp)):c?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldForward,-f,Uc),Vc)),kc.look.set(Hc),kc.up.set(a.worldUp)):u?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldUp,f,Uc),Vc)),kc.look.set(Hc),kc.up.set(h.normalizeVec3(h.mulVec3Scalar(a.worldForward,1,Gc),jc))):p&&(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldUp,-f,Uc),Vc)),kc.look.set(Hc),kc.up.set(h.normalizeVec3(h.mulVec3Scalar(a.worldForward,-1,Gc)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(Hc),t.cameraFlight.duration>0?t.cameraFlight.flyTo(kc,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(kc),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class Wc{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController,r=t.pivotController,l=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let o=!1,c=!1;const u=this._scene.canvas.canvas,p=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};u.addEventListener("mousemove",this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(o||c)return;const i=l.hasSubs("hover"),r=l.hasSubs("hoverOut"),u=l.hasSubs("hoverOff"),h=l.hasSubs("hoverSurface"),p=l.hasSubs("hoverSnapOrSurface");if(i||r||u||h||p)if(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=h,a.scheduleSnapOrPick=p,a.update(),a.pickResult){if(a.pickResult.entity){const t=a.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&l.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),l.fire("hoverEnter",a.pickResult,!0),this._lastPickedEntityId=t)}l.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&l.fire("hoverSurface",a.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(l.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),l.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(o=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===t.which))){const t=a.pickResult;t&&t.worldPos?(r.setPivotPos(t.worldPos),r.startPivot()):(s.smartPivot?r.setCanvasPivotPos(n.pointerCanvasPos):r.setPivotPos(e.camera.look),r.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(o=!1),3===e.which&&(c=!1),r.getPivoting()&&r.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(r.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const o=l.hasSubs("picked"),c=l.hasSubs("pickedNothing"),u=l.hasSubs("pickedSurface"),A=l.hasSubs("doublePicked"),d=l.hasSubs("doublePickedSurface"),f=l.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||A||d||f))return(o||c||u)&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=u,a.update(),a.pickResult?(l.fire("picked",a.pickResult,!0),a.pickedSurface&&l.fire("pickedSurface",a.pickResult,!0)):l.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo,a.schedulePickSurface=u,a.update();const e=a.pickResult,i=a.pickedSurface;this._timeout=setTimeout((()=>{e?(l.fire("picked",e,!0),i&&(l.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):l.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo||A||d,a.schedulePickSurface=a.schedulePickEntity&&d,a.update(),a.pickResult){if(l.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&l.fire("doublePickedSurface",a.pickResult,!0),s.doublePickFlyTo&&(p(a.pickResult),!s.firstPerson&&s.followPointer)){const e=a.pickResult.entity.aabb,s=h.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(l.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(p(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=h.getAABB3Center(s);t.pivotController.setPivotPos(n),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class zc{constructor(e,t,s,n,i){this._scene=e;const a=e.input,r=[],l=e.canvas.canvas;let o=!0;this._onSceneMouseMove=a.on("mousemove",(()=>{o=!0})),this._onSceneKeyDown=a.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(r[t]=!0,t===a.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=a.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(r[n]=!1,n===a.KEY_SHIFT&&(l.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(l=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=l.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,r),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,r),a=c._isKeyDownForAction(c.ROTATE_X_POS,r),l=c._isKeyDownForAction(c.ROTATE_X_NEG,r),o=u*s.keyboardRotationRate;(e||n||a||l)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=o:n&&(i.rotateDeltaY-=o),a?i.rotateDeltaX+=o:l&&(i.rotateDeltaX-=o),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!r[a.KEY_CTRL]&&!r[a.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,r),a=c._isKeyDownForAction(c.DOLLY_FORWARDS,r);if(e||a){const r=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),a?i.dollyDelta-=r:e&&(i.dollyDelta+=r),o&&(n.followPointerDirty=!0,o=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,r),p=c._isKeyDownForAction(c.PAN_BACKWARDS,r),A=c._isKeyDownForAction(c.PAN_LEFT,r),d=c._isKeyDownForAction(c.PAN_RIGHT,r),f=c._isKeyDownForAction(c.PAN_UP,r),I=c._isKeyDownForAction(c.PAN_DOWN,r),y=(r[a.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||A||d||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=y:f&&(i.panDeltaY+=-y),d?i.panDeltaX+=-y:A&&(i.panDeltaX+=y),p?i.panDeltaZ+=y:h&&(i.panDeltaZ+=-y))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const Kc=h.vec3();class Yc{constructor(e,t,s,n,i){this._scene=e;const a=e.camera,r=t.pickController,l=t.pivotController,o=t.panController;let c=1,u=1,p=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.pickResult&&r.pickResult.worldPos?p=r.pickResult.worldPos:(u=1,p=null),n.followPointerDirty=!1),p){const t=Math.abs(h.lenVec3(h.subVec3(p,e.camera.eye,Kc)));u=t/s.dollyProximityThreshold}u{n.mouseover=!0}),a.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{n.mouseover=!1,a.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{qc(e,a,n.pointerCanvasPos)}),a.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(qc(e,a,n.pointerCanvasPos),n.mouseover=!0)}),a.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function qc(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const Jc=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class Zc{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController,r=t.pivotController,l=h.vec2(),o=h.vec2(),c=h.vec2(),u=h.vec2(),p=[],A=this._scene.canvas.canvas;let d=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),A.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,o=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===o.length&&(Jc(i[0],l),s.followPointer&&(a.pickCursorPos=l,a.schedulePickSurface=!0,a.update(),s.planView||(a.picked&&a.pickedSurface&&a.pickResult&&a.pickResult.worldPos?(r.setPivotPos(a.pickResult.worldPos),!s.firstPerson&&r.startPivot()&&r.showPivot()):(s.smartPivot?r.setCanvasPivotPos(n.pointerCanvasPos):r.setPivotPos(e.camera.look),!s.firstPerson&&r.startPivot()&&r.showPivot()))));p.length{r.getPivoting()&&r.endPivot()}),A.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const r=e.canvas.boundary,l=r[2],A=r[3],I=t.touches;if(t.touches.length===d){if(1===d){Jc(I[0],o),h.subVec2(o,p[0],u);const t=u[0],a=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(a)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const r=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*r/A*s.touchPanRate,i.panDeltaY+=a*r/A*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/A)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(a/A)*s.touchPanRate}else i.rotateDeltaY-=t/l*(1*s.dragRotationRate),i.rotateDeltaX+=a/A*(1.5*s.dragRotationRate)}else if(2===d){const t=I[0],r=I[1];Jc(t,o),Jc(r,c);const l=h.geometricMeanVec2(p[0],p[1]),u=h.geometricMeanVec2(o,c),d=h.vec2();h.subVec2(l,u,d);const f=d[0],y=d[1],m=e.camera,v=h.distVec2([t.pageX,t.pageY],[r.pageX,r.pageY]),w=(h.distVec2(p[0],p[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===m.projection){const t=a.pickResult?a.pickResult.worldPos:e.center,n=Math.abs(h.lenVec3(h.subVec3(t,e.camera.eye,[])))*Math.tan(m.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/A*s.touchPanRate,i.panDeltaY-=y*n/A*s.touchPanRate}else i.panDeltaX-=.5*m.ortho.scale*(f/A)*s.touchPanRate,i.panDeltaY-=.5*m.ortho.scale*(y/A)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e{let n;s&&s.worldPos&&(n=s.worldPos);const i=s?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};A.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,a=e.changedTouches;if(l=Date.now(),1===i.length&&1===a.length){u=l,$c(i[0],c);const a=c[0],r=c[1],o=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(o),Math.round(h)],canvasPos:[Math.round(a),Math.round(r)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;o.length{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,l=e.changedTouches,A=r.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===l.length&&u>-1&&t-u<150&&(p>-1&&u-p<325?($c(l[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=A,a.update(),a.pickResult?(a.pickResult.touchInput=!0,r.fire("doublePicked",a.pickResult),a.pickedSurface&&r.fire("doublePickedSurface",a.pickResult),s.doublePickFlyTo&&d(a.pickResult)):(r.fire("doublePickedNothing"),s.doublePickFlyTo&&d()),p=-1):h.distVec2(o[0],c)<4&&($c(l[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=A,a.update(),a.pickResult?(a.pickResult.touchInput=!0,r.fire("picked",a.pickResult),a.pickedSurface&&r.fire("pickedSurface",a.pickResult)):r.fire("pickedNothing"),p=t),u=-1),o.length=i.length;for(let e=0,t=i.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:h.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:h.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new Lc(this,this._configs),pivotController:new xc(s,this._configs),panController:new Rc(s),cameraFlight:new Ae(this,{duration:.5})},this._handlers=[new Xc(this.scene,this._controllers,this._configs,this._states,this._updates),new Zc(this.scene,this._controllers,this._configs,this._states,this._updates),new Fc(this.scene,this._controllers,this._configs,this._states,this._updates),new Qc(this.scene,this._controllers,this._configs,this._states,this._updates),new Wc(this.scene,this._controllers,this._configs,this._states,this._updates),new eu(this.scene,this._controllers,this._configs,this._states,this._updates),new zc(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new Yc(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",y.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;e0?lu(t):null,r=s&&s.length>0?lu(s):null,l=e=>{if(!e)return;var t=!0;(r&&r[e.type]||a&&!a[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,o=s.length;i{for(let s=0,n=e.meshIds.length;s{const s=t[e];let n,i;if(s.positionsCompressed){const e=Pe.getPositionsBounds(s.positionsCompressed);n=Pe.decompressPosition(e.min,s.positionsDecodeMatrix,[]),i=Pe.decompressPosition(e.max,s.positionsDecodeMatrix,[])}else{const e=Pe.getPositionsBounds(s.positions);n=e.min,i=e.max}n[0]+=s.origin[0],n[1]+=s.origin[1],n[2]+=s.origin[2],i[0]+=s.origin[0],i[1]+=s.origin[1],i[2]+=s.origin[2],h.expandAABB3Point3(l,n),h.expandAABB3Point3(l,i),o+=s.numPrimitives})),n[r]={aabb:l,numPrimitives:o,entityId:s.id}}let r,l=[],o={};if(Object.keys(n).length>0){r=function(e){const t=[];for(let s=0,n=e.length;s{s=Math.max(s,e.entity.id)}));const n=new Array(s+1);t.forEach((t=>{n[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=n,this._lastVisibleFrameOfNodes=new Array(n.length),this._lastVisibleFrameOfNodes.fill(0)}_searchVisibleNodesWithFrustumCulling(){return this._aabbTree.searchCustom(((e,t)=>this._aabbIntersectsCameraFrustum(e,t)),(e=>this._aabbContainedInCameraFrustum(e)))}_markVisibleFrameOfVisibleNodes(e,t){const s=this._lastVisibleFrameOfNodes;for(let n=0,i=e.length;nthis._frustumProps.CAM_FACTOR_1?(s|=r<0?64:128,s&=-17):s&=-33;const l=mo(h.dotVec3(i,this._frustumProps.up),a);Math.abs(l)>this._frustumProps.CAM_FACTOR_2?(s|=l<0?1024:2048,s&=-257):s&=-513}return 4&s&&8&s&&(s|=4096),64&s&&128&s&&(s|=8192),1024&s&&2048&s&&(s|=16384),e._check=s,s}}class wo{constructor(e,t){this.sceneModel=t,this.entities=[],this.meshes=[],this.finalized=!1}addEntity(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}addMesh(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}finalize(e){if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new vo,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(()=>this.applyViewFrustumCulling.call(this)))}applyViewFrustumCulling(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}destroy(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}class go extends C{constructor(e,t={}){super(e,t),this._scene=e,this._vfcManagers={},this._vfcManagerList=[],this.enabled=t.enabled,this._init()}_init(){this._scene.on("rendering",(()=>{for(let e=0,t=this._vfcManagerList.length;e
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const Eo=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class bo extends C{constructor(e,t={}){super(e,t),this._backgroundColor=h.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new To(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+h.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Ro(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Ro(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new ot(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,p=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Oo[0]=a,Oo[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,p),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Oo),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new ot(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new me(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new me(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new me(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const No=new Float32Array(Uo(17,[0,1])),xo=new Float32Array(Uo(17,[1,0])),Lo=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Ho(n,t));return s}(17,4)),Mo=new Float32Array(2);class Fo{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new ot(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new me(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new me(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new me(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Mo[0]=r,Mo[1]=l,n.uniform2fv(this._uViewport,Mo),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,xo):n.uniform2fv(this._uSampleOffsets,No),n.uniform1fv(this._uSampleWeights,Lo);const p=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,p,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Ho(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function Uo(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Go{constructor(e){this.scene=e,this._renderBuffersBasic={},this._renderBuffersScaled={}}getRenderBuffer(e,t){const s=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled;let n=s[e];return n||(n=new Ss(this.scene.canvas.canvas,this.scene.canvas.gl,t),s[e]=n),n}destroy(){for(let e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(let e in this._renderBuffersScaled)this._renderBuffersScaled[e].destroy()}}const jo=function(t,s){s=s||{};const n=new Do(t),i=t.canvas.canvas,a=t.canvas.gl,r=!!s.transparent,l=s.alphaDepthMask,o=new e({});let c={},u={},p=!0,d=!0,f=!0,I=!0,y=!0,m=!0,v=!0,w=!0;const g=new Go(t);let T=!1;const E=new So(t),b=new Fo(t);function D(){p&&(!function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e],s=t.drawableMap,n=t.drawableListPreCull;let i=0;for(let e in s)s.hasOwnProperty(e)&&(n[i++]=s[e]);n.length=i}}(),p=!1,d=!0),d&&(!function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),d=!1,f=!0),f&&function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e],s=t.drawableListPreCull,n=t.drawableList;let i=0;for(let e=0,t=s.length;e0)for(n.withSAO=!0,S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||k>0||H>0||U>0){if(a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):(a.blendEquation(a.FUNC_ADD),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,l||a.depthMask(!1),(H>0||U>0)&&a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),U>0)for(S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||W>0){if(n.lastProgramId=null,t.highlightMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),W>0)for(S=0;S0)for(S=0;S0||K>0||Q>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.enable(a.CULL_FACE),K>0)for(S=0;S0)for(S=0;S0||X>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),X>0)for(S=0;S0)for(S=0;S0||J>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),J>0)for(S=0;S0)for(S=0;S0){const t=Math.floor(e/4),s=l.size[0],n=t%s-Math.floor(s/2),a=Math.floor(t/s)-Math.floor(s/2),o=Math.sqrt(Math.pow(n,2)+Math.pow(a,2));y.push({x:n,y:a,dist:o,isVertex:i&&r?A[e+3]>p.length/2:i,result:[A[e+0],A[e+1],A[e+2],A[e+3]]})}let m=null,v=null;if(y.length>0){y.sort(((e,t)=>e.isVertex!==t.isVertex?e.isVertex?-1:1:e.dist-t.dist)),v=y[0].isVertex?"vertex":"edge",y=y[0].result;const e=p[y[3]],t=e.origin,s=e.coordinateScale;m=[y[0]*s[0]+t[0],y[1]*s[1]+t[1],y[2]*s[2]+t[2]]}if(null===d&&null==m)return null;let w=null;return null!==m&&(w=t.camera.projectWorldPos(m)),{snapType:v,snappedToVertex:"vertex"===v,snappedToEdge:"edge"===v,worldPos:d,snappedWorldPos:m,snappedCanvasPos:w}},this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new Bo(t,g),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){D(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight),a.clearColor(0,0,0,0),a.enable(a.DEPTH_TEST),a.disable(a.CULL_FACE),a.disable(a.BLEND),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT);for(let e in c)if(c.hasOwnProperty(e)){const t=c[e].drawableList;for(let e=0,s=t.length;e{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("mousemove",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=(e,t)=>{if(!this.enabled)return;const s=Math.max(-1,Math.min(1,40*-e.deltaY));this.fire("mousewheel",s,!0)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(n=>{e>=n[0]-s&&e<=n[0]+s&&t>=n[1]-s&&t<=n[1]+s&&this.fire("mouseclicked",n,!0)}))}this._eventsBound=!0}}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getMouseCanvasPos(e){if(e){let t=e.target,s=0,n=0;for(;t.offsetParent;)s+=t.offsetLeft,n+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-s,this.mouseCanvasPos[1]=e.pageY-n}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}class ko extends C{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new ye({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class Qo extends C{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ye({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.canvas.boundary,t=e[2]/e[3],s=this._fovAxis;let n=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(n/=t),n=Math.min(n,120),h.perspectiveMat4(n*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class Wo extends C{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ye({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.canvas.boundary,n=s[2],i=s[3],a=n/i;let r,l,o,c;n>i?(r=-t,l=t,o=t/a,c=-t/a):(r=-t*a,l=t*a,o=t,c=-t),h.orthoMat4c(r,l,c,o,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class zo extends C{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ye({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){h.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class Ko extends C{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ye({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy()}}const Yo=h.vec3(),Xo=h.vec3(),qo=h.vec3(),Jo=h.vec3(),Zo=h.vec3(),$o=h.vec3(),ec=h.vec4(),tc=h.vec4(),sc=h.vec4(),nc=h.mat4(),ic=h.mat4(),ac=h.vec3(),rc=h.vec3(),lc=h.vec3(),oc=h.vec3();class cc extends C{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new ye({deviceMatrix:h.mat4(),hasDeviceMatrix:!1,matrix:h.mat4(),normalMatrix:h.mat4(),inverseMatrix:h.mat4()}),this._perspective=new Qo(this),this._ortho=new Wo(this),this._frustum=new zo(this),this._customProjection=new Ko(this),this._project=this._perspective,this._eye=h.vec3([0,0,10]),this._look=h.vec3([0,0,0]),this._up=h.vec3([0,1,0]),this._worldUp=h.vec3([0,1,0]),this._worldRight=h.vec3([1,0,0]),this._worldForward=h.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection?(h.subVec3(this._eye,this._look,ac),h.normalizeVec3(ac,rc),h.mulVec3Scalar(rc,1e3,lc),h.addVec3(this._look,lc,oc),t=oc):t=this._eye,e.hasDeviceMatrix?(h.lookAtMat4v(t,this._look,this._up,ic),h.mulMat4(e.deviceMatrix,ic,e.matrix)):h.lookAtMat4v(t,this._look,this._up,e.matrix),h.inverseMat4(this._state.matrix,this._state.inverseMatrix),h.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=h.subVec3(this._eye,this._look,Yo);h.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,nc),t=h.transformPoint3(nc,t,Xo),this.eye=h.addVec3(this._look,t,qo),this.up=h.transformPoint3(nc,this._up,Jo)}orbitPitch(e){if(this._constrainPitch&&(e=h.dotVec3(this._up,this._worldUp)/h.DEGTORAD)<1)return;let t=h.subVec3(this._eye,this._look,Yo);const s=h.cross3Vec3(h.normalizeVec3(t,Xo),h.normalizeVec3(this._up,qo));h.rotationMat4v(.0174532925*e,s,nc),t=h.transformPoint3(nc,t,Jo),this.up=h.transformPoint3(nc,this._up,Zo),this.eye=h.addVec3(t,this._look,$o)}yaw(e){let t=h.subVec3(this._look,this._eye,Yo);h.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,nc),t=h.transformPoint3(nc,t,Xo),this.look=h.addVec3(t,this._eye,qo),this._gimbalLock&&(this.up=h.transformPoint3(nc,this._up,Jo))}pitch(e){if(this._constrainPitch&&(e=h.dotVec3(this._up,this._worldUp)/h.DEGTORAD)<1)return;let t=h.subVec3(this._look,this._eye,Yo);const s=h.cross3Vec3(h.normalizeVec3(t,Xo),h.normalizeVec3(this._up,qo));h.rotationMat4v(.0174532925*e,s,nc),this.up=h.transformPoint3(nc,this._up,$o),t=h.transformPoint3(nc,t,Jo),this.look=h.addVec3(t,this._eye,Zo)}pan(e){const t=h.subVec3(this._eye,this._look,Yo),s=[0,0,0];let n;if(0!==e[0]){const i=h.cross3Vec3(h.normalizeVec3(t,[]),h.normalizeVec3(this._up,Xo));n=h.mulVec3Scalar(i,e[0]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]}0!==e[1]&&(n=h.mulVec3Scalar(h.normalizeVec3(this._up,qo),e[1]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),0!==e[2]&&(n=h.mulVec3Scalar(h.normalizeVec3(t,Jo),e[2]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),this.eye=h.addVec3(this._eye,s,Zo),this.look=h.addVec3(this._look,s,$o)}zoom(e){const t=h.subVec3(this._eye,this._look,Yo),s=Math.abs(h.lenVec3(t,Xo)),n=Math.abs(s+e);if(n<.5)return;const i=h.normalizeVec3(t,qo);this.eye=h.addVec3(this._look,h.mulVec3Scalar(i,n),Jo)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=h.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return h.lenVec3(h.subVec3(this._look,this._eye,Yo))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}projectWorldPos(e){const t=ec,s=tc,n=sc;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,h.mulMat4v4(this.viewMatrix,t,s),h.mulMat4v4(this.projMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1;const i=this.scene.canvas.canvas,a=i.offsetWidth/2,r=i.offsetHeight/2;return[n[0]*a+a,n[1]*r+r]}destroy(){super.destroy(),this._state.destroy()}}const uc={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class hc extends C{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=h.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return uc}set units(e){e||(e="meters");uc[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=h.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=h.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class pc extends C{constructor(e,t={}){super(e,t),this._supported=ct.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}const Ac={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class dc extends $t{get type(){return"PointsMaterial"}get presets(){return Ac}constructor(e,t={}){super(e,t),this._state=new ye({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=Ac[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ac).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const fc={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class Ic extends $t{get type(){return"LinesMaterial"}get presets(){return fc}constructor(e,t={}){super(e,t),this._state=new ye({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=fc[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(fc).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}function yc(e,t){const s={};let n,i;for(let a=0,r=t.length;a{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new jo(this,{transparent:n,alphaDepthMask:i}),this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;let e=null;this.getHash=function(){if(e)return e;const t=this.sectionPlanes;if(0===t.length)return this.hash=";";const s=[];for(let e=0,n=t.length;e0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),n=null,s=null},this.removeLight=function(e){for(let t=0,i=this.lights.length;t{this._renderer.imageDirty()})),this.lod=new oo(this,{enabled:t.lodEnabled}),this.vfc=new go(this,{enabled:t.vfcEnabled})}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+y.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=h.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const n=this.types[s];n&&(delete n[t],y.isEmptyObject(n)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_objectHighlightedUpdated(e,t=!0){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_webglContextLost(){this.canvas.spinner.processes++;for(const e in this.components)if(this.components.hasOwnProperty(e)){const t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}_webglContextRestored(){const e=this.canvas.gl;for(const t in this.components)if(this.components.hasOwnProperty(t)){const s=this.components[t];s._webglContextRestored&&s._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get pickSurfacePrecisionEnabled(){return!1}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&P.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),!e&&!this._renderer.needsRender())return;t.sceneId=this.id;const s=this._passes,n=this._clearEachPass;let i,a;for(i=0;ii&&(i=e[3]),e[4]>a&&(a=e[4]),e[5]>r&&(r=e[5]),c=!0}c||(t=-100,s=-100,n=-100,i=100,a=100,r=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=n,this._aabb[3]=i,this._aabb[4]=a,this._aabb[5]=r,this._aabbDirty=!1}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=yc(this,s));const n=e.excludeEntities||e.exclude;return n&&(e.excludeEntityIds=yc(this,n)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}snapPick(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge)}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t{if(e.collidable){const o=e.aabb;o[0]a&&(a=o[3]),o[4]>r&&(r=o[4]),o[5]>l&&(l=o[5]),t=!0}})),t){const e=h.AABB3();return e[0]=s,e[1]=n,e[2]=i,e[3]=a,e[4]=r,e[5]=l,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){y.isString(e)&&(e=[e]);let s=!1;for(let n=0,i=e.length;n{this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=h.vec3();h.decomposeMat4(h.inverseMat4(this._scene.viewer.camera.viewMatrix,h.mat4()),t,h.vec4(),h.vec3());const s=h.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),O(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Se(this._scene,He({radius:n})),this._pivotSphere=new Jt(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){h.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,h.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let a=t._lastBoundingClientRect;if(!a||t._canvasSizeChanged){const e=t.canvas;a=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(a.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(a.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(O(this.getPivotPos(),this._rtcCenter,this._rtcPos),h.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new ss(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=h.lookAtMat4v(e.eye,e.look,e.worldUp);h.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=h.distVec3(e.eye,s),t=h.inverseMat4(t);const n=h.transformVec3(t,this._cameraOffset),i=h.vec3();if(h.subVec3(e.eye,s,i),h.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=h.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=h.normalizeVec3(h.subVec3(e.look,e.eye,Cc)),s=h.cross3Vec3(t,e.worldUp,_c);return h.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(h.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),a=n.subarray(12),r=[0,0,-1,1],l=h.dotVec4(r,i)/h.dotVec4(r,a),o=Oc;t.project.unproject(e,l,Sc,Nc,o);const c=h.normalizeVec3(h.subVec3(o,t.eye,Cc)),u=h.addVec3(t.eye,h.mulVec3Scalar(c,s,_c),Bc);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=h.clamp(this._polar,.001,Math.PI-.001);const a=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===s.worldUp[2]){const e=a[1];a[1]=a[2],a[2]=e}const r=h.lenVec3(h.subVec3(s.look,s.eye,h.vec3())),l=this.getPivotPos();h.addVec3(a,l);let o=h.lookAtMat4v(a,l,s.worldUp);o=h.inverseMat4(o);const c=h.transformVec3(o,this._cameraOffset);o[12]-=c[0],o[13]-=c[1],o[14]-=c[2];const u=[o[8],o[9],o[10]];s.eye=[o[12],o[13],o[14]],h.subVec3(s.eye,h.mulVec3Scalar(u,r),s.look),s.up=[o[4],o[5],o[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class Lc{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=h.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._needFireEvents=!1}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1,this._needFireEvents=!1;const e=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.snapPick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&e.snappedWorldPos?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents=!0):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const t=this.pickResult.canvasPos;if(t[0]===this.pickCursorPos[0]&&t[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents=e,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents=!0):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents=!0)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!0)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,cursorPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new Po;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.snappedWorldPos,e.cursorPos=this.pickCursorPos,e.canvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=!1}}destroy(){}}const Mc=h.vec2();class Fc{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController;let r,l,o,c=0,u=0,p=0,A=0,d=!1;const f=h.vec3();let I=!0;const y=this._scene.canvas.canvas,m=[];function v(e=!0){y.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],p=n.pointerCanvasPos[0],A=n.pointerCanvasPos[1],e&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.picked&&a.pickedSurface&&a.pickResult&&a.pickResult.worldPos?(d=!0,f.set(a.pickResult.worldPos)):d=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;m[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;m[n]=!1}),y.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:m[e.input.KEY_SHIFT]||s.planView?(r=!0,v()):(r=!0,v(!1));break;case 2:l=!0,v();break;case 3:o=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!r&&!l&&!o)return;const t=e.canvas.boundary,a=t[2],p=t[3],A=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(m[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&l||s.panRightClick&&o){const t=A-c,s=I-u,n=e.camera;if("perspective"===n.projection){const a=Math.abs(d?h.lenVec3(h.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*a/p,i.panDeltaY+=1.5*s*a/p}else i.panDeltaX+=.5*n.ortho.scale*(t/p),i.panDeltaY+=.5*n.ortho.scale*(s/p)}else!r||l||o||s.planView||(s.firstPerson?(i.rotateDeltaY-=(A-c)/a*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/p*(s.dragRotationRate/4)):(i.rotateDeltaY-=(A-c)/a*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/p*(1.5*s.dragRotationRate)));c=A,u=I}),y.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:r=!1,l=!1,o=!1}}),y.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,a=0,r=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,a+=s.scrollLeft,r+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+a-n,t[1]=e.pageY+r-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Mc);const s=Mc[0],n=Mc[1];Math.abs(s-p)<3&&Math.abs(n-A)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Mc,event:e},!0)}y.style.removeProperty("cursor")}}),y.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;y.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var a=null!==g?t-g:0;g=t,a>.05&&(a=.05),a{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const r=i._isKeyDownForAction(i.AXIS_VIEW_RIGHT),l=i._isKeyDownForAction(i.AXIS_VIEW_BACK),o=i._isKeyDownForAction(i.AXIS_VIEW_LEFT),c=i._isKeyDownForAction(i.AXIS_VIEW_FRONT),u=i._isKeyDownForAction(i.AXIS_VIEW_TOP),p=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(r||l||o||c||u||p))return;const A=e.aabb,d=h.getAABB3Diag(A);h.getAABB3Center(A,Hc);const f=Math.abs(d/Math.tan(t.cameraFlight.fitFOV*h.DEGTORAD)),I=1.1*d;kc.orthoScale=I,r?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldRight,f,Uc),Vc)),kc.look.set(Hc),kc.up.set(a.worldUp)):l?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldForward,f,Uc),Vc)),kc.look.set(Hc),kc.up.set(a.worldUp)):o?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldRight,-f,Uc),Vc)),kc.look.set(Hc),kc.up.set(a.worldUp)):c?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldForward,-f,Uc),Vc)),kc.look.set(Hc),kc.up.set(a.worldUp)):u?(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldUp,f,Uc),Vc)),kc.look.set(Hc),kc.up.set(h.normalizeVec3(h.mulVec3Scalar(a.worldForward,1,Gc),jc))):p&&(kc.eye.set(h.addVec3(Hc,h.mulVec3Scalar(a.worldUp,-f,Uc),Vc)),kc.look.set(Hc),kc.up.set(h.normalizeVec3(h.mulVec3Scalar(a.worldForward,-1,Gc)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(Hc),t.cameraFlight.duration>0?t.cameraFlight.flyTo(kc,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(kc),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class Wc{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController,r=t.pivotController,l=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let o=!1,c=!1;const u=this._scene.canvas.canvas,p=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};u.addEventListener("mousemove",this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(o||c)return;const i=l.hasSubs("hover"),r=l.hasSubs("hoverOut"),u=l.hasSubs("hoverOff"),h=l.hasSubs("hoverSurface"),p=l.hasSubs("hoverSnapOrSurface");if(i||r||u||h||p)if(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=h,a.scheduleSnapOrPick=p,a.update(),a.pickResult){if(a.pickResult.entity){const t=a.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&l.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),l.fire("hoverEnter",a.pickResult,!0),this._lastPickedEntityId=t)}l.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&l.fire("hoverSurface",a.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(l.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),l.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(o=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===t.which))){const t=a.pickResult;t&&t.worldPos?(r.setPivotPos(t.worldPos),r.startPivot()):(s.smartPivot?r.setCanvasPivotPos(n.pointerCanvasPos):r.setPivotPos(e.camera.look),r.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(o=!1),3===e.which&&(c=!1),r.getPivoting()&&r.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(r.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const o=l.hasSubs("picked"),c=l.hasSubs("pickedNothing"),u=l.hasSubs("pickedSurface"),A=l.hasSubs("doublePicked"),d=l.hasSubs("doublePickedSurface"),f=l.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||A||d||f))return(o||c||u)&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=u,a.update(),a.pickResult?(l.fire("picked",a.pickResult,!0),a.pickedSurface&&l.fire("pickedSurface",a.pickResult,!0)):l.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo,a.schedulePickSurface=u,a.update();const e=a.pickResult,i=a.pickedSurface;this._timeout=setTimeout((()=>{e?(l.fire("picked",e,!0),i&&(l.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):l.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo||A||d,a.schedulePickSurface=a.schedulePickEntity&&d,a.update(),a.pickResult){if(l.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&l.fire("doublePickedSurface",a.pickResult,!0),s.doublePickFlyTo&&(p(a.pickResult),!s.firstPerson&&s.followPointer)){const e=a.pickResult.entity.aabb,s=h.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(l.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(p(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=h.getAABB3Center(s);t.pivotController.setPivotPos(n),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class zc{constructor(e,t,s,n,i){this._scene=e;const a=e.input,r=[],l=e.canvas.canvas;let o=!0;this._onSceneMouseMove=a.on("mousemove",(()=>{o=!0})),this._onSceneKeyDown=a.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(r[t]=!0,t===a.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=a.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(r[n]=!1,n===a.KEY_SHIFT&&(l.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(l=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=l.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,r),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,r),a=c._isKeyDownForAction(c.ROTATE_X_POS,r),l=c._isKeyDownForAction(c.ROTATE_X_NEG,r),o=u*s.keyboardRotationRate;(e||n||a||l)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=o:n&&(i.rotateDeltaY-=o),a?i.rotateDeltaX+=o:l&&(i.rotateDeltaX-=o),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!r[a.KEY_CTRL]&&!r[a.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,r),a=c._isKeyDownForAction(c.DOLLY_FORWARDS,r);if(e||a){const r=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),a?i.dollyDelta-=r:e&&(i.dollyDelta+=r),o&&(n.followPointerDirty=!0,o=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,r),p=c._isKeyDownForAction(c.PAN_BACKWARDS,r),A=c._isKeyDownForAction(c.PAN_LEFT,r),d=c._isKeyDownForAction(c.PAN_RIGHT,r),f=c._isKeyDownForAction(c.PAN_UP,r),I=c._isKeyDownForAction(c.PAN_DOWN,r),y=(r[a.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||A||d||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=y:f&&(i.panDeltaY+=-y),d?i.panDeltaX+=-y:A&&(i.panDeltaX+=y),p?i.panDeltaZ+=y:h&&(i.panDeltaZ+=-y))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const Kc=h.vec3();class Yc{constructor(e,t,s,n,i){this._scene=e;const a=e.camera,r=t.pickController,l=t.pivotController,o=t.panController;let c=1,u=1,p=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.pickResult&&r.pickResult.worldPos?p=r.pickResult.worldPos:(u=1,p=null),n.followPointerDirty=!1),p){const t=Math.abs(h.lenVec3(h.subVec3(p,e.camera.eye,Kc)));u=t/s.dollyProximityThreshold}u{n.mouseover=!0}),a.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{n.mouseover=!1,a.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{qc(e,a,n.pointerCanvasPos)}),a.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(qc(e,a,n.pointerCanvasPos),n.mouseover=!0)}),a.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function qc(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const Jc=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class Zc{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController,r=t.pivotController,l=h.vec2(),o=h.vec2(),c=h.vec2(),u=h.vec2(),p=[],A=this._scene.canvas.canvas;let d=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),A.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,o=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===o.length&&(Jc(i[0],l),s.followPointer&&(a.pickCursorPos=l,a.schedulePickSurface=!0,a.update(),s.planView||(a.picked&&a.pickedSurface&&a.pickResult&&a.pickResult.worldPos?(r.setPivotPos(a.pickResult.worldPos),!s.firstPerson&&r.startPivot()&&r.showPivot()):(s.smartPivot?r.setCanvasPivotPos(n.pointerCanvasPos):r.setPivotPos(e.camera.look),!s.firstPerson&&r.startPivot()&&r.showPivot()))));p.length{r.getPivoting()&&r.endPivot()}),A.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const r=e.canvas.boundary,l=r[2],A=r[3],I=t.touches;if(t.touches.length===d){if(1===d){Jc(I[0],o),h.subVec2(o,p[0],u);const t=u[0],a=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(a)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const r=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*r/A*s.touchPanRate,i.panDeltaY+=a*r/A*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/A)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(a/A)*s.touchPanRate}else i.rotateDeltaY-=t/l*(1*s.dragRotationRate),i.rotateDeltaX+=a/A*(1.5*s.dragRotationRate)}else if(2===d){const t=I[0],r=I[1];Jc(t,o),Jc(r,c);const l=h.geometricMeanVec2(p[0],p[1]),u=h.geometricMeanVec2(o,c),d=h.vec2();h.subVec2(l,u,d);const f=d[0],y=d[1],m=e.camera,v=h.distVec2([t.pageX,t.pageY],[r.pageX,r.pageY]),w=(h.distVec2(p[0],p[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===m.projection){const t=a.pickResult?a.pickResult.worldPos:e.center,n=Math.abs(h.lenVec3(h.subVec3(t,e.camera.eye,[])))*Math.tan(m.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/A*s.touchPanRate,i.panDeltaY-=y*n/A*s.touchPanRate}else i.panDeltaX-=.5*m.ortho.scale*(f/A)*s.touchPanRate,i.panDeltaY-=.5*m.ortho.scale*(y/A)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e{let n;s&&s.worldPos&&(n=s.worldPos);const i=s?s.entity.aabb:e.aabb;if(n){const s=e.camera;h.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};A.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,a=e.changedTouches;if(l=Date.now(),1===i.length&&1===a.length){u=l,$c(i[0],c);const a=c[0],r=c[1],o=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(o),Math.round(h)],canvasPos:[Math.round(a),Math.round(r)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;o.length{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,l=e.changedTouches,A=r.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===l.length&&u>-1&&t-u<150&&(p>-1&&u-p<325?($c(l[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=A,a.update(),a.pickResult?(a.pickResult.touchInput=!0,r.fire("doublePicked",a.pickResult),a.pickedSurface&&r.fire("doublePickedSurface",a.pickResult),s.doublePickFlyTo&&d(a.pickResult)):(r.fire("doublePickedNothing"),s.doublePickFlyTo&&d()),p=-1):h.distVec2(o[0],c)<4&&($c(l[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=A,a.update(),a.pickResult?(a.pickResult.touchInput=!0,r.fire("picked",a.pickResult),a.pickedSurface&&r.fire("pickedSurface",a.pickResult)):r.fire("pickedNothing"),p=t),u=-1),o.length=i.length;for(let e=0,t=i.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:h.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:h.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new Lc(this,this._configs),pivotController:new xc(s,this._configs),panController:new Rc(s),cameraFlight:new Ae(this,{duration:.5})},this._handlers=[new Xc(this.scene,this._controllers,this._configs,this._states,this._updates),new Zc(this.scene,this._controllers,this._configs,this._states,this._updates),new Fc(this.scene,this._controllers,this._configs,this._states,this._updates),new Qc(this.scene,this._controllers,this._configs,this._states,this._updates),new Wc(this.scene,this._controllers,this._configs,this._states,this._updates),new eu(this.scene,this._controllers,this._configs,this._states,this._updates),new zc(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new Yc(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",y.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;e0?lu(t):null,r=s&&s.length>0?lu(s):null,l=e=>{if(!e)return;var t=!0;(r&&r[e.type]||a&&!a[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,o=s.length;i * Copyright (c) 2022 Niklas von Hertzen diff --git a/dist/xeokit-sdk.min.es.js b/dist/xeokit-sdk.min.es.js index 2ec3ddb896..8d3bd9a36f 100644 --- a/dist/xeokit-sdk.min.es.js +++ b/dist/xeokit-sdk.min.es.js @@ -1,4 +1,4 @@ -class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e={}){this._id=t.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==e.hideOnMouseDown&&(document.addEventListener("mousedown",(e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),e.items&&(this.items=e.items),this._hideOnAction=!1!==e.hideOnAction,this.context=e.context,this.enabled=!1!==e.enabled,this.hide()}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,n=s.length;e{const a=this._getNextId(),r=new s(a);for(let s=0,a=e.length;s0,c=this._getNextId(),u=s.getTitle||(()=>s.title||""),h=s.doAction||s.callback||(()=>{}),p=s.getEnabled||(()=>!0),A=s.getShown||(()=>!0),d=new i(c,u,h,p,A);if(d.parentMenu=r,l.items.push(d),o){const e=t(n);d.subMenu=e,e.parentItem=d}this._itemList.push(d),this._itemMap[d.id]=d}}return this._menuList.push(r),this._menuMap[r.id]=r,r};this._rootMenu=t(e)}_getNextId(){return"ContextMenu_"+this._id+"_"+this._nextId++}_createUI(){const e=t=>{this._createMenuUI(t);const s=t.groups;for(let t=0,n=s.length;t'),s.push("
    "),t)for(let e=0,n=t.length;e'+o+" [MORE]"):s.push('
  • '+o+"
  • ")}}s.push("
"),s.push("");const n=s.join("");document.body.insertAdjacentHTML("beforeend",n);const i=document.querySelector("."+e.id);e.menuElement=i,i.style["border-radius"]="4px",i.style.display="none",i.style["z-index"]=3e5,i.style.background="white",i.style.border="1px solid black",i.style["box-shadow"]="0 4px 5px 0 gray",i.oncontextmenu=e=>{e.preventDefault()};const a=this;let r=null;if(t)for(let e=0,s=t.length;e{e.preventDefault();const s=t.subMenu;if(!s)return void(r&&(a._hideMenu(r.id),r=null));if(r&&r.id!==s.id&&(a._hideMenu(r.id),r=null),!1===t.enabled)return;const n=t.itemElement,i=s.menuElement,l=n.getBoundingClientRect();i.getBoundingClientRect();l.right+200>window.innerWidth?a._showMenu(s.id,l.left-200,l.top-1):a._showMenu(s.id,l.right-5,l.top-1),r=s})),n||(t.itemElement.addEventListener("click",(e=>{e.preventDefault(),a._context&&!1!==t.enabled&&(t.doAction&&t.doAction(a._context),this._hideOnAction?a.hide():(a._updateItemsTitles(),a._updateItemsEnabledStatus()))})),t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault(),!1!==t.enabled&&t.doHover&&t.doHover(a._context)})))):console.error("ContextMenu item element not found: "+t.id)}}}_updateItemsTitles(){if(this._context)for(let e=0,t=this._itemList.length;ewindow.innerHeight&&(s=window.innerHeight-n),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=s+"px"}_hideMenuElement(e){e.style.display="none"}}class r{constructor(e,t={}){this.viewer=e,this.scene=this.viewer.scene,this._lensCursorDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._lensCursorDiv,this.viewer.scene.canvas.canvas),this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red",this._lensCursorDiv.style.borderRadius="20px",this._lensCursorDiv.style.width="10px",this._lensCursorDiv.style.height="10px",this._lensCursorDiv.style.margin="-200px -200px",this._lensCursorDiv.style.zIndex="100000",this._lensCursorDiv.style.position="absolute",this._lensCursorDiv.style.pointerEvents="none",this._lensContainer=document.createElement("div"),this._lensContainer.style.border="1px solid black",this._lensContainer.style.background="white",this._lensContainer.style.borderRadius="50%",this._lensContainer.style.width="300px",this._lensContainer.style.height="300px",this._lensContainer.style.marginTop="85px",this._lensContainer.style.marginLeft="25px",this._lensContainer.style.zIndex="15000",this._lensContainer.style.position="absolute",this._lensContainer.style.pointerEvents="none",this._lensContainer.style.visibility="hidden",this._lensCanvas=document.createElement("canvas"),this._lensCanvas.style.borderRadius="50%",this._lensCanvas.style.width="300px",this._lensCanvas.style.height="300px",this._lensCanvas.style.zIndex="15000",this._lensCanvas.style.pointerEvents="none",document.body.appendChild(this._lensContainer),this._lensContainer.appendChild(this._lensCanvas),this._lensCanvasContext=this._lensCanvas.getContext("2d"),this._canvasElement=this.viewer.scene.canvas.canvas,this._centerPos=null,this._cursorPos=null,this._lensPosToggle=!0,this._zoomLevel=t.zoomLevel||2,this._active=!1!==t.active,this._visible=!1,this._snapped=!1,this._onViewerRendering=this.viewer.scene.on("rendering",(()=>{this._active&&this._visible&&this.update()}))}update(){if(!this._active||!this._visible)return;if(!this._centerPos)return;const e=this._lensContainer.getBoundingClientRect(),t=this._canvasElement.getBoundingClientRect(),s=this._centerPos[0]e.left&&this._centerPos[1]e.top;this._lensContainer.style.marginLeft="25px",s&&(this._lensPosToggle?this._lensContainer.style.marginTop=t.bottom-t.top-this._lensCanvas.height-85+"px":this._lensContainer.style.marginTop="85px",this._lensPosToggle=!this._lensPosToggle),this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);const n=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,this._centerPos[0]-n/2,this._centerPos[1]-n/2,n,n,0,0,this._lensCanvas.width,this._lensCanvas.height);const i=[(e.left+e.right)/2,(e.top+e.bottom)/2];if(this._cursorPos){const e=this._cursorPos[0]-this._centerPos[0],t=this._cursorPos[1]-this._centerPos[1];this._lensCursorDiv.style.marginLeft=i[0]+e*this._zoomLevel-10+"px",this._lensCursorDiv.style.marginTop=i[1]+t*this._zoomLevel-10+"px"}else this._lensCursorDiv.style.marginLeft=i[0]-10+"px",this._lensCursorDiv.style.marginTop=i[1]-10+"px"}set zoomFactor(e){this._zoomFactor=e,this.update()}get zoomFactor(){return this._zoomFactor}set centerPos(e){this._centerPos=e,this.update()}get centerPos(){return this._centerPos}set cursorPos(e){this._cursorPos=e,this.update()}get cursorPos(){return this._cursorPos}set snapped(e){this._snapped=e,e?(this._lensCursorDiv.style.background="greenyellow",this._lensCursorDiv.style.border="2px solid green"):(this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red")}get snapped(){return this._snapped}set active(e){this._active=e,this._lensContainer.style.visibility=e&&this._visible?"visible":"hidden",e&&this._visible||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}get active(){return this._active}set visible(e){this._visible=e,this._lensContainer.style.visibility=e&&this._active?"visible":"hidden",e&&this._active||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}get visible(){return this._visible}destroy(){this._destroyed||(this.viewer.scene.off(this._onViewerRendering),this._lensContainer.removeChild(this._lensCanvas),document.body.removeChild(this._lensContainer),this._destroyed=!0)}}class l{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let o=!0,c=o?Float64Array:Float32Array;const u=new c(16),h=new c(16),p=new c(4),A={setDoublePrecisionEnabled(e){o=e,c=o?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>o,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new c(e||2),vec3:e=>new c(e||3),vec4:e=>new c(e||4),mat3:e=>new c(e||9),mat3ToMat4:(e,t=new c(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new c(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new c(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new c(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>A.dotVec4(e,e),lenVec4:e=>Math.sqrt(A.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>A.dotVec3(e,e),sqLenVec2:e=>A.dotVec2(e,e),lenVec3:e=>Math.sqrt(A.sqLenVec3(e)),distVec3:(()=>{const e=new c(3);return(t,s)=>A.lenVec3(A.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(A.sqLenVec2(e)),distVec2:(()=>{const e=new c(2);return(t,s)=>A.lenVec2(A.subVec2(t,s,e))})(),rcpVec3:(e,t)=>A.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/A.lenVec4(e);return A.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/A.lenVec3(e);return A.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/A.lenVec2(e);return A.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=A.dotVec3(e,t)/Math.sqrt(A.sqLenVec3(e)*A.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new c(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=A.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=A.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=A.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||A.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>A.m4s(0),setMat4ToOnes:()=>A.m4s(1),diagonalMat4v:e=>new c([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>A.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>A.diagonalMat4c(e,e,e,e),identityMat4:(e=new c(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new c(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>A.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new c(9));const n=e[0],i=e[3],a=e[6],r=e[1],l=e[4],o=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+l*I+o*v,s[4]=r*d+l*y+o*w,s[7]=r*f+l*m+o*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=A.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||A.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||A.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new c(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,A.translationMat4v(e,i))})(),translationMat4s:(e,t)=>A.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>A.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=A.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,h,p,d,f,I;return u=l*o,h=o*c,p=c*l,d=l*i,f=o*i,I=c*i,(s=s||A.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*p-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*h+d,s[7]=0,s[8]=r*p+f,s[9]=r*h-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>A.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=A.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=A.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new c(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,A.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>A.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=A.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,h=n*o,p=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=h+v,s[2]=p-m,s[3]=0,s[4]=h-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=p+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=A.vec4()){const n=A.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],h=e[6],p=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,p),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(h,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,p),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(h,-1,1)),Math.abs(h)<.99999?(s[1]=Math.atan2(-u,p),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(h,p),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,p))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(h,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,p),s[1]=0)),s},composeMat4:(e,t,s,n=A.mat4())=>(A.quaternionToRotationMat4(t,n),A.scaleMat4v(s,n),A.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new c(3),t=new c(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=A.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=A.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=A.lenVec3(e);A.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,h=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=h,t[9]*=h,t[10]*=h,A.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=A.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],h=t[1],p=t[2];if(i===u&&a===h&&r===p)return A.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-h,I=r-p,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>A.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=A.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=A.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];A.addVec4(i,n,u),A.subVec4(i,n,h);const a=2*n[2],r=h[0],l=h[1],o=h[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=u[0]/r,s[9]=u[1]/l,s[10]=-u[2]/o,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/o,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=A.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],A.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=A.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=A.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new c(16),t=new c(16),s=new c(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||A.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||A.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=A.vec4()){const n=e[0]*A.DEGTORAD/2,i=e[1]*A.DEGTORAD/2,a=e[2]*A.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),h=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"YXZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"ZXY"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"ZYX"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"YZX"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o-c*u*h):"XZY"===t&&(s[0]=c*l*o-r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o+c*u*h),s},mat4ToQuaternion(e,t=A.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let h;const p=s+r+u;return p>0?(h=.5/Math.sqrt(p+1),t[3]=.25/h,t[0]=(c-l)*h,t[1]=(i-o)*h,t[2]=(a-n)*h):s>r&&s>u?(h=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/h,t[0]=.25*h,t[1]=(n+a)/h,t[2]=(i+o)/h):r>u?(h=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/h,t[0]=(n+a)/h,t[1]=.25*h,t[2]=(l+c)/h):(h=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/h,t[0]=(i+o)/h,t[1]=(l+c)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,s=A.vec4()){const n=Math.sqrt(A.dotVec3(e,e)*A.dotVec3(t,t));let i=n+A.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):A.cross3Vec3(e,t,s),s[3]=i,A.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=A.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new c(16);return(t,s,n)=>(n=n||A.vec3(),A.quaternionToRotationMat4(t,e),A.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=A.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=A.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,h=c*i+o*n-r*a,p=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+h*-o-p*-l,s[1]=h*c+d*-l+p*-r-u*-o,s[2]=p*c+d*-o+u*-l-h*-r,s},quaternionToMat4(e,t){t=A.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,h=o*a,p=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+h,t[2]=f-u,t[4]=d-h,t[5]=1-(p+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(p+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=A.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>A.normalizeQuaternion(A.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=A.vec4()){const s=(e=A.normalizeQuaternion(e,p))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new c(e||6),AABB2:e=>new c(e||4),OBB3:e=>new c(e||32),OBB2:e=>new c(e||16),Sphere3:(e,t,s,n)=>new c([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new c(3),t=new c(3),s=new c(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],A.subVec3(t,e,s),Math.abs(A.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new c(3),t=new c(3),s=new c(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=A.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],h=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>h?u:h,Math.abs(A.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||A.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||A.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=A.AABB3())=>(e[0]=A.MAX_DOUBLE,e[1]=A.MAX_DOUBLE,e[2]=A.MAX_DOUBLE,e[3]=A.MIN_DOUBLE,e[4]=A.MIN_DOUBLE,e[5]=A.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=A.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new c(3);return(t,s,n)=>{s=s||A.AABB3();let i,a,r,l=A.MAX_DOUBLE,o=A.MAX_DOUBLE,c=A.MAX_DOUBLE,u=A.MIN_DOUBLE,h=A.MIN_DOUBLE,p=A.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>h&&(h=a),r>p&&(p=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=h,s[5]=p,s}})(),OBB3ToAABB3(e,t=A.AABB3()){let s,n,i,a=A.MAX_DOUBLE,r=A.MAX_DOUBLE,l=A.MAX_DOUBLE,o=A.MIN_DOUBLE,c=A.MIN_DOUBLE,u=A.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=A.AABB3()){let s,n,i,a=A.MAX_DOUBLE,r=A.MAX_DOUBLE,l=A.MAX_DOUBLE,o=A.MIN_DOUBLE,c=A.MIN_DOUBLE,u=A.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new c(3);return(t,s)=>{s=s||A.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new c(3),t=new c(3);return(s,n)=>{n=n||A.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=h);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new c(3),t=new c(3);return(s,n)=>{n=n||A.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ih&&(h=u);return n[3]=h,n}})(),getSphere3Center:(e,t=A.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=A.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=A.MAX_DOUBLE,e[1]=A.MAX_DOUBLE,e[2]=A.MIN_DOUBLE,e[3]=A.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=A.AABB2()){let s,n,i,a,r=A.MAX_DOUBLE,l=A.MAX_DOUBLE,o=A.MIN_DOUBLE,c=A.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=A.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,h=r*l-i*c,p=i*o-a*l,d=Math.sqrt(u*u+h*h+p*p);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=h/d,n[2]=p/d),n},rayTriangleIntersect:(()=>{const e=new c(3),t=new c(3),s=new c(3),n=new c(3),i=new c(3);return(a,r,l,o,c,u)=>{u=u||A.vec3();const h=A.subVec3(o,l,e),p=A.subVec3(c,l,t),d=A.cross3Vec3(r,p,s),f=A.dotVec3(h,d);if(f<1e-6)return null;const I=A.subVec3(a,l,n),y=A.dotVec3(I,d);if(y<0||y>f)return null;const m=A.cross3Vec3(I,h,i),v=A.dotVec3(r,m);if(v<0||y+v>f)return null;const w=A.dotVec3(p,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new c(3),t=new c(3),s=new c(3),n=new c(3);return(i,a,r,l,o,c)=>{c=c||A.vec3(),a=A.normalizeVec3(a,e);const u=A.subVec3(l,r,t),h=A.subVec3(o,r,s),p=A.cross3Vec3(u,h,n);A.normalizeVec3(p,p);const d=-A.dotVec3(r,p),f=-(A.dotVec3(i,p)+d)/A.dotVec3(a,p);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new c(3),t=new c(3),s=new c(3);return(n,i,a,r,l)=>{const o=A.subVec3(r,i,e),c=A.subVec3(a,i,t),u=A.subVec3(n,i,s),h=A.dotVec3(o,o),p=A.dotVec3(o,c),d=A.dotVec3(o,u),f=A.dotVec3(c,c),I=A.dotVec3(c,u),y=h*f-p*p;if(0===y)return null;const m=1/y,v=(f*d-p*I)*m,w=(h*I-p*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=A.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new c(3),t=new c(3),s=new c(3),n=new c(3),i=new c(3),a=new c(3);return(r,l,o)=>{let c,u;const h=new Array(r.length/3);let p,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new c(3),t=new c(3),s=new c(3),n=new c(3),i=new c(3),a=new c(3),r=new c(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let h=0;h>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,h;const p=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new c(4),t=new c(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,A.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],A.transformVec3(s,e,t),A.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new c(16),t=new c(16),s=new c(4),n=new c(4),i=new c(4),a=new c(4);return(r,l,o,c,u,h)=>{const p=A.mulMat4(o,l,e),d=A.inverseMat4(p,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,A.transformVec4(d,s,n),A.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,A.transformVec4(d,i,a),A.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],A.subVec3(a,n,h),A.normalizeVec3(h)}})(),canvasPosToLocalRay:(()=>{const e=new c(3),t=new c(3);return(s,n,i,a,r,l,o)=>{A.canvasPosToWorldRay(s,n,i,r,e,t),A.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new c(16),t=new c(4),s=new c(4);return(n,i,a,r,l)=>{const o=A.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,A.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],A.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new c(6),l={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let o,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,o=0,u=s.length;or[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return l.triangles=s,l.leaf=!0,l;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),l.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(o=0,u=s.length;o{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};A.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=A.vec3(),u=A.vec3(),h=A.vec3(),p=A.vec3(),d=A.vec3(),f=A.vec3(),I=A.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class d{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const f={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var I=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{g.removeItem(e.id),delete C.scenes[e.id],delete w[e.id],f.components.scenes--}))},this.clear=function(){let e;for(const t in C.scenes)C.scenes.hasOwnProperty(t)&&(e=C.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete C.scenes[e.id]))},this.scheduleTask=function(e,t){T.push(e),T.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;T.length>0&&(e<0||n0&&D>0){var t=1e3/D;R+=t,b.push(t),b.length>=30&&(R-=b.shift()),f.frame.fps=Math.round(R/b.length)}!function(e){const t=C.runTasks(e+10),s=C.getNumTasks();f.frame.tasksRun=t,f.frame.tasksScheduled=s,f.frame.tasksBudget=10}(e),function(e){for(var t in E.time=e,C.scenes)if(C.scenes.hasOwnProperty(t)){var s=C.scenes[t];E.sceneId=t,E.startTime=s.startTime,E.deltaTime=null!=E.prevTime?E.time-E.prevTime:0,s.fire("tick",E,!0)}E.prevTime=e}(e),function(){const e=C.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=w[r],n||(n=w[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),P=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(_):requestAnimationFrame(_)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(_):requestAnimationFrame(_);class B{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof B))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+v.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(v.isNumeric(s)||v.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+v.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+v.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+v.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():C.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(A.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){q.set(this._viewPos),q[3]=1,A.transformPoint4(this.scene.camera.projMatrix,q,J);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+J[0]/J[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-J[1]/J[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof X?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),N(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class ${constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class ee{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class te{constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var se=A.vec3(),ne=A.vec3();class ie extends B{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new Z(s,t.origin),this._cornerMarker=new Z(s,t.corner),this._targetMarker=new Z(s,t.target),this._originWorld=A.vec3(),this._cornerWorld=A.vec3(),this._targetWorld=A.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new ee(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new ee(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new ee(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new $(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new $(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new te(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(A.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const p=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>p||f>p||I>p)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);A.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,h=t.length;u1?i.other:i.one,i?(i=le(i,[t]),s&&(i=le(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const a=this._events[t];return void 0!==a&&s(a),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function re(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),a=this.getPoint(n),r=A.subVec3(a,i,[]);return A.normalizeVec3(r,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),a=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),a+=A.lenVec3(A.subVec3(t,i,[])),n.push(a),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,a=n.length;s=t||e*n[a-1];for(var r,l=0,o=a-1;l<=o;)if((r=n[i=Math.floor(l+(o-l)/2)]-s)<0)l=i+1;else{if(!(r>0)){o=i;break}o=i-1}if(n[i=o]===s)return i/(a-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(a-1)}}class ce extends oe{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,a=t[0===n?n:n-1],r=t[n],l=t[n>t.length-2?t.length-1:n+1],o=t[n>t.length-3?t.length-1:n+2],c=A.vec3();return c[0]=A.catmullRomInterpolate(a[0],r[0],l[0],o[0],i),c[1]=A.catmullRomInterpolate(a[1],r[1],l[1],o[1],i),c[2]=A.catmullRomInterpolate(a[2],r[2],l[2],o[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const ue=A.vec3();class he extends B{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new ce(this),this._lookCurve=new ce(this),this._upCurve=new ce(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,s,n){const i={t:e,eye:t.slice(0),look:s.slice(0),up:n.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}addFrames(e){let t;for(let s=0,n=e.length;s1?1:e,t.eye=this._eyeCurve.getPoint(e,ue),t.look=this._lookCurve.getPoint(e,ue),t.up=this._upCurve.getPoint(e,ue)}sampleFrame(e,t,s,n){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,s),this._upCurve.getPoint(e,n)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=A.vec3();var s=0;this._frames[0].t=0;const n=[];for(let e=1,a=this._frames.length;e=1;e>1&&(e=1);const s=this.easing?ye._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(A.subVec3(n.eye,n.look,Ie),n.eye=A.lerpVec3(s,0,1,this._eye1,this._eye2,de),n.look=A.subVec3(de,Ie,Ae)):this._flyingLook&&(n.look=A.lerpVec3(s,0,1,this._look1,this._look2,Ae),n.up=A.lerpVec3(s,0,1,this._up1,this._up2,fe)):this._flyingEyeLookUp&&(n.eye=A.lerpVec3(s,0,1,this._eye1,this._eye2,de),n.look=A.lerpVec3(s,0,1,this._look1,this._look2,Ae),n.up=A.lerpVec3(s,0,1,this._up1,this._up2,fe)),this._projection2){const t="ortho"===this._projection2?ye._easeOutExpo(e,0,1,1):ye._easeInCubic(e,0,1,1);n.customProjection.matrix=A.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();C.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class me extends B{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new ye(this),this._t=0,this.state=me.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case me.SCRUBBING:return;case me.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=me.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case me.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=me.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=me.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=me.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=me.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=me.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=me.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=me.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}me.STOPPED=0,me.SCRUBBING=1,me.PLAYING=2,me.PLAYING_TO=3;class ve extends B{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),f.memory.meshes++}destroy(){super.destroy(),f.memory.meshes--}}const we=new e({});class ge{constructor(e){this.id=we.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){we.removeItem(this.id)}}class Te{constructor(e,t,s,n,i,a,r,l,o){switch(this._gl=e,this.type=t,this.allocated=!1,s.constructor){case Uint8Array:this.itemType=e.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=e.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=e.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=e.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=e.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=e.INT,this.itemByteSize=4;break;default:this.itemType=e.FLOAT,this.itemByteSize=4}this.usage=a,this.length=0,this.dataLength=n,this.numItems=0,this.itemSize=i,this.normalized=!!r,this.stride=l||0,this.offset=o||0,this._allocate(s)}_allocate(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}var Ee=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=A.vec3(),u=A.vec3(),h=A.vec3(),p=A.vec3(),d=A.vec3(),f=A.vec3(),I=A.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();const be=function(){const e=A.mat4(),t=A.mat4();return function(s,n){n=n||A.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return A.identityMat4(e),A.translationMat4v(s,e),A.identityMat4(t),A.scalingMat4v([l/u,o/u,c/u],t),A.mulMat4(e,t,n),n}}();var De=function(){const e=A.mat4(),t=A.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function Ce(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function _e(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const Be={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=Re(e,l,"floor","ceil"),n=Ce(s),a=_e(e,l,n),a>r&&(i=s,r=a),s=Re(e,l,"ceil","ceil"),n=Ce(s),a=_e(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},Oe=f.memory,Se=A.AABB3();class Ne extends ve{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new ge({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=Be.getPositionsBounds(t.positions),n=Be.compressPositions(t.positions,e.min,e.max);s.positions=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=Be.getUVBounds(t.uv),n=Be.compressUVs(t.uv,e.min,e.max);s.uv=n.quantized,s.uvDecodeMatrix=n.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);t.normals&&(this._state.compressGeometry?s.normals=Be.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),Oe.meshes++,this._buildVBOs()}_buildVBOs(){const e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),Oe.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new Te(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),Oe.positions+=e.positionsBuf.numItems),e.normals){let s=e.compressGeometry;e.normalsBuf=new Te(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,s),Oe.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new Te(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),Oe.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new Te(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),Oe.uvs+=e.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=Ee(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),Oe.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=A.buildPickTriangles(e.positions,e.indices,e.compressGeometry),n=s.positions,i=s.colors;this._pickTrianglePositionsBuf=new Te(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new Te(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),Oe.positions+=this._pickTrianglePositionsBuf.numItems,Oe.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}_webglContextLost(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}_webglContextRestored(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),Be.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=Be.getPositionsBounds(e),n=Be.compressPositions(e,s.min,s.max);e=n.quantized,t.positionsDecodeMatrix=n.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),Be.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),Be.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=A.AABB3()),A.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=A.OBB3()),A.positions3ToAABB3(this._state.positions,Se,this._state.positionsDecodeMatrix),A.AABB3ToOBB3(Se,this._obb),this._obbDirty=!1),this._obb}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),Oe.meshes--}}const xe=f.memory,Le=A.AABB3();class Me extends ve{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new ge({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=A.OBB3();const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var i;if(t.positionsDecodeMatrix);else{const e=Be.getPositionsBounds(t.positions),a=Be.compressPositions(t.positions,e.min,e.max);i=a.quantized,s.positionsDecodeMatrix=a.decodeMatrix,s.positionsBuf=new Te(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),xe.positions+=s.positionsBuf.numItems,A.positions3ToAABB3(t.positions,this._aabb),A.positions3ToAABB3(i,Le,s.positionsDecodeMatrix),A.AABB3ToOBB3(Le,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new Te(n,n.ARRAY_BUFFER,e,e.length,4,n.STATIC_DRAW),xe.colors+=s.colorsBuf.numItems}if(t.uv){const e=Be.getUVBounds(t.uv),i=Be.compressUVs(t.uv,e.min,e.max),a=i.quantized;s.uvDecodeMatrix=i.decodeMatrix,s.uvBuf=new Te(n,n.ARRAY_BUFFER,a,a.length,2,n.STATIC_DRAW),xe.uvs+=s.uvBuf.numItems}if(t.normals){const e=Be.compressNormals(t.normals);let i=s.compressGeometry;s.normalsBuf=new Te(n,n.ARRAY_BUFFER,e,e.length,3,n.STATIC_DRAW,i),xe.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new Te(n,n.ELEMENT_ARRAY_BUFFER,e,e.length,1,n.STATIC_DRAW),xe.indices+=s.indicesBuf.numItems;const a=Ee(i,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new Te(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),xe.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),xe.meshes--}}var Fe={};function He(e,t={}){return new Promise((function(s,n){t.src||(console.error("load3DSGeometry: Parameter expected: src"),n());var i=e.canvas.spinner;i.processes++,v.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,n());var a=Fe.parse.from3DS(e).edit.objects[0].mesh,r=a.vertices,l=a.uvt,o=a.indices;i.processes--,s(v.apply(t,{primitive:"triangles",positions:r,normals:null,uv:l,indices:o}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,n()}))}))}function Ue(e,t={}){return new Promise((function(s,n){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),n());var i=e.canvas.spinner;i.processes++,v.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,n());for(var a=Fe.parse.fromOBJ(e),r=Fe.edit.unwrap(a.i_verts,a.c_verts,3),l=Fe.edit.unwrap(a.i_norms,a.c_norms,3),o=Fe.edit.unwrap(a.i_uvt,a.c_uvt,2),c=new Int32Array(a.i_verts.length),u=0;u0?l:null,autoNormals:0===l.length,uv:o,indices:c}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,n()}))}))}function Ge(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return v.apply(e,{positions:[h,p,A,o,p,A,o,c,A,h,c,A,h,p,A,h,c,A,h,c,u,h,p,u,h,p,A,h,p,u,o,p,u,o,p,A,o,p,A,o,p,u,o,c,u,o,c,A,o,c,u,h,c,u,h,c,A,o,c,A,h,c,u,o,c,u,o,p,u,h,p,u],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function je(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return v.apply(e,{primitive:"lines",positions:[o,c,u,o,c,A,o,p,u,o,p,A,h,c,u,h,c,A,h,p,u,h,p,A],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function Ve(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let n=e.height||1;n<0&&(console.error("negative height not allowed - will invert"),n*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);let a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);const r=!!e.openEnded;let l=e.center;const o=l?l[0]:0,c=l?l[1]:0,u=l?l[2]:0,h=n/2,p=n/a,A=2*Math.PI/i,d=1/i,f=(t-s)/a,I=[],y=[],m=[],w=[];let g,T,E,b,D,P,R,C,_,B,O;const S=(90-180*Math.atan(n/(s-t))/Math.PI)/90;for(g=0;g<=a;g++)for(D=t-g*f,P=h-g*p,T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),y.push(D*E),y.push(S),y.push(D*b),m.push(T*d),m.push(1*g/a),I.push(D*E+o),I.push(P+c),I.push(D*b+u);for(g=0;g0){for(_=I.length/3,y.push(0),y.push(1),y.push(0),m.push(.5),m.push(.5),I.push(0+o),I.push(h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,y.push(t*E),y.push(1),y.push(t*b),m.push(B),m.push(O),I.push(t*E+o),I.push(h+c),I.push(t*b+u);for(T=0;T0){for(_=I.length/3,y.push(0),y.push(-1),y.push(0),m.push(.5),m.push(.5),I.push(0+o),I.push(0-h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,y.push(s*E),y.push(-1),y.push(s*b),m.push(B),m.push(O),I.push(s*E+o),I.push(0-h+c),I.push(s*b+u);for(T=0;T65535?Uint32Array:Uint16Array)(h*p*6);for(g=0;g360&&(a=360);const r=e.center;let l=r?r[0]:0,o=r?r[1]:0;const c=r?r[2]:0,u=[],h=[],p=[],d=[];let f,I,y,m,w,g,T,E,b,D,P,R;for(E=0;E<=i;E++)for(T=0;T<=n;T++)f=T/n*a,I=.785398+E/i*Math.PI*2,l=t*Math.cos(f),o=t*Math.sin(f),y=(t+s*Math.cos(I))*Math.cos(f),m=(t+s*Math.cos(I))*Math.sin(f),w=s*Math.sin(I),u.push(y+l),u.push(m+o),u.push(w+c),p.push(1-T/n),p.push(E/i),g=A.normalizeVec3(A.subVec3([y,m,w],[l,o,c],[]),[]),h.push(g[0]),h.push(g[1]),h.push(g[2]);for(E=1;E<=i;E++)for(T=1;T<=n;T++)b=(n+1)*E+T-1,D=(n+1)*(E-1)+T-1,P=(n+1)*(E-1)+T,R=(n+1)*E+T,d.push(b),d.push(D),d.push(P),d.push(P),d.push(R),d.push(b);return v.apply(e,{positions:u,normals:h,uv:p,indices:d})}Fe.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},Fe.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(Fe.parse._buffToStr(e));window.location.href=s},Fe.clone=function(e){return JSON.parse(JSON.stringify(e))},Fe.bin={},Fe.bin.f=new Float32Array(1),Fe.bin.fb=new Uint8Array(Fe.bin.f.buffer),Fe.bin.rf=function(e,t){for(var s=Fe.bin.f,n=Fe.bin.fb,i=0;i<4;i++)n[i]=e[t+i];return s[0]},Fe.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Fe.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Fe.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},Fe.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},Fe.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},Fe.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},Fe.parse={},Fe.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",n=0;ni&&(i=o),ca&&(a=c),ur&&(r=u)}return{min:{x:t,y:s,z:n},max:{x:i,y:a,z:r}}};const Ke={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function Ye(e={}){var t=e.origin||[0,0,0],s=t[0],n=t[1],i=t[2],a=e.size||1,r=[],l=[],o=e.text;v.isNumeric(o)&&(o=""+o);for(var c,u,h,p,A,d,f,I,y,m=(o||"").split("\n"),w=0,g=0,T=.04,E=0;E0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice();let t;for(let s=0,n=e.length;s0,o=!!i.compressGeometry,c=[];c.push("#version 300 es"),c.push("// Lambertian drawing vertex shader"),c.push("in vec3 position;"),c.push("uniform mat4 modelMatrix;"),c.push("uniform mat4 viewMatrix;"),c.push("uniform mat4 projMatrix;"),c.push("uniform vec4 colorize;"),c.push("uniform vec3 offset;"),o&&c.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(c.push("uniform float logDepthBufFC;"),c.push("out float vFragDepth;"),c.push("bool isPerspectiveMatrix(mat4 m) {"),c.push(" return (m[2][3] == - 1.0);"),c.push("}"),c.push("out float isPerspective;"));l&&c.push("out vec4 vWorldPosition;");if(c.push("uniform vec4 lightAmbient;"),c.push("uniform vec4 materialColor;"),c.push("uniform vec3 materialEmissive;"),i.normalsBuf){c.push("in vec3 normal;"),c.push("uniform mat4 modelNormalMatrix;"),c.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),c.push(" }"),c.push(" return normalize(v);"),c.push("}"))}c.push("out vec4 vColor;"),"points"===i.primitiveName&&c.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(c.push("void billboard(inout mat4 mat) {"),c.push(" mat[0][0] = 1.0;"),c.push(" mat[0][1] = 0.0;"),c.push(" mat[0][2] = 0.0;"),"spherical"===a&&(c.push(" mat[1][0] = 0.0;"),c.push(" mat[1][1] = 1.0;"),c.push(" mat[1][2] = 0.0;")),c.push(" mat[2][0] = 0.0;"),c.push(" mat[2][1] = 0.0;"),c.push(" mat[2][2] =1.0;"),c.push("}"));c.push("void main(void) {"),c.push("vec4 localPosition = vec4(position, 1.0); "),c.push("vec4 worldPosition;"),o&&c.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(o?c.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):c.push("vec4 localNormal = vec4(normal, 0.0); "),c.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),c.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));c.push("mat4 viewMatrix2 = viewMatrix;"),c.push("mat4 modelMatrix2 = modelMatrix;"),r&&c.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(c.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),c.push("billboard(modelMatrix2);"),c.push("billboard(viewMatrix2);"),c.push("billboard(modelViewMatrix);"),i.normalsBuf&&(c.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),c.push("billboard(modelNormalMatrix2);"),c.push("billboard(viewNormalMatrix2);"),c.push("billboard(modelViewNormalMatrix);")),c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&c.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(c.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),c.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),c.push("float lambertian = 1.0;"),i.normalsBuf)for(let e=0,t=n.lights.length;e0,a=t.gammaOutput,r=[];r.push("#version 300 es"),r.push("// Lambertian drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(i){r.push("in vec4 vWorldPosition;"),r.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),r.push("}")}"points"===n.primitiveName&&(r.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),r.push("float r = dot(cxy, cxy);"),r.push("if (r > 1.0) {"),r.push(" discard;"),r.push("}"));t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?r.push("outColor = linearToGamma(vColor, gammaFactor);"):r.push("outColor = vColor;");return r.push("}"),r}(e)):(this.vertex=function(e){const t=e.scene;e._material;const s=e._state,n=t._sectionPlanesState,i=e._geometry._state,a=t._lightsState;let r;const l=s.billboard,o=s.background,c=s.stationary,u=function(e){if(!e._geometry._state.uvBuf)return!1;const t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),h=Ts(e),p=n.sectionPlanes.length>0,A=gs(e),d=!!i.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),d&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),p&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));a.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(h){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(let e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}u&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),d&&f.push("uniform mat3 uvDecodeMatrix;"));i.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===i.primitiveName&&f.push("uniform float pointSize;");"spherical"!==l&&"cylindrical"!==l||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===l&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(A){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(let e=0,t=a.lights.length;e0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(let e=0,t=a.lights.length;e0,o=Ts(e),c=n.uvBuf,u="PhongMaterial"===r.type,h="MetallicMaterial"===r.type,p="SpecularMaterial"===r.type,A=gs(e);t.gammaInput;const d=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));A&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),d&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(l){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var I=0;I0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),u&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = "+ws[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(h||p)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),a.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+ws[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),n.colors&&f.push("in vec4 vColor;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._occlusionMap||s._alphaMap)&&f.push("in vec2 vUV;");o&&(a.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));r.ambient&&f.push("uniform vec3 materialAmbient;");r.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==r.alpha&&null!==r.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");r.emissive&&f.push("uniform vec3 materialEmissive;");r.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==r.glossiness&&null!==r.glossiness&&f.push("uniform float materialGlossiness;");void 0!==r.shininess&&null!==r.shininess&&f.push("uniform float materialShininess;");r.specular&&f.push("uniform vec3 materialSpecular;");void 0!==r.metallic&&null!==r.metallic&&f.push("uniform float materialMetallic;");void 0!==r.roughness&&null!==r.roughness&&f.push("uniform float materialRoughness;");void 0!==r.specularF0&&null!==r.specularF0&&f.push("uniform float materialSpecularF0;");c&&s._ambientMap&&(f.push("uniform sampler2D ambientMap;"),s._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));c&&s._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),s._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));c&&s._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),s._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));c&&s._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),s._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));o&&c&&s._metallicMap&&(f.push("uniform sampler2D metallicMap;"),s._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));o&&c&&s._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),s._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));o&&c&&s._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),s._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));o&&s._normalMap&&(f.push("uniform sampler2D normalMap;"),s._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));c&&s._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),s._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));c&&s._alphaMap&&(f.push("uniform sampler2D alphaMap;"),s._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));o&&c&&s._specularMap&&(f.push("uniform sampler2D specularMap;"),s._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));o&&c&&s._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),s._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));o&&c&&s._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),s._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));o&&(s._diffuseFresnel||s._specularFresnel||s._alphaFresnel||s._emissiveFresnel||s._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),s._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),s._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),s._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),s._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),s._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),o)for(let e=0,t=a.lights.length;e 0.0) { discard; }"),f.push("}")}"points"===n.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),r.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");r.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):r.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");n.colors&&f.push("diffuseColor *= vColor.rgb;");r.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");r.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==r.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");n.colors&&f.push("alpha *= vColor.a;");void 0!==r.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==r.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==r.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==r.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._occlusionMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));c&&s._ambientMap&&(s._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+ws[s._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));c&&s._diffuseMap&&(s._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+ws[s._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));c&&s._baseColorMap&&(s._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+ws[s._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));c&&s._emissiveMap&&(s._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+ws[s._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));c&&s._alphaMap&&(s._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));c&&s._occlusionMap&&(s._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(o&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){c&&s._normalMap?(s._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),c&&s._specularMap&&(s._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),c&&s._glossinessMap&&(s._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),c&&s._specularGlossinessMap&&(s._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),c&&s._metallicMap&&(s._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),c&&s._roughnessMap&&(s._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),c&&s._metallicRoughnessMap&&(s._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),s._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),s._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),s._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),s._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),u&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),p&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),h&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),u&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||h)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(let e=0,t=a.lights.length;e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function Cs(e){console.error(e.join("\n"))}class _s{constructor(e,t){this.id=Ps.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new Es(e,e.VERTEX_SHADER,Rs(this.source.vertex)),this._fragmentShader=new Es(e,e.FRAGMENT_SHADER,Rs(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void Cs(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void Cs(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void Cs(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void Cs(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void Cs(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;s0?Bs.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?Bs.FS_MAX_FLOAT_PRECISION="mediump":Bs.FS_MAX_FLOAT_PRECISION="lowp":Bs.FS_MAX_FLOAT_PRECISION="mediump",Bs.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),Bs.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),Bs.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),Bs.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),Bs.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Bs.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),Bs.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),Bs.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),Bs.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),Bs.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){Bs.SUPPORTED_EXTENSIONS[e]=!0})))}const Ss=A.vec3(),Ns=new e({}),xs=function(e,t){this.id=Ns.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new vs(t),this._allocate(t)},Ls={};xs.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,(t.gammaInput?"gi;":";")+(t.gammaOutput?"go":""),t._lightsState.getHash(),t._sectionPlanesState.getHash(),e._geometry._state.hash,e._material._state.hash,e._state.drawHash].join(";");let n=Ls[s];if(!n){if(n=new xs(s,e),n.errors)return console.log(n.errors.join("\n")),null;Ls[s]=n,f.memory.programs++}return n._useCount++,n},xs.prototype.put=function(){0==--this._useCount&&(Ns.removeItem(this.id),this._program&&this._program.destroy(),delete Ls[this._hash],f.memory.programs--)},xs.prototype.webglContextRestored=function(){this._program=null},xs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=Bs.MAX_TEXTURE_UNITS,n=t.scene,i=t._material,a=n.canvas.gl,r=this._program,l=t._state,o=t._material._state,c=t._geometry._state,u=n.camera,h=t.origin,p=l.background;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,p&&a.depthFunc(a.LEQUAL),this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,h?e.getRTCViewMatrix(l.originHash,h):u.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,u.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(u=0,h=a.sectionPlanes.length;u0&&i.lightMaps[0].texture&&this._uLightMap&&(l.bindTexture(this._uLightMap,i.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),i.reflectionMaps.length>0&&i.reflectionMaps[0].texture&&this._uReflectionMap&&(l.bindTexture(this._uReflectionMap,i.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),this._uGammaFactor&&n.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};class Ms{constructor(e){this.vertex=function(e){const t=e.scene,s=t._lightsState,n=function(e){const t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,r=e._state.billboard,l=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// EmphasisFillShaderSource vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 colorize;"),o.push("uniform vec3 offset;"),a&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");if(o.push("uniform vec4 lightAmbient;"),o.push("uniform vec4 fillColor;"),n){o.push("in vec3 normal;"),o.push("uniform mat4 modelNormalMatrix;"),o.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"))}o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),a&&o.push("localPosition = positionsDecodeMatrix * localPosition;");n&&(a?o.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):o.push("vec4 localNormal = vec4(normal, 0.0); "),o.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),o.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),l&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),n&&(o.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),o.push("billboard(modelNormalMatrix2);"),o.push("billboard(viewNormalMatrix2);"),o.push("billboard(modelViewNormalMatrix);")),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&o.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),n)for(let e=0,t=s.lights.length;e0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const Fs=new e({}),Hs=A.vec3(),Us=function(e,t){this.id=Fs.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ms(t),this._allocate(t)},Gs={};Us.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Gs[t];return s||(s=new Us(t,e),Gs[t]=s,f.memory.programs++),s._useCount++,s},Us.prototype.put=function(){0==--this._useCount&&(Fs.removeItem(this.id),this._program&&this._program.destroy(),delete Gs[this._hash],f.memory.programs--)},Us.prototype.webglContextRestored=function(){this._program=null},Us.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl,r=0===s?t._xrayMaterial._state:1===s?t._highlightMaterial._state:t._selectedMaterial._state,l=t._state,o=t._geometry._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Edges drawing vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec4 edgeColor;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));s&&r.push("out vec4 vWorldPosition;");r.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.push("vColor = edgeColor;"),s&&r.push("vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=e.scene._sectionPlanesState,n=e.scene.gammaOutput,i=s.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const Vs=new e({}),ks=A.vec3(),Qs=function(e,t){this.id=Vs.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new js(t),this._allocate(t)},Ws={};Qs.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Ws[t];return s||(s=new Qs(t,e),Ws[t]=s,f.memory.programs++),s._useCount++,s},Qs.prototype.put=function(){0==--this._useCount&&(Vs.removeItem(this.id),this._program&&this._program.destroy(),delete Ws[this._hash],f.memory.programs--)},Qs.prototype.webglContextRestored=function(){this._program=null},Qs.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl;let r;const l=t._state,o=t._geometry,c=o._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(l.originHash,u):i.viewMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh picking vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("out vec4 vViewPosition;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"));r.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(e)}}const Ks=A.vec3(),Ys=function(e,t){this._hash=e,this._shaderSource=new zs(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Xs={};Ys.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let s=Xs[t];if(!s){if(s=new Ys(t,e),s.errors)return console.log(s.errors.join("\n")),null;Xs[t]=s,f.memory.programs++}return s._useCount++,s},Ys.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Xs[this._hash],f.memory.programs--)},Ys.prototype.webglContextRestored=function(){this._program=null},Ys.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t>24&255,u=o>>16&255,h=o>>8&255,p=255&o;n.uniform4f(this._uPickColor,p/255,h/255,u/255,c/255),r.indicesBuf?(n.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&n.drawArrays(n.TRIANGLES,0,r.positions.numItems)},Ys.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new _s(s,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0,n=!!e._geometry._state.compressGeometry;e._state.billboard,e._state.stationary;const i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),s&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("out vec4 vColor;"),n&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),n&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),s&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = clipPos;"),i.push("}"),i}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(e)}}const Js=A.vec3(),Zs=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new qs(t),this._allocate(t)},$s={};Zs.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=$s[t];if(!s){if(s=new Zs(t,e),s.errors)return console.log(s.errors.join("\n")),null;$s[t]=s,f.memory.programs++}return s._useCount++,s},Zs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete $s[this._hash],f.memory.programs--)},Zs.prototype.webglContextRestored=function(){this._program=null},Zs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry,l=t._geometry._state,o=t.origin,c=a.backfaces,u=a.frontface,h=s.camera.project,p=r._getPickTrianglePositions(),A=r._getPickTriangleColors();if(this._program.bind(),e.useProgram++,s.logarithmicDepthBufferEnabled){const e=2/(Math.log(h.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,e)}if(n.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(e)}}const tn=A.vec3(),sn=function(e,t){this._hash=e,this._shaderSource=new en(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},nn={};sn.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";");let s=nn[t];if(!s){if(s=new sn(t,e),s.errors)return console.log(s.errors.join("\n")),null;nn[t]=s,f.memory.programs++}return s._useCount++,s},sn.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete nn[this._hash],f.memory.programs--)},sn.prototype.webglContextRestored=function(){this._program=null},sn.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._material._state,a=t._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){const t=i.backfaces;e.backfaces!==t&&(t?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=t);const s=i.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),this._lastMaterialId=i.id}const o=s.camera;if(n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCViewMatrix(a.originHash,l):o.viewMatrix),a.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,s=!!e._geometry._state.compressGeometry,n=[];n.push("// Mesh shadow vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),n.push("uniform vec3 offset;"),s&&n.push("uniform mat4 positionsDecodeMatrix;");t&&n.push("out vec4 vWorldPosition;");n.push("void main(void) {"),n.push("vec4 localPosition = vec4(position, 1.0); "),n.push("vec4 worldPosition;"),s&&n.push("localPosition = positionsDecodeMatrix * localPosition;");n.push("worldPosition = modelMatrix * localPosition;"),n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&n.push("vWorldPosition = worldPosition;");return n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n}(e),this.fragment=function(e){const t=e.scene;t.canvas.gl;const s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(e)}}const rn=function(e,t){this._hash=e,this._shaderSource=new an(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},ln={};rn.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let n=ln[s];if(!n){if(n=new rn(s,e),n.errors)return console.log(n.errors.join("\n")),null;ln[s]=n,f.memory.programs++}return n._useCount++,n},rn.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete ln[this._hash],f.memory.programs--)},rn.prototype.webglContextRestored=function(){this._program=null},rn.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene.canvas.gl,n=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.id!==this._lastMaterialId){const t=n.backfaces;e.backfaces!==t&&(t?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=t);const i=n.frontface;e.frontface!==i&&(i?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=i),e.lineWidth!==n.lineWidth&&(s.lineWidth(n.lineWidth),e.lineWidth=n.lineWidth),this._uPointSize&&s.uniform1i(this._uPointSize,n.pointSize),this._lastMaterialId=n.id}if(s.uniformMatrix4fv(this._uModelMatrix,s.FALSE,t.worldMatrix),i.combineGeometry){const n=t.vertexBufs;n.id!==this._lastVertexBufsId&&(n.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(n.positionsBuf,n.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),this._lastVertexBufsId=n.id)}this._uClippable&&s.uniform1i(this._uClippable,t._state.clippable),s.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(s.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(s.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(s.drawArrays(s.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},rn.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new _s(s,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uShadowViewMatrix=n.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=n.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0){let e,t,i,a,r;for(let l=0,o=this._uSectionPlanes.length;l0)for(let s=0;s0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const wn=function(){const e=A.vec3(),t=A.vec3(),s=A.vec3(),n=A.vec3(),i=A.vec3(),a=A.vec3(),r=A.vec4(),l=A.vec3(),o=A.vec3(),c=A.vec3(),u=A.vec3(),h=A.vec3(),p=A.vec3(),d=A.vec3(),f=A.vec3(),I=A.vec3(),y=A.vec4(),m=A.vec4(),v=A.vec4(),w=A.vec3(),g=A.vec3(),T=A.vec3(),E=A.vec3(),b=A.vec3(),D=A.vec3(),P=A.vec3(),R=A.vec3(),C=A.vec3(),_=A.vec3(),B=A.vec3();return function(O,N,x,L){var M=L.primIndex;if(null!=M&&M>-1){const G=O.geometry._state,j=O.scene,V=j.camera,k=j.canvas;if("triangles"===G.primitiveName){L.primitive="triangle";const j=M,Q=G.indices,W=G.positions;let z,K,Y;if(Q){var F=Q[j+0],H=Q[j+1],U=Q[j+2];a[0]=F,a[1]=H,a[2]=U,L.indices=a,z=3*F,K=3*H,Y=3*U}else z=3*j,K=z+3,Y=K+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],n[0]=W[K+0],n[1]=W[K+1],n[2]=W[K+2],i[0]=W[Y+0],i[1]=W[Y+1],i[2]=W[Y+2],G.compressGeometry){const e=G.positionsDecodeMatrix;e&&(Be.decompressPosition(s,e,s),Be.decompressPosition(n,e,n),Be.decompressPosition(i,e,i))}L.canvasPos?A.canvasPosToLocalRay(k.canvas,O.origin?S(N,O.origin):N,x,O.worldMatrix,L.canvasPos,e,t):L.origin&&L.direction&&A.worldRayToLocalRay(O.worldMatrix,L.origin,L.direction,e,t),A.normalizeVec3(t),A.rayPlaneIntersect(e,t,s,n,i,r),L.localPos=r,L.position=r,y[0]=r[0],y[1]=r[1],y[2]=r[2],y[3]=1,A.transformVec4(O.worldMatrix,y,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],L.canvasPos&&O.origin&&(l[0]+=O.origin[0],l[1]+=O.origin[1],l[2]+=O.origin[2]),L.worldPos=l,A.transformVec4(V.matrix,m,v),o[0]=v[0],o[1]=v[1],o[2]=v[2],L.viewPos=o,A.cartesianToBarycentric(r,s,n,i,c),L.bary=c;const X=G.normals;if(X){if(G.compressGeometry){const e=3*F,t=3*H,s=3*U;Be.decompressNormal(X.subarray(e,e+2),u),Be.decompressNormal(X.subarray(t,t+2),h),Be.decompressNormal(X.subarray(s,s+2),p)}else u[0]=X[z],u[1]=X[z+1],u[2]=X[z+2],h[0]=X[K],h[1]=X[K+1],h[2]=X[K+2],p[0]=X[Y],p[1]=X[Y+1],p[2]=X[Y+2];const e=A.addVec3(A.addVec3(A.mulVec3Scalar(u,c[0],w),A.mulVec3Scalar(h,c[1],g),T),A.mulVec3Scalar(p,c[2],E),b);L.worldNormal=A.normalizeVec3(A.transformVec3(O.worldNormalMatrix,e,D))}const q=G.uv;if(q){if(d[0]=q[2*F],d[1]=q[2*F+1],f[0]=q[2*H],f[1]=q[2*H+1],I[0]=q[2*U],I[1]=q[2*U+1],G.compressGeometry){const e=G.uvDecodeMatrix;e&&(Be.decompressUV(d,e,d),Be.decompressUV(f,e,f),Be.decompressUV(I,e,I))}L.uv=A.addVec3(A.addVec3(A.mulVec2Scalar(d,c[0],P),A.mulVec2Scalar(f,c[1],R),C),A.mulVec2Scalar(I,c[2],_),B)}}}}}();class gn extends B{get type(){return"Material"}constructor(e,t={}){super(e,t),f.memory.materials++}destroy(){super.destroy(),f.memory.materials--}}const Tn={opaque:0,mask:1,blend:2},En=["opaque","mask","blend"];class bn extends gn{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new ge({type:"PhongMaterial",ambient:A.vec3([1,1,1]),diffuse:A.vec3([1,1,1]),specular:A.vec3([1,1,1]),emissive:A.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=Tn[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return En[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}function Dn(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];let s;switch(t){case"WEBGL_depth_texture":s=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":s=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":s=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=e.getExtension(t)}return e._cachedExtensions[t]=s,s}function Pn(e,t,s=null){let n;const i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===s){const t=Dn(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===i)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(n=Dn(e,"WEBGL_compressed_texture_s3tc"),null===n)return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){const t=Dn(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===i)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){const t=Dn(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){const t=Dn(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===i)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){const t=Dn(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){const t=Dn(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===i)return 3001===s?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}const Rn=new Uint8Array([0,0,0,1]);class Cn{constructor({gl:e,target:t,format:s,type:n,wrapS:i,wrapT:a,wrapR:r,encoding:l,preloadColor:o,premultiplyAlpha:c,flipY:u}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=s||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!u,this.unpackAlignment=4,this.wrapS=i||1e3,this.wrapT=a||1e3,this.wrapR=r||1e3,this.encoding=l||3001,this.texture=e.createTexture(),o&&this.setPreloadColor(o),this.allocated=!0}setPreloadColor(e){e?(Rn[0]=Math.floor(255*e[0]),Rn[1]=Math.floor(255*e[1]),Rn[2]=Math.floor(255*e[2]),Rn[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(Rn[0]=0,Rn[1]=0,Rn[2]=0,Rn[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let s=0,n=e.length;s1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=Pn(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=Pn(s,this.wrapT);if(r&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,r),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=Pn(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}i?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Bn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Bn(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Pn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Pn(s,this.magFilter)));const l=Pn(s,this.format,this.encoding),o=Pn(s,this.type),c=_n(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t>t;return e+1}class xn extends B{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new ge({texture:new Cn({gl:this.scene.canvas.gl}),matrix:A.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=A.vec2([0,0]),this._scale=A.vec2([1,1]),this._rotate=A.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),f.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this._state.texture=new Cn({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}_update(){const e=this._state;if(this._matrixDirty){let t,s;0===this._translate[0]&&0===this._translate[1]||(t=A.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=A.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?A.mulMat4(t,s):s),0!==this._rotate&&(s=A.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?A.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=On(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let s=new Image;s.onload=function(){s=On(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),f.memory.textures--}}const Ln=A.vec3(),Mn=A.vec3();A.vec3();const Fn=A.vec3([0,-1,0]),Hn=A.vec4([0,0,0,1]);class Un extends B{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=A.vec3(),this._origin=A.vec3(),this._rtcPos=A.vec3(),this._dir=A.vec3(),this._size=1,this._imageSize=A.vec2(),this._texture=new xn(this),this._plane=new vn(this,{geometry:new Ne(this,Qe({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new bn(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new vn(this,{geometry:new Ne(this,ke({size:1,divisions:10})),material:new bn(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new it(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),N(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,s=[-this._dir[0],-this._dir[1],-this._dir[2]];A.subVec3(t,this.position,Ln);const n=-A.dotVec3(s,Ln);A.normalizeVec3(s),A.mulVec3Scalar(s,n,Mn),A.vec3PairToQuaternion(Fn,e,Hn),this._node.quaternion=Hn}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],s=this._imageSize[1];if(t>s){const n=s/t;this._node.scale=[e,1,e*n]}else{const n=t/s;this._node.scale=[e*n,1,e]}}}class Gn extends gn{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new ge({type:"LambertMaterial",ambient:A.vec3([1,1,1]),color:A.vec3([1,1,1]),emissive:A.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),this.ambient=t.ambient,this.color=t.color,this.emissive=t.emissive,this.alpha=t.alpha,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this.backfaces=t.backfaces,this.frontface=t.frontface}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set color(e){let t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get color(){return this._state.color}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}get alpha(){return this._state.alpha}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}const jn={opaque:0,mask:1,blend:2},Vn=["opaque","mask","blend"];class kn extends gn{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new ge({type:"MetallicMaterial",baseColor:A.vec4([1,1,1]),emissive:A.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.baseColor=t.baseColor,this.metallic=t.metallic,this.roughness=t.roughness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.baseColorMap&&(this._baseColorMap=this._checkComponent("Texture",t.baseColorMap)),t.metallicMap&&(this._metallicMap=this._checkComponent("Texture",t.metallicMap)),t.roughnessMap&&(this._roughnessMap=this._checkComponent("Texture",t.roughnessMap)),t.metallicRoughnessMap&&(this._metallicRoughnessMap=this._checkComponent("Texture",t.metallicRoughnessMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set baseColor(e){let t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get baseColor(){return this._state.baseColor}get baseColorMap(){return this._baseColorMap}set metallic(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}get metallic(){return this._state.metallic}get metallicMap(){return this._attached.metallicMap}set roughness(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}get roughness(){return this._state.roughness}get roughnessMap(){return this._attached.roughnessMap}get metallicRoughnessMap(){return this._attached.metallicRoughnessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._attached.emissiveMap}get occlusionMap(){return this._attached.occlusionMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._attached.alphaMap}get normalMap(){return this._attached.normalMap}set alphaMode(e){let t=jn[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Vn[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const Qn={opaque:0,mask:1,blend:2},Wn=["opaque","mask","blend"];class zn extends gn{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new ge({type:"SpecularMaterial",diffuse:A.vec3([1,1,1]),emissive:A.vec3([0,0,0]),specular:A.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.diffuse=t.diffuse,this.specular=t.specular,this.glossiness=t.glossiness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.glossinessMap&&(this._glossinessMap=this._checkComponent("Texture",t.glossinessMap)),t.specularGlossinessMap&&(this._specularGlossinessMap=this._checkComponent("Texture",t.specularGlossinessMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}get diffuseMap(){return this._diffuseMap}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}get specularMap(){return this._specularMap}get specularGlossinessMap(){return this._specularGlossinessMap}set glossiness(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}get glossiness(){return this._state.glossiness}get glossinessMap(){return this._glossinessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._emissiveMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._alphaMap}get normalMap(){return this._normalMap}get occlusionMap(){return this._occlusionMap}set alphaMode(e){let t=Qn[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Wn[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const Kn={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class Yn extends gn{get type(){return"EmphasisMaterial"}get presets(){return Kn}constructor(e,t={}){super(e,t),this._state=new ge({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(e=e||"default",this._preset===e)return;const t=Kn[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Kn).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Xn={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class qn extends gn{get type(){return"EdgeMaterial"}get presets(){return Xn}constructor(e,t={}){super(e,t),this._state=new ge({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Xn[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Xn).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class Jn extends B{get type(){return"Fresnel"}constructor(e,t={}){super(e,t),this._state=new ge({edgeColor:A.vec3([0,0,0]),centerColor:A.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),this.edgeColor=t.edgeColor,this.centerColor=t.centerColor,this.edgeBias=t.edgeBias,this.centerBias=t.centerBias,this.power=t.power}set edgeColor(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set centerColor(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}get centerColor(){return this._state.centerColor}set edgeBias(e){this._state.edgeBias=e||0,this.glRedraw()}get edgeBias(){return this._state.edgeBias}set centerBias(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}get centerBias(){return this._state.centerBias}set power(e){this._state.power=null!=e?e:1,this.glRedraw()}get power(){return this._state.power}destroy(){super.destroy(),this._state.destroy()}}class Zn extends B{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=A.vec3(t.pos||[0,0,0]),this._up=A.vec3(t.up||[0,1,0]),this._normal=A.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=A.vec3(),this._rtcPos=A.vec3(),this._imageSize=A.vec2(),this._texture=new xn(this),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new it(this,{matrix:A.inverseMat4(A.lookAtMat4v(this._pos,A.subVec3(this._pos,this._normal,A.mat4()),this._up,A.mat4())),children:[this._bitmapMesh=new vn(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new Ne(this,Qe({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new bn(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}class $n extends B{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],this._origin=A.vec3(t.origin||[0,0,0]),t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=n.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new ge({type:"dir",dir:A.vec3([1,1,1]),color:A.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=A.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,n=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],i=[0,1,0];A.lookAtMat4v(n,s,i,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=A.identityMat4()),A.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new si(this.scene.canvas.canvas,this.scene.canvas.gl,{size:[1024,1024]})),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}class ii extends ei{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const s=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const n=this.scene.camera,i=this.scene.canvas;this._onCameraViewMatrix=n.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=n.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=i.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new ge({type:"point",pos:A.vec3([1,1,1]),color:A.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=A.identityMat4());const e=s._state.pos,t=n.look,i=n.up;A.lookAtMat4v(e,t,i,s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:()=>{if(s._shadowProjMatrixDirty){s._shadowProjMatrix||(s._shadowProjMatrix=A.identityMat4());const e=s.scene.canvas.canvas;A.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1}return s._shadowProjMatrix},getShadowRenderBuf:()=>(s._shadowRenderBuf||(s._shadowRenderBuf=new si(s.scene.canvas.canvas,s.scene.canvas.gl,{size:[1024,1024]})),s._shadowRenderBuf)}),this.pos=t.pos,this.color=t.color,this.intensity=t.intensity,this.constantAttenuation=t.constantAttenuation,this.linearAttenuation=t.linearAttenuation,this.quadraticAttenuation=t.quadraticAttenuation,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set pos(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get pos(){return this._state.pos}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set constantAttenuation(e){this._state.attenuation[0]=e||0,this.glRedraw()}get constantAttenuation(){return this._state.attenuation[0]}set linearAttenuation(e){this._state.attenuation[1]=e||0,this.glRedraw()}get linearAttenuation(){return this._state.attenuation[1]}set quadraticAttenuation(e){this._state.attenuation[2]=e||0,this.glRedraw()}get quadraticAttenuation(){return this._state.attenuation[2]}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function ai(e){if(!ri(e.width)||!ri(e.height)){const t=document.createElement("canvas");t.width=li(e.width),t.height=li(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function ri(e){return 0==(e&e-1)}function li(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class oi extends B{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new ge({texture:new Cn({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),f.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let a=0;a{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set collidable(e){this._mesh.collidable=!1!==e}get collidable(){return this._mesh.collidable}set clippable(e){this._mesh.clippable=!1!==e}get clippable(){return this._mesh.clippable}set pickable(e){this._mesh.pickable=!1!==e}get pickable(){return this._mesh.pickable}set opacity(e){this._mesh.opacity=e}get opacity(){return this._mesh.opacity}_updatePlaneSizeFromImage(){const e=.5*this._size,t=this._imageSize[0],s=this._imageSize[1],n=s/t;this._geometry.positions=t>s?[e,e*n,0,-e,e*n,0,-e,-e*n,0,e,-e*n,0]:[e/n,e,0,-e/n,e,0,-e/n,-e,0,e/n,-e,0]}}const pi=A.vec3(),Ai=A.vec3(),di=A.mat4();class fi{constructor(){this.normal=A.vec3(),this.offset=0,this.testVertex=A.vec3()}set(e,t,s,n){const i=1/Math.sqrt(e*e+t*t+s*s);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=s*i,this.offset=n*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class Ii{constructor(){this.planes=[new fi,new fi,new fi,new fi,new fi,new fi]}}function yi(e,t,s){const n=A.mulMat4(s,t,di),i=n[0],a=n[1],r=n[2],l=n[3],o=n[4],c=n[5],u=n[6],h=n[7],p=n[8],d=n[9],f=n[10],I=n[11],y=n[12],m=n[13],v=n[14],w=n[15];e.planes[0].set(l-i,h-o,I-p,w-y),e.planes[1].set(l+i,h+o,I+p,w+y),e.planes[2].set(l-a,h-c,I-d,w-m),e.planes[3].set(l+a,h+c,I+d,w+m),e.planes[4].set(l-r,h-u,I-f,w-v),e.planes[5].set(l+r,h+u,I+f,w+v)}function mi(e,t){let s=Ii.INSIDE;const n=pi,i=Ai;n[0]=t[0],n[1]=t[1],n[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];const a=[n,i];for(let t=0;t<6;++t){const n=e.planes[t];if(n.normal[0]*a[n.testVertex[0]][0]+n.normal[1]*a[n.testVertex[1]][1]+n.normal[2]*a[n.testVertex[2]][2]+n.offset<0)return Ii.OUTSIDE;n.normal[0]*a[1-n.testVertex[0]][0]+n.normal[1]*a[1-n.testVertex[1]][1]+n.normal[2]*a[1-n.testVertex[2]][2]+n.offset<0&&(s=Ii.INTERSECT)}return s}Ii.INSIDE=0,Ii.INTERSECT=1,Ii.OUTSIDE=2;class vi{constructor(e){this._eye=A.vec3(),this._look=A.vec3(),this._up=A.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,s=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,n=this._projection;function i(){switch(n.type){case"perspective":s.perspective.fov=n.fov,s.perspective.fovAxis=n.fovAxis,s.perspective.near=n.near,s.perspective.far=n.far;break;case"ortho":s.ortho.scale=n.scale,s.ortho.near=n.near,s.ortho.far=n.far;break;case"frustum":s.frustum.left=n.left,s.frustum.right=n.right,s.frustum.top=n.top,s.frustum.bottom=n.bottom,s.frustum.near=n.near,s.frustum.far=n.far;break;case"custom":s.customProjection.matrix=n.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:n.scale,projection:n.projection},(()=>{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const wi=A.vec3();class gi{constructor(e){if(this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,e){const t=e.metaScene.scene;this.saveObjects(t,e)}}saveObjects(e,t,s){this.numObjects=0,this._mask=s?v.apply(s,{}):null;const n=!s||s.visible,i=!s||s.edges,a=!s||s.xrayed,r=!s||s.highlighted,l=!s||s.selected,o=!s||s.clippable,c=!s||s.pickable,u=!s||s.colorize,h=!s||s.opacity,p=t.metaObjects,A=e.objects;for(let e=0,t=p.length;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=A.vec3();return t[0]=A.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=A.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=A.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}class Di extends oe{constructor(e,t={}){super(e,t),this._cachedLengths=[],this._dirty=!0,this._curves=[],this._t=0,this._dirtySubs=[],this._destroyedSubs=[],this.curves=t.curves||[],this.t=t.t}addCurve(e){this._curves.push(e),this._dirty=!0}set curves(e){var t,s,n;for(e=e||[],s=0,n=this._curves.length;s1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}get length(){var e=this._getCurveLengths();return e[e.length-1]}getPoint(e){for(var t,s=e*this.length,n=this._getCurveLengths(),i=0;i=s){var a=1-(n[i]-s)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],s=0,n=this._curves.length;for(e=0;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=A.vec3();return t[0]=A.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=A.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=A.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}class Ri{constructor(e,t,s,n,i=null,a=0){this.model=e,this.object=null,this.parent=null,this.id=t,this._aabb=null,this.layer=i,this.portionId=a,this._color=[s[0],s[1],s[2],n],this._colorize=[s[0],s[1],s[2],n],this._colorizing=!1,this._transparent=n<255,this.numTriangles=0,this.origin=null}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const s=e<255,n=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),n&&this.layer.setTransparent(this.portionId,t,s)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,s,n){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,s,n)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex(this.portionId,e)}set aabb(e){this._aabb=e}get aabb(){return this._aabb}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const Ci=new class{constructor(){this._uint8Arrays={},this._float32Arrays={}}_clear(){this._uint8Arrays={},this._float32Arrays={}}getUInt8Array(e){let t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}getFloat32Array(e){let t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}};let _i=0;const Bi={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},Oi=new Float32Array([1,1,1,1]),Si=new Float32Array([0,0,0,1]),Ni=A.vec4(),xi=A.vec3();A.vec3();const Li=A.vec3(),Mi=A.mat4();class Fi{constructor(e,t=!1,{instancing:s=!1,edges:n=!1}={}){this._scene=e,this._withSAO=t,this._instancing=s,this._edges=n,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}_getHash(){return this._scene._sectionPlanesState.getHash()}_buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}_buildVertexShader(){return[""]}_buildFragmentShader(){return[""]}_addMatricesUniformBlockLines(e,t=!1){return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}getValid(){return this._hash===this._getHash()}setSectionPlanesStateUniforms(e){const t=this._scene,{gl:s}=t.canvas,{model:n,layerIndex:i}=e,a=t._sectionPlanesState.sectionPlanes.length;if(a>0){const r=t._sectionPlanesState.sectionPlanes,l=i*a,o=n.renderFlags;for(let t=0;t0&&(this._uReflectionMap="reflectionMap"),s.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(let t=0,s=e._sectionPlanesState.sectionPlanes.length;t0&&d.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,d.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),d.lightMaps.length>0&&d.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,d.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),this._withSAO){const t=r.sao;if(t.possible){const s=l.drawingBufferWidth,n=l.drawingBufferHeight;Ni[0]=s,Ni[1]=n,Ni[2]=t.blendCutoff,Ni[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,Ni),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++}}if(n){const e=this._edges?"edgeColor":"fillColor",t=this._edges?"edgeAlpha":"fillAlpha";if(s===Bi[(this._edges?"EDGES":"SILHOUETTE")+"_XRAYED"]){const s=r.xrayMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===Bi[(this._edges?"EDGES":"SILHOUETTE")+"_HIGHLIGHTED"]){const s=r.highlightMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===Bi[(this._edges?"EDGES":"SILHOUETTE")+"_SELECTED"]){const s=r.selectedMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else l.uniform4fv(this._uColor,this._edges?Si:Oi)}this._draw({state:o,frameCtx:e,incrementDrawState:i}),l.bindVertexArray(null)}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null,f.memory.programs--}}class Hi extends Fi{constructor(e,t,{instancing:s=!1,edges:n=!1}={}){super(e,t,{instancing:s,edges:n})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;if(this._edges)t.drawElements(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0);else{const e=n.pickElementsCount||s.indicesBuf.numItems,a=n.pickElementsOffset?n.pickElementsOffset*s.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,e,s.indicesBuf.itemType,a),i&&n.drawElements++}}}class Ui extends Hi{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class Gi extends Fi{constructor(e,t,{edges:s=!1}={}){super(e,t,{instancing:!0,edges:s})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;this._edges?t.drawElementsInstanced(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances):(t.drawElementsInstanced(t.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++)}}class ji extends Gi{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class Vi extends Fi{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArrays(t.POINTS,0,s.positionsBuf.numItems),i&&n.drawArrays++}}class ki extends Fi{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArraysInstanced(t.POINTS,0,s.positionsBuf.numItems,s.numInstances),i&&n.drawArrays++}}class Qi extends Fi{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElements(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0),i&&n.drawElements++}}class Wi extends Fi{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElementsInstanced(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++}}class zi extends Hi{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i;const a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class Ki extends Hi{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching flat-shading draw vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._lightsState,s=e._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),n){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,s=t.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}class Xi extends Ui{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class qi extends Ui{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Ji extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class Zi extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class $i extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec3 worldNormal = octDecode(normal.xy); "),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}}class ea extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching occlusion fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}class ta extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching depth fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}class sa extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class na extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry shadow vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push(" int colorFlag = int(flags) & 0xF;"),s.push(" bool visible = (colorFlag > 0);"),s.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push(" if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry shadow fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = encodeFloat( gl_FragCoord.z); "),s.push("}"),s}}class ia extends Hi{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Triangles batching quality draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),r.push("uniform sampler2D uAOMap;"),r.push("in vec4 vViewPosition;"),r.push("in vec3 vViewNormal;"),r.push("in vec4 vColor;"),r.push("in vec2 vUV;"),r.push("in vec2 vMetallicRoughness;"),n.lightMaps.length>0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick flat normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out float vFlags;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags = flags;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick flat normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}}class ra extends Hi{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching color texture vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._lightsState,n=e._sectionPlanesState,i=n.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(let e=0,t=n.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(let e=0,t=n.sectionPlanes.length;e 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,t=s.lights.length;e5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]}}const ua=A.mat4(),ha=A.mat4();function pa(e,t,s){const n=e.length,i=new Uint16Array(n),a=t[0],r=t[1],l=t[2],o=t[3]-a,c=t[4]-r,u=t[5]-l,h=65525,p=h/o,d=h/c,f=h/u,I=e=>e>=0?e:0;for(let t=0;t=0?1:-1),t=(1-Math.abs(n))*(i>=0?1:-1),n=e,i=t}return new Int8Array([Math[t](127.5*n+(n<0?-1:0)),Math[s](127.5*i+(i<0?-1:0))])}function fa(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}const Ia=A.vec3(),ya=A.vec3(),ma=A.vec3(),va=A.vec3(),wa=A.mat4();class ga extends Fi{drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:h}=n,p=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Ia;let I,y;if(f[0]=A.safeInv(p[3]-p[0])*A.MAX_INT,f[1]=A.safeInv(p[4]-p[1])*A.MAX_INT,f[2]=A.safeInv(p[5]-p[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(f[0]),e.snapPickCoordinateScale[1]=A.safeInv(f[1]),e.snapPickCoordinateScale[2]=A.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=ya;if(o){const e=ma;A.transformPoint3(u,o,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=S(d,t,wa),y=va,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(h,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),l.indicesBuf.bind(),r.drawElements(r.TRIANGLES,l.indicesBuf.numItems,l.indicesBuf.itemType,0),l.indicesBuf.unbind()}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Ta=A.vec3(),Ea=A.vec3(),ba=A.vec3(),Da=A.vec3(),Pa=A.mat4();class Ra extends Fi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:h}=n,p=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Ta;let I,y;if(f[0]=A.safeInv(p[3]-p[0])*A.MAX_INT,f[1]=A.safeInv(p[4]-p[1])*A.MAX_INT,f[2]=A.safeInv(p[5]-p[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(f[0]),e.snapPickCoordinateScale[1]=A.safeInv(f[1]),e.snapPickCoordinateScale[2]=A.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=Ea;if(o){const e=ba;A.transformPoint3(u,o,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=S(d,t,Pa),y=Da,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(h,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(l.edgeIndicesBuf.bind(),r.drawElements(r.LINES,l.edgeIndicesBuf.numItems,l.edgeIndicesBuf.itemType,0),l.edgeIndicesBuf.unbind()):r.drawArrays(r.POINTS,0,l.positionsBuf.numItems)}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0;e.pointsMaterial._state;const s=[];return s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class Ca{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new ga(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Ra(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const _a={};const Ba=A.mat4(),Oa=A.mat4(),Sa=A.vec4([0,0,0,1]),Na=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]),A.OBB3();const xa=A.vec3(),La=A.vec3(),Ma=A.vec3(),Fa=A.vec3(),Ha=A.vec3(),Ua=A.vec3(),Ga=A.vec3();class ja{constructor(e){console.info("Creating TrianglesBatchingLayer"),this.model=e.model,this.sortId="TrianglesBatchingLayer"+(e.solid?"-solid":"-surface")+(e.autoNormals?"-autonormals":"-normals")+(e.textureSet&&e.textureSet.colorTexture?"-colorTexture":"")+(e.textureSet&&e.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=oa[t];return s||(s=new la(e),oa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete oa[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=_a[t];return s||(s=new Ca(e),_a[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete _a[t],s._destroy()}))),s}(e.model.scene),this._buffer=new ca(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ge({origin:A.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:e.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=A.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=A.mat4(e.positionsDecodeMatrix)),e.uvDecodeMatrix?(this._state.uvDecodeMatrix=A.mat3(e.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,e.origin&&this._state.origin.set(e.origin),this.aabb=A.collapseAABB3(),this.solid=!!e.solid}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(let e=0,t=i.length;e0){const e=Ba;I?A.inverseMat4(A.transposeMat4(I,Oa),e):A.identityMat4(e,e),function(e,t,s,n,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let r,l,o,c,u,h,p=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(h=0;hu&&(o=r,u=c),r=da(d,"floor","ceil"),l=fa(r),c=a(d,l),c>u&&(o=r,u=c),r=da(d,"ceil","ceil"),l=fa(r),c=a(d,l),c>u&&(o=r,u=c),n[i+h+0]=o[0],n[i+h+1]=o[1],n[i+h+2]=0}(e,n,n.length,w.normals,w.normals.length)}if(l)for(let e=0,t=l.length;e0)for(let e=0,t=a.length;e0)for(let e=0,t=r.length;e0){const n=this._state.positionsDecodeMatrix?new Uint16Array(s.positions):pa(s.positions,this._modelAABB,this._state.positionsDecodeMatrix=A.mat4());if(e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(let e=0,t=this._portions.length;e0){const n=new Int8Array(s.normals);let i=!0;e.normalsBuf=new Te(t,t.ARRAY_BUFFER,n,s.normals.length,3,t.STATIC_DRAW,i)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.uv.length>0)if(e.uvDecodeMatrix){let n=!1;e.uvBuf=new Te(t,t.ARRAY_BUFFER,s.uv,s.uv.length,2,t.STATIC_DRAW,n)}else{const n=Be.getUVBounds(s.uv),i=Be.compressUVs(s.uv,n.min,n.max),a=i.quantized;let r=!1;e.uvDecodeMatrix=A.mat3(i.decodeMatrix),e.uvBuf=new Te(t,t.ARRAY_BUFFER,a,a.length,2,t.STATIC_DRAW,r)}if(s.metallicRoughness.length>0){const n=new Uint8Array(s.metallicRoughness);let i=!1;e.metallicRoughnessBuf=new Te(t,t.ARRAY_BUFFER,n,s.metallicRoughness.length,2,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n),a=!1;e.flagsBuf=new Te(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new Te(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}if(s.edgeIndices.length>0){const n=new Uint32Array(s.edgeIndices);e.edgeIndicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,n,s.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}isEmpty(){return!this._state.indicesBuf}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=e,n=this._portions[s],i=4*n.vertsBaseIndex,a=4*n.numVerts,r=this._scratchMemory.getUInt8Array(a),l=t[0],o=t[1],c=t[2],u=t[3];for(let e=0;em)&&(m=e,n.set(v),i&&A.triangleNormal(d,f,I,i),y=!0)}}return y&&i&&(A.transformVec3(this.model.worldNormalMatrix,i,i),A.normalizeVec3(i)),y}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}class Va extends Gi{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i,a,r;const l=[];for(l.push("#version 300 es"),l.push("// Instancing geometry drawing vertex shader"),l.push("uniform int renderPass;"),l.push("in vec3 position;"),l.push("in vec2 normal;"),l.push("in vec4 color;"),l.push("in float flags;"),e.entityOffsetsEnabled&&l.push("in vec3 offset;"),l.push("in vec4 modelMatrixCol0;"),l.push("in vec4 modelMatrixCol1;"),l.push("in vec4 modelMatrixCol2;"),l.push("in vec4 modelNormalMatrixCol0;"),l.push("in vec4 modelNormalMatrixCol1;"),l.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(l,!0),e.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;")),l.push("uniform vec4 lightAmbient;"),i=0,a=s.lights.length;i= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"),n&&(l.push("out vec4 vWorldPosition;"),l.push("out float vFlags;")),l.push("out vec4 vColor;"),l.push("void main(void) {"),l.push("int colorFlag = int(flags) & 0xF;"),l.push("if (colorFlag != renderPass) {"),l.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),l.push("} else {"),l.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),l.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix * worldPosition; "),l.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),l.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),l.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),i=0,a=s.lights.length;i0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class ka extends Gi{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState;let n,i;const a=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry flat-shading drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),a){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}for(r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),n=0,i=s.lights.length;n0,s=[];return s.push("#version 300 es"),s.push("// Instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing fill fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Wa extends ji{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class za extends ji{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Ka extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class Ya extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Xa extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec2 normal;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("in vec4 modelNormalMatrixCol0;"),s.push("in vec4 modelNormalMatrixCol1;"),s.push("in vec4 modelNormalMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}}class qa extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// TrianglesInstancingOcclusionRenderer vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesInstancingOcclusionRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}class Ja extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}class Za extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class $a extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}const er={3e3:"linearToLinear",3001:"sRGBToLinear"};class tr extends Gi{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Instancing geometry quality drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),r.push("#define PI 3.14159265359"),r.push("#define RECIPROCAL_PI 0.31830988618"),r.push("#define RECIPROCAL_PI2 0.15915494"),r.push("#define EPSILON 1e-6"),r.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),r.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),r.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),r.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),r.push(" return normalize(surf_norm );"),r.push(" }"),r.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),r.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),r.push(" vec2 st0 = dFdx( uv.st );"),r.push(" vec2 st1 = dFdy( uv.st );"),r.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),r.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),r.push(" vec3 N = normalize( surf_norm );"),r.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),r.push(" mat3 tsn = mat3( S, T, N );"),r.push(" return normalize( tsn * mapN );"),r.push("}"),r.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),r.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),r.push("}"),r.push("struct IncidentLight {"),r.push(" vec3 color;"),r.push(" vec3 direction;"),r.push("};"),r.push("struct ReflectedLight {"),r.push(" vec3 diffuse;"),r.push(" vec3 specular;"),r.push("};"),r.push("struct Geometry {"),r.push(" vec3 position;"),r.push(" vec3 viewNormal;"),r.push(" vec3 worldNormal;"),r.push(" vec3 viewEyeDir;"),r.push("};"),r.push("struct Material {"),r.push(" vec3 diffuseColor;"),r.push(" float specularRoughness;"),r.push(" vec3 specularColor;"),r.push(" float shine;"),r.push("};"),r.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),r.push(" float r = ggxRoughness + 0.0001;"),r.push(" return (2.0 / (r * r) - 2.0);"),r.push("}"),r.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),r.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),r.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),r.push("}"),n.reflectionMaps.length>0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = "+er[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = "+er[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&s.push("out float vFlags;"),s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&s.push("vFlags = flags;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}}class nr extends Gi{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState;let i,a;const r=s.sectionPlanes.length>0,l=[];if(l.push("#version 300 es"),l.push("// Instancing geometry drawing fragment shader"),l.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),l.push("precision highp float;"),l.push("precision highp int;"),l.push("#else"),l.push("precision mediump float;"),l.push("precision mediump int;"),l.push("#endif"),e.logarithmicDepthBufferEnabled&&(l.push("in float isPerspective;"),l.push("uniform float logDepthBufFC;"),l.push("in float vFragDepth;")),l.push("uniform sampler2D uColorMap;"),this._withSAO&&(l.push("uniform sampler2D uOcclusionTexture;"),l.push("uniform vec4 uSAOParams;"),l.push("const float packUpscale = 256. / 255.;"),l.push("const float unpackDownScale = 255. / 256.;"),l.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),l.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),l.push("float unpackRGBToFloat( const in vec4 v ) {"),l.push(" return dot( v, unPackFactors );"),l.push("}")),l.push("uniform float gammaFactor;"),l.push("vec4 linearToLinear( in vec4 value ) {"),l.push(" return value;"),l.push("}"),l.push("vec4 sRGBToLinear( in vec4 value ) {"),l.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),l.push("}"),l.push("vec4 gammaToLinear( in vec4 value) {"),l.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),l.push("}"),t&&(l.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),l.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),l.push("}")),r){l.push("in vec4 vWorldPosition;"),l.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),l.push(" if (clippable) {"),l.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),l.push(" discard;"),l.push(" }"),l.push("}")}for(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),l.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),l.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),l.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),i=0,a=n.lights.length;i0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const pr=A.vec3(),Ar=A.vec3(),dr=A.vec3(),fr=A.vec3(),Ir=A.mat4();class yr extends Fi{constructor(e){super(e,!1,{instancing:!0})}drawLayer(e,t,s){if(!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:h}=n,p=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=pr;let I,y;if(f[0]=A.safeInv(p[3]-p[0])*A.MAX_INT,f[1]=A.safeInv(p[4]-p[1])*A.MAX_INT,f[2]=A.safeInv(p[5]-p[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(f[0]),e.snapPickCoordinateScale[1]=A.safeInv(f[1]),e.snapPickCoordinateScale[2]=A.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=Ar;if(o){const e=A.transformPoint3(u,o,dr);t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=S(d,t,Ir),y=fr,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(h,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(l.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(l.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(l.modelMatrixCol2Buf),r.vertexAttribDivisor(this._aModelMatrixCol0.location,1),r.vertexAttribDivisor(this._aModelMatrixCol1.location,1),r.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(l.flagsBuf),r.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(l.edgeIndicesBuf.bind(),r.drawElementsInstanced(r.LINES,l.edgeIndicesBuf.numItems,l.edgeIndicesBuf.itemType,0,l.numInstances),l.edgeIndicesBuf.unbind()):r.drawArraysInstanced(r.POINTS,0,l.positionsBuf.numItems,l.numInstances),r.vertexAttribDivisor(this._aModelMatrixCol0.location,0),r.vertexAttribDivisor(this._aModelMatrixCol1.location,0),r.vertexAttribDivisor(this._aModelMatrixCol2.location,0),r.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&r.vertexAttribDivisor(this._aOffset.location,0)}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class mr{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new hr(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new yr(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const vr={};const wr=new Uint8Array(4),gr=new Float32Array(1),Tr=A.vec4([0,0,0,1]),Er=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]);const br=new Float32Array(3),Dr=A.vec3(),Pr=A.vec3(),Rr=A.vec3(),Cr=A.vec3(),_r=A.vec3(),Br=A.vec3(),Or=A.vec3();class Sr{constructor(e){console.info("Creating TrianglesInstancingLayer"),this.model=e.model,this.sortId="TrianglesInstancingLayer"+(e.solid?"-solid":"-surface")+(e.normals?"-normals":"-autoNormals"),this.layerIndex=e.layerIndex,this._instancingRenderers=function(e){const t=e.id;let s=ar[t];return s||(s=new ir(e),ar[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete ar[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=vr[t];return s||(s=new mr(e),vr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete vr[t],s._destroy()}))),s}(e.model.scene),this._aabb=A.collapseAABB3(),this._state=new ge({numInstances:0,obb:A.OBB3(),origin:A.vec3(),geometry:e.geometry,textureSet:e.textureSet,pbrSupported:!1,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],e.origin&&this._state.origin.set(e.origin),this._finalized=!1,this.aabb=A.collapseAABB3(),this.solid=!!e.solid,this.numIndices=e.geometry.numIndices}createPortion(e){const t=e.color,s=e.metallic,n=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,r=e.aabb,l=e.pickColor;if(this._finalized)throw"Already finalized";const o=t[0],c=t[1],u=t[2];if(this._colors.push(o),this._colors.push(c),this._colors.push(u),this._colors.push(i),this._metallicRoughness.push(null!=s?s:0),this._metallicRoughness.push(null!=n?n:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){let e=A.transposeMat4(a,A.mat4()),t=A.inverseMat4(e);this._modelNormalMatrixCol0.push(t[0]),this._modelNormalMatrixCol0.push(t[4]),this._modelNormalMatrixCol0.push(t[8]),this._modelNormalMatrixCol0.push(t[12]),this._modelNormalMatrixCol1.push(t[1]),this._modelNormalMatrixCol1.push(t[5]),this._modelNormalMatrixCol1.push(t[9]),this._modelNormalMatrixCol1.push(t[13]),this._modelNormalMatrixCol2.push(t[2]),this._modelNormalMatrixCol2.push(t[6]),this._modelNormalMatrixCol2.push(t[10]),this._modelNormalMatrixCol2.push(t[14])}this._pickColors.push(l[0]),this._pickColors.push(l[1]),this._pickColors.push(l[2]),this._pickColors.push(l[3]);const h=this._state.geometry.positionsCompressed.length,p=this._state.geometry.positionsCompressed,d=this._state.geometry.positionsDecodeMatrix;for(let e=0;e0){let t=!1;e.colorsBuf=new Te(n,n.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,n.DYNAMIC_DRAW,t),this._colors=[]}if(this._metallicRoughness.length>0){const t=new Uint8Array(this._metallicRoughness);let s=!1;e.metallicRoughnessBuf=new Te(n,n.ARRAY_BUFFER,t,this._metallicRoughness.length,2,n.STATIC_DRAW,s)}if(a>0){let t=!1;e.flagsBuf=new Te(n,n.ARRAY_BUFFER,new Float32Array(a),a,1,n.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;e.offsetsBuf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,n.DYNAMIC_DRAW,t),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){const s=!1;e.positionsBuf=new Te(n,n.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,n.STATIC_DRAW,s),e.positionsDecodeMatrix=A.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){const s=new Uint8Array(t.colorsCompressed),i=!1;e.colorsBuf=new Te(n,n.ARRAY_BUFFER,s,s.length,4,n.STATIC_DRAW,i)}if(t.uvCompressed&&t.uvCompressed.length>0){const s=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new Te(n,n.ARRAY_BUFFER,s,s.length,2,n.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new Te(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,n.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new Te(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,n.STATIC_DRAW)),this._modelMatrixCol0.length>0){const t=!1;e.modelMatrixCol0Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelMatrixCol1Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelMatrixCol2Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol1Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol2Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){const t=!1;e.pickColorsBuf=new Te(n,n.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,n.STATIC_DRAW,t),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&s&&s.colorTexture&&s.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!s&&!!s.colorTexture,this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";wr[0]=t[0],wr[1]=t[1],wr[2]=t[2],wr[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(wr,4*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&F),i=!!(t&V),a=!!(t&k),r=!!(t&Q),l=!!(t&W),o=!!(t&U),c=!!(t&H);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Bi.NOT_RENDERED:s?Bi.COLOR_TRANSPARENT:Bi.COLOR_OPAQUE,h=!n||c?Bi.NOT_RENDERED:r?Bi.SILHOUETTE_SELECTED:a?Bi.SILHOUETTE_HIGHLIGHTED:i?Bi.SILHOUETTE_XRAYED:Bi.NOT_RENDERED;let p=0;p=!n||c?Bi.NOT_RENDERED:r?Bi.EDGES_SELECTED:a?Bi.EDGES_HIGHLIGHTED:i?Bi.EDGES_XRAYED:l?s?Bi.EDGES_COLOR_TRANSPARENT:Bi.EDGES_COLOR_OPAQUE:Bi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Bi.PICK:Bi.NOT_RENDERED)<<12,A|=(t&G?1:0)<<16,gr[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(gr,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(br[0]=t[0],br[1]=t[1],br[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(br,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}getEachVertex(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;const s=this._state,n=s.geometry,i=this._portions[e];if(!i)return void this.model.error("portion not found: "+e);const a=n.quantizedPositions,r=s.origin,l=i.offset,o=r[0]+l[0],c=r[1]+l[1],u=r[2]+l[2],h=Tr,p=i.matrix,d=this.model.sceneModelMatrix,f=s.positionsDecodeMatrix;for(let e=0,s=a.length;ev)&&(v=e,n.set(w),i&&A.triangleNormal(f,I,y,i),m=!0)}}return m&&i&&(A.transformVec3(l.normalMatrix,i,i),A.transformVec3(this.model.worldNormalMatrix,i,i),A.normalizeVec3(i)),m}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}class Nr extends Qi{drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class xr extends Qi{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class Lr{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Nr(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new xr(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Mr={};class Fr{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const Hr=A.vec4([0,0,0,1]),Ur=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]),A.OBB3();class Gr{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=Mr[t];return s||(s=new Lr(e),Mr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Mr[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new Fr(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ge({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:A.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=A.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=A.vec3(e.origin)),this.aabb=A.collapseAABB3()}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=pa(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.colors.length>0){const n=s.colors.length/4,i=new Float32Array(n);let a=!1;e.flagsBuf=new Te(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new Te(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2],c=t[3];for(let e=0;e0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 lightAmbient;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class Vr extends Wi{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 color;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class kr{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new jr(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Vr(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Qr={};const Wr=new Uint8Array(4),zr=new Float32Array(1),Kr=A.vec4([0,0,0,1]),Yr=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]);const Xr=new Float32Array(3);class qr{constructor(e){this.model=e.model,this.material=e.material,this.sortId="LinesInstancingLayer",this.layerIndex=e.layerIndex,this._linesInstancingRenderers=function(e){const t=e.id;let s=Qr[t];return s||(s=new kr(e),Qr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Qr[t],s._destroy()}))),s}(e.model.scene),this._aabb=A.collapseAABB3(),this._state=new ge({obb:A.OBB3(),numInstances:0,origin:null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],e.origin&&(this._state.origin=A.vec3(e.origin)),this._finalized=!1,this.aabb=A.collapseAABB3()}createPortion(e){const t=e.color,s=e.opacity,n=e.meshMatrix,i=e.aabb;if(this._finalized)throw"Already finalized";const a=t[0],r=t[1],l=t[2];t[3],this._colors.push(a),this._colors.push(r),this._colors.push(l),this._colors.push(s),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(n[0]),this._modelMatrixCol0.push(n[4]),this._modelMatrixCol0.push(n[8]),this._modelMatrixCol0.push(n[12]),this._modelMatrixCol1.push(n[1]),this._modelMatrixCol1.push(n[5]),this._modelMatrixCol1.push(n[9]),this._modelMatrixCol1.push(n[13]),this._modelMatrixCol2.push(n[2]),this._modelMatrixCol2.push(n[6]),this._modelMatrixCol2.push(n[10]),this._modelMatrixCol2.push(n[14]),A.collapseAABB3(i);const o=this._state.obb,c=o.length;for(let e=0;e0){let t=!1;this._state.colorsBuf=new Te(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,t),this._colors=[]}if(s>0){let t=!1;this._state.flagsBuf=new Te(e,e.ARRAY_BUFFER,new Float32Array(s),s,1,e.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Wr[0]=t[0],Wr[1]=t[1],Wr[2]=t[2],Wr[3]=t[3],this._state.colorsBuf.setData(Wr,4*e,4)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&F),i=!!(t&V),a=!!(t&k),r=!!(t&Q),l=!!(t&W),o=!!(t&U),c=!!(t&H);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Bi.NOT_RENDERED:s?Bi.COLOR_TRANSPARENT:Bi.COLOR_OPAQUE,h=!n||c?Bi.NOT_RENDERED:r?Bi.SILHOUETTE_SELECTED:a?Bi.SILHOUETTE_HIGHLIGHTED:i?Bi.SILHOUETTE_XRAYED:Bi.NOT_RENDERED;let p=0;p=!n||c?Bi.NOT_RENDERED:r?Bi.EDGES_SELECTED:a?Bi.EDGES_HIGHLIGHTED:i?Bi.EDGES_XRAYED:l?s?Bi.EDGES_COLOR_TRANSPARENT:Bi.EDGES_COLOR_OPAQUE:Bi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Bi.PICK:Bi.NOT_RENDERED)<<12,A|=(t&G?255:0)<<16,zr[0]=A,this._state.flagsBuf.setData(zr,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Xr[0]=t[0],Xr[1]=t[1],Xr[2]=t[2],this._state.offsetsBuf.setData(Xr,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesXRayed(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawOcclusion(e,t){}drawShadow(e,t){}drawPickMesh(e,t){}drawPickDepths(e,t){}drawPickNormals(e,t){}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}class Jr extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial,n=[];return n.push("#version 300 es"),n.push("// Points batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Zr extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}class $r extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class el extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batched pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batched pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class tl extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push(" gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class sl{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Jr(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Zr(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new $r(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new el(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new tl(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const nl={};class il{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]}}const al=A.vec4(),rl=A.vec4(),ll=A.vec4([0,0,0,1]),ol=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]),A.OBB3();class cl{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=nl[t];return s||(s=new sl(e),nl[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete nl[t],s._destroy()}))),s}(e.model.scene),this._buffer=new il(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ge({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:A.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=A.collapseAABB3(),this._portions=[],this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=A.vec3(e.origin)),this.aabb=A.collapseAABB3()}canCreatePortion(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}createPortion(e){if(this._finalized)throw"Already finalized";const t=e.positions,s=e.positionsCompressed,n=e.color,i=e.colorsCompressed,a=e.colors,r=e.meshMatrix,l=e.worldAABB,o=e.pickColor,c=this._buffer,u=c.positions.length/3;let h;if(this._preCompressedPositionsExpected){if(!s)throw"positionsCompressed expected";for(let e=0,t=s.length;e0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=pa(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n);let a=!1;e.flagsBuf=new Te(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new Te(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized"}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2];for(let e=0;e0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class hl extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 silhouetteColor;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class pl extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick mesh fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class Al extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class dl extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class fl extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class Il extends ki{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("gl_PointSize = pointSize;"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }"),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class yl{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new ul(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new hl(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new fl(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new pl(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Al(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new dl(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new Il(this._scene)),this._shadowRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}const ml={};const vl=new Uint8Array(4),wl=new Float32Array(1),gl=A.vec4([0,0,0,1]),Tl=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]);const El=new Float32Array(3);class bl{constructor(e){this.model=e.model,this.material=e.material,this.sortId="PointsInstancingLayer",this.layerIndex=e.layerIndex,this._pointsInstancingRenderers=function(e){const t=e.id;let s=ml[t];return s||(s=new yl(e),ml[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete ml[t],s._destroy()}))),s}(e.model.scene),this._aabb=A.collapseAABB3(),this._state=new ge({obb:A.OBB3(),numInstances:0,origin:e.origin?A.vec3(e.origin):null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=A.collapseAABB3()}createPortion(e){const t=e.meshMatrix,s=e.aabb,n=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(n[0]),this._pickColors.push(n[1]),this._pickColors.push(n[2]),this._pickColors.push(n[3]),A.collapseAABB3(s);const i=this._state.obb,a=i.length;for(let e=0;e0){let n=!1;s.flagsBuf=new Te(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,n)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;s.offsetsBuf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(n.positionsCompressed&&n.positionsCompressed.length>0){const t=!1;s.positionsBuf=new Te(e,e.ARRAY_BUFFER,n.positionsCompressed,n.positionsCompressed.length,3,e.STATIC_DRAW,t),s.positionsDecodeMatrix=A.mat4(n.positionsDecodeMatrix)}if(n.colorsCompressed&&n.colorsCompressed.length>0){const t=new Uint8Array(n.colorsCompressed),i=!1;s.colorsBuf=new Te(e,e.ARRAY_BUFFER,t,t.length,4,e.STATIC_DRAW,i)}if(this._modelMatrixCol0.length>0){const t=!1;s.modelMatrixCol0Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),s.modelMatrixCol1Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),s.modelMatrixCol2Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){const t=!1;s.pickColorsBuf=new Te(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,t),this._pickColors=[]}s.geometry=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";vl[0]=t[0],vl[1]=t[1],vl[2]=t[2],this._state.colorsBuf.setData(vl,3*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&F),i=!!(t&V),a=!!(t&k),r=!!(t&Q),l=!!(t&W),o=!!(t&U),c=!!(t&H);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Bi.NOT_RENDERED:s?Bi.COLOR_TRANSPARENT:Bi.COLOR_OPAQUE,h=!n||c?Bi.NOT_RENDERED:r?Bi.SILHOUETTE_SELECTED:a?Bi.SILHOUETTE_HIGHLIGHTED:i?Bi.SILHOUETTE_XRAYED:Bi.NOT_RENDERED;let p=0;p=!n||c?Bi.NOT_RENDERED:r?Bi.EDGES_SELECTED:a?Bi.EDGES_HIGHLIGHTED:i?Bi.EDGES_XRAYED:l?s?Bi.EDGES_COLOR_TRANSPARENT:Bi.EDGES_COLOR_OPAQUE:Bi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Bi.PICK:Bi.NOT_RENDERED)<<12,A|=(t&G?255:0)<<16,wl[0]=A,this._state.flagsBuf.setData(wl,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(El[0]=t[0],El[1]=t[1],El[2]=t[2],this._state.offsetsBuf.setData(El,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawEdgesXRayed(e,t){}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Bi.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Bi.PICK)}drawPickNormals(e,t){}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}class Dl{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class Pl{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const Rl={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class Cl{constructor(e,t,s){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,s=this.handlers.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==Ol[e])return void Ol[e].push({onLoad:t,onProgress:s,onError:n});Ol[e]=[],Ol[e].push({onLoad:t,onProgress:s,onError:n});const a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),r=this.mimeType,l=this.responseType;fetch(a).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const s=Ol[e],n=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,r=0!==a;let l=0;const o=new ReadableStream({start(e){!function t(){n.read().then((({done:n,value:i})=>{if(n)e.close();else{l+=i.byteLength;const n=new ProgressEvent("progress",{lengthComputable:r,loaded:l,total:a});for(let e=0,t=s.length;e{switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,r)));case"json":return e.json();default:if(void 0===r)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(r),s=t&&t[1]?t[1].toLowerCase():void 0,n=new TextDecoder(s);return e.arrayBuffer().then((e=>n.decode(e)))}}})).then((t=>{Rl.add(e,t);const s=Ol[e];delete Ol[e];for(let e=0,n=s.length;e{const s=Ol[e];if(void 0===s)throw this.manager.itemError(e),t;delete Ol[e];for(let e=0,n=s.length;e{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class Nl{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e{const n=this._getIdleWorker();-1!==n?(this._initWorker(n),this.workerStatus|=1<e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let xl=0;class Ll{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new Nl,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const n=e.capabilities;this._workerConfig={astcSupported:n.astcSupported,etc1Supported:n.etc1Supported,etc2Supported:n.etc2Supported,dxtSupported:n.dxtSupported,bptcSupported:n.bptcSupported,pvrtcSupported:n.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new Sl;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new Sl;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const n=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,n]).then((([e,t])=>{const s=Ll.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(Ll.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(Ll.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(Ll.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([n])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),xl>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),xl++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((n,i)=>{const a=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e))).then((e=>{const s=e.data,{mipmaps:a,width:r,height:l,format:o,type:c,error:u,dfdTransferFn:h,dfdFlags:p}=s;if("error"===c)return i(u);t.setCompressedData({mipmaps:a,props:{format:o,minFilter:1===a.length?1006:1008,magFilter:1===a.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&p)}}),n()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),xl--}}Ll.BasisFormat={ETC1S:0,UASTC_4x4:1},Ll.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},Ll.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},Ll.BasisWorker=function(){let e,t,s;const n=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(r){const u=r.data;switch(u.type){case"init":e=u.config,h=u.transcoderBinary,t=new Promise((e=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:r,hasAlpha:h,mipmaps:p,format:A,dfdTransferFn:d,dfdFlags:f}=function(t){const r=new s.KTX2File(new Uint8Array(t));function u(){r.close(),r.delete()}if(!r.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=r.isUASTC()?a.UASTC_4x4:a.ETC1S,p=r.getWidth(),A=r.getHeight(),d=r.getLevels(),f=r.getHasAlpha(),I=r.getDFDTransferFunc(),y=r.getDFDFlags(),{transcoderFormat:m,engineFormat:v}=function(t,s,r,u){let h,p;const A=t===a.ETC1S?l:o;for(let n=0;n{delete Ml[t],s.destroy()}))),s} +class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e={}){this._id=t.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==e.hideOnMouseDown&&(document.addEventListener("mousedown",(e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),e.items&&(this.items=e.items),this._hideOnAction=!1!==e.hideOnAction,this.context=e.context,this.enabled=!1!==e.enabled,this.hide()}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,n=s.length;e{const a=this._getNextId(),r=new s(a);for(let s=0,a=e.length;s0,c=this._getNextId(),u=s.getTitle||(()=>s.title||""),h=s.doAction||s.callback||(()=>{}),p=s.getEnabled||(()=>!0),A=s.getShown||(()=>!0),d=new i(c,u,h,p,A);if(d.parentMenu=r,l.items.push(d),o){const e=t(n);d.subMenu=e,e.parentItem=d}this._itemList.push(d),this._itemMap[d.id]=d}}return this._menuList.push(r),this._menuMap[r.id]=r,r};this._rootMenu=t(e)}_getNextId(){return"ContextMenu_"+this._id+"_"+this._nextId++}_createUI(){const e=t=>{this._createMenuUI(t);const s=t.groups;for(let t=0,n=s.length;t'),s.push("
    "),t)for(let e=0,n=t.length;e'+o+" [MORE]"):s.push('
  • '+o+"
  • ")}}s.push("
"),s.push("");const n=s.join("");document.body.insertAdjacentHTML("beforeend",n);const i=document.querySelector("."+e.id);e.menuElement=i,i.style["border-radius"]="4px",i.style.display="none",i.style["z-index"]=3e5,i.style.background="white",i.style.border="1px solid black",i.style["box-shadow"]="0 4px 5px 0 gray",i.oncontextmenu=e=>{e.preventDefault()};const a=this;let r=null;if(t)for(let e=0,s=t.length;e{e.preventDefault();const s=t.subMenu;if(!s)return void(r&&(a._hideMenu(r.id),r=null));if(r&&r.id!==s.id&&(a._hideMenu(r.id),r=null),!1===t.enabled)return;const n=t.itemElement,i=s.menuElement,l=n.getBoundingClientRect();i.getBoundingClientRect();l.right+200>window.innerWidth?a._showMenu(s.id,l.left-200,l.top-1):a._showMenu(s.id,l.right-5,l.top-1),r=s})),n||(t.itemElement.addEventListener("click",(e=>{e.preventDefault(),a._context&&!1!==t.enabled&&(t.doAction&&t.doAction(a._context),this._hideOnAction?a.hide():(a._updateItemsTitles(),a._updateItemsEnabledStatus()))})),t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault(),!1!==t.enabled&&t.doHover&&t.doHover(a._context)})))):console.error("ContextMenu item element not found: "+t.id)}}}_updateItemsTitles(){if(this._context)for(let e=0,t=this._itemList.length;ewindow.innerHeight&&(s=window.innerHeight-n),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=s+"px"}_hideMenuElement(e){e.style.display="none"}}class r{constructor(e,t={}){this.viewer=e,this.scene=this.viewer.scene,this._lensCursorDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._lensCursorDiv,this.viewer.scene.canvas.canvas),this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red",this._lensCursorDiv.style.borderRadius="20px",this._lensCursorDiv.style.width="10px",this._lensCursorDiv.style.height="10px",this._lensCursorDiv.style.margin="-200px -200px",this._lensCursorDiv.style.zIndex="100000",this._lensCursorDiv.style.position="absolute",this._lensCursorDiv.style.pointerEvents="none",this._lensContainer=document.createElement("div"),this._lensContainer.style.border="1px solid black",this._lensContainer.style.background="white",this._lensContainer.style.borderRadius="50%",this._lensContainer.style.width="300px",this._lensContainer.style.height="300px",this._lensContainer.style.marginTop="85px",this._lensContainer.style.marginLeft="25px",this._lensContainer.style.zIndex="15000",this._lensContainer.style.position="absolute",this._lensContainer.style.pointerEvents="none",this._lensContainer.style.visibility="hidden",this._lensCanvas=document.createElement("canvas"),this._lensCanvas.style.borderRadius="50%",this._lensCanvas.style.width="300px",this._lensCanvas.style.height="300px",this._lensCanvas.style.zIndex="15000",this._lensCanvas.style.pointerEvents="none",document.body.appendChild(this._lensContainer),this._lensContainer.appendChild(this._lensCanvas),this._lensCanvasContext=this._lensCanvas.getContext("2d"),this._canvasElement=this.viewer.scene.canvas.canvas,this._centerPos=null,this._cursorPos=null,this._lensPosToggle=!0,this._zoomLevel=t.zoomLevel||2,this._active=!1!==t.active,this._visible=!1,this._snapped=!1,this._onViewerRendering=this.viewer.scene.on("rendering",(()=>{this._active&&this._visible&&this.update()}))}update(){if(!this._active||!this._visible)return;if(!this._centerPos)return;const e=this._lensContainer.getBoundingClientRect(),t=this._canvasElement.getBoundingClientRect(),s=this._centerPos[0]e.left&&this._centerPos[1]e.top;this._lensContainer.style.marginLeft="25px",s&&(this._lensPosToggle?this._lensContainer.style.marginTop=t.bottom-t.top-this._lensCanvas.height-85+"px":this._lensContainer.style.marginTop="85px",this._lensPosToggle=!this._lensPosToggle),this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);const n=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,this._centerPos[0]-n/2,this._centerPos[1]-n/2,n,n,0,0,this._lensCanvas.width,this._lensCanvas.height);const i=[(e.left+e.right)/2,(e.top+e.bottom)/2];if(this._cursorPos){const e=this._cursorPos[0]-this._centerPos[0],t=this._cursorPos[1]-this._centerPos[1];this._lensCursorDiv.style.marginLeft=i[0]+e*this._zoomLevel-10+"px",this._lensCursorDiv.style.marginTop=i[1]+t*this._zoomLevel-10+"px"}else this._lensCursorDiv.style.marginLeft=i[0]-10+"px",this._lensCursorDiv.style.marginTop=i[1]-10+"px"}set zoomFactor(e){this._zoomFactor=e,this.update()}get zoomFactor(){return this._zoomFactor}set centerPos(e){this._centerPos=e,this.update()}get centerPos(){return this._centerPos}set cursorPos(e){this._cursorPos=e,this.update()}get cursorPos(){return this._cursorPos}set snapped(e){this._snapped=e,e?(this._lensCursorDiv.style.background="greenyellow",this._lensCursorDiv.style.border="2px solid green"):(this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red")}get snapped(){return this._snapped}set active(e){this._active=e,this._lensContainer.style.visibility=e&&this._visible?"visible":"hidden",e&&this._visible||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}get active(){return this._active}set visible(e){this._visible=e,this._lensContainer.style.visibility=e&&this._active?"visible":"hidden",e&&this._active||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}get visible(){return this._visible}destroy(){this._destroyed||(this.viewer.scene.off(this._onViewerRendering),this._lensContainer.removeChild(this._lensCanvas),document.body.removeChild(this._lensContainer),this._destroyed=!0)}}class l{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let o=!0,c=o?Float64Array:Float32Array;const u=new c(16),h=new c(16),p=new c(4),A={setDoublePrecisionEnabled(e){o=e,c=o?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>o,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new c(e||2),vec3:e=>new c(e||3),vec4:e=>new c(e||4),mat3:e=>new c(e||9),mat3ToMat4:(e,t=new c(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new c(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new c(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new c(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>A.dotVec4(e,e),lenVec4:e=>Math.sqrt(A.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>A.dotVec3(e,e),sqLenVec2:e=>A.dotVec2(e,e),lenVec3:e=>Math.sqrt(A.sqLenVec3(e)),distVec3:(()=>{const e=new c(3);return(t,s)=>A.lenVec3(A.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(A.sqLenVec2(e)),distVec2:(()=>{const e=new c(2);return(t,s)=>A.lenVec2(A.subVec2(t,s,e))})(),rcpVec3:(e,t)=>A.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/A.lenVec4(e);return A.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/A.lenVec3(e);return A.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/A.lenVec2(e);return A.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=A.dotVec3(e,t)/Math.sqrt(A.sqLenVec3(e)*A.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new c(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=A.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=A.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=A.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||A.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>A.m4s(0),setMat4ToOnes:()=>A.m4s(1),diagonalMat4v:e=>new c([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>A.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>A.diagonalMat4c(e,e,e,e),identityMat4:(e=new c(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new c(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>A.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new c(9));const n=e[0],i=e[3],a=e[6],r=e[1],l=e[4],o=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+l*I+o*v,s[4]=r*d+l*y+o*w,s[7]=r*f+l*m+o*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=A.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||A.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||A.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new c(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,A.translationMat4v(e,i))})(),translationMat4s:(e,t)=>A.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>A.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=A.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,h,p,d,f,I;return u=l*o,h=o*c,p=c*l,d=l*i,f=o*i,I=c*i,(s=s||A.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*p-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*h+d,s[7]=0,s[8]=r*p+f,s[9]=r*h-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>A.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=A.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=A.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new c(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,A.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>A.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=A.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,h=n*o,p=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=h+v,s[2]=p-m,s[3]=0,s[4]=h-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=p+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=A.vec4()){const n=A.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],h=e[6],p=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,p),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(h,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,p),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(h,-1,1)),Math.abs(h)<.99999?(s[1]=Math.atan2(-u,p),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(h,p),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,p))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(h,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,p),s[1]=0)),s},composeMat4:(e,t,s,n=A.mat4())=>(A.quaternionToRotationMat4(t,n),A.scaleMat4v(s,n),A.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new c(3),t=new c(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=A.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=A.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=A.lenVec3(e);A.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,h=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=h,t[9]*=h,t[10]*=h,A.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=A.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],h=t[1],p=t[2];if(i===u&&a===h&&r===p)return A.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-h,I=r-p,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>A.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=A.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=A.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];A.addVec4(i,n,u),A.subVec4(i,n,h);const a=2*n[2],r=h[0],l=h[1],o=h[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=u[0]/r,s[9]=u[1]/l,s[10]=-u[2]/o,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/o,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=A.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],A.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=A.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=A.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new c(16),t=new c(16),s=new c(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||A.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||A.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=A.vec4()){const n=e[0]*A.DEGTORAD/2,i=e[1]*A.DEGTORAD/2,a=e[2]*A.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),h=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"YXZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"ZXY"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"ZYX"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"YZX"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o-c*u*h):"XZY"===t&&(s[0]=c*l*o-r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o+c*u*h),s},mat4ToQuaternion(e,t=A.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let h;const p=s+r+u;return p>0?(h=.5/Math.sqrt(p+1),t[3]=.25/h,t[0]=(c-l)*h,t[1]=(i-o)*h,t[2]=(a-n)*h):s>r&&s>u?(h=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/h,t[0]=.25*h,t[1]=(n+a)/h,t[2]=(i+o)/h):r>u?(h=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/h,t[0]=(n+a)/h,t[1]=.25*h,t[2]=(l+c)/h):(h=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/h,t[0]=(i+o)/h,t[1]=(l+c)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,s=A.vec4()){const n=Math.sqrt(A.dotVec3(e,e)*A.dotVec3(t,t));let i=n+A.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):A.cross3Vec3(e,t,s),s[3]=i,A.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=A.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new c(16);return(t,s,n)=>(n=n||A.vec3(),A.quaternionToRotationMat4(t,e),A.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=A.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=A.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,h=c*i+o*n-r*a,p=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+h*-o-p*-l,s[1]=h*c+d*-l+p*-r-u*-o,s[2]=p*c+d*-o+u*-l-h*-r,s},quaternionToMat4(e,t){t=A.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,h=o*a,p=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+h,t[2]=f-u,t[4]=d-h,t[5]=1-(p+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(p+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=A.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>A.normalizeQuaternion(A.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=A.vec4()){const s=(e=A.normalizeQuaternion(e,p))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new c(e||6),AABB2:e=>new c(e||4),OBB3:e=>new c(e||32),OBB2:e=>new c(e||16),Sphere3:(e,t,s,n)=>new c([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new c(3),t=new c(3),s=new c(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],A.subVec3(t,e,s),Math.abs(A.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new c(3),t=new c(3),s=new c(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=A.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],h=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>h?u:h,Math.abs(A.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||A.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||A.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=A.AABB3())=>(e[0]=A.MAX_DOUBLE,e[1]=A.MAX_DOUBLE,e[2]=A.MAX_DOUBLE,e[3]=A.MIN_DOUBLE,e[4]=A.MIN_DOUBLE,e[5]=A.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=A.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new c(3);return(t,s,n)=>{s=s||A.AABB3();let i,a,r,l=A.MAX_DOUBLE,o=A.MAX_DOUBLE,c=A.MAX_DOUBLE,u=A.MIN_DOUBLE,h=A.MIN_DOUBLE,p=A.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>h&&(h=a),r>p&&(p=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=h,s[5]=p,s}})(),OBB3ToAABB3(e,t=A.AABB3()){let s,n,i,a=A.MAX_DOUBLE,r=A.MAX_DOUBLE,l=A.MAX_DOUBLE,o=A.MIN_DOUBLE,c=A.MIN_DOUBLE,u=A.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=A.AABB3()){let s,n,i,a=A.MAX_DOUBLE,r=A.MAX_DOUBLE,l=A.MAX_DOUBLE,o=A.MIN_DOUBLE,c=A.MIN_DOUBLE,u=A.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new c(3);return(t,s)=>{s=s||A.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new c(3),t=new c(3);return(s,n)=>{n=n||A.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=h);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new c(3),t=new c(3);return(s,n)=>{n=n||A.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ih&&(h=u);return n[3]=h,n}})(),getSphere3Center:(e,t=A.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=A.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=A.MAX_DOUBLE,e[1]=A.MAX_DOUBLE,e[2]=A.MIN_DOUBLE,e[3]=A.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=A.AABB2()){let s,n,i,a,r=A.MAX_DOUBLE,l=A.MAX_DOUBLE,o=A.MIN_DOUBLE,c=A.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=A.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,h=r*l-i*c,p=i*o-a*l,d=Math.sqrt(u*u+h*h+p*p);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=h/d,n[2]=p/d),n},rayTriangleIntersect:(()=>{const e=new c(3),t=new c(3),s=new c(3),n=new c(3),i=new c(3);return(a,r,l,o,c,u)=>{u=u||A.vec3();const h=A.subVec3(o,l,e),p=A.subVec3(c,l,t),d=A.cross3Vec3(r,p,s),f=A.dotVec3(h,d);if(f<1e-6)return null;const I=A.subVec3(a,l,n),y=A.dotVec3(I,d);if(y<0||y>f)return null;const m=A.cross3Vec3(I,h,i),v=A.dotVec3(r,m);if(v<0||y+v>f)return null;const w=A.dotVec3(p,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new c(3),t=new c(3),s=new c(3),n=new c(3);return(i,a,r,l,o,c)=>{c=c||A.vec3(),a=A.normalizeVec3(a,e);const u=A.subVec3(l,r,t),h=A.subVec3(o,r,s),p=A.cross3Vec3(u,h,n);A.normalizeVec3(p,p);const d=-A.dotVec3(r,p),f=-(A.dotVec3(i,p)+d)/A.dotVec3(a,p);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new c(3),t=new c(3),s=new c(3);return(n,i,a,r,l)=>{const o=A.subVec3(r,i,e),c=A.subVec3(a,i,t),u=A.subVec3(n,i,s),h=A.dotVec3(o,o),p=A.dotVec3(o,c),d=A.dotVec3(o,u),f=A.dotVec3(c,c),I=A.dotVec3(c,u),y=h*f-p*p;if(0===y)return null;const m=1/y,v=(f*d-p*I)*m,w=(h*I-p*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=A.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new c(3),t=new c(3),s=new c(3),n=new c(3),i=new c(3),a=new c(3);return(r,l,o)=>{let c,u;const h=new Array(r.length/3);let p,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new c(3),t=new c(3),s=new c(3),n=new c(3),i=new c(3),a=new c(3),r=new c(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let h=0;h>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,h;const p=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new c(4),t=new c(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,A.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],A.transformVec3(s,e,t),A.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new c(16),t=new c(16),s=new c(4),n=new c(4),i=new c(4),a=new c(4);return(r,l,o,c,u,h)=>{const p=A.mulMat4(o,l,e),d=A.inverseMat4(p,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,A.transformVec4(d,s,n),A.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,A.transformVec4(d,i,a),A.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],A.subVec3(a,n,h),A.normalizeVec3(h)}})(),canvasPosToLocalRay:(()=>{const e=new c(3),t=new c(3);return(s,n,i,a,r,l,o)=>{A.canvasPosToWorldRay(s,n,i,r,e,t),A.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new c(16),t=new c(4),s=new c(4);return(n,i,a,r,l)=>{const o=A.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,A.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],A.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new c(6),l={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let o,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,o=0,u=s.length;or[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return l.triangles=s,l.leaf=!0,l;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),l.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(o=0,u=s.length;o{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};A.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=A.vec3(),u=A.vec3(),h=A.vec3(),p=A.vec3(),d=A.vec3(),f=A.vec3(),I=A.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class d{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const f={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var I=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{g.removeItem(e.id),delete C.scenes[e.id],delete w[e.id],f.components.scenes--}))},this.clear=function(){let e;for(const t in C.scenes)C.scenes.hasOwnProperty(t)&&(e=C.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete C.scenes[e.id]))},this.scheduleTask=function(e,t){T.push(e),T.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;T.length>0&&(e<0||n0&&D>0){var t=1e3/D;R+=t,b.push(t),b.length>=30&&(R-=b.shift()),f.frame.fps=Math.round(R/b.length)}!function(e){const t=C.runTasks(e+10),s=C.getNumTasks();f.frame.tasksRun=t,f.frame.tasksScheduled=s,f.frame.tasksBudget=10}(e),function(e){for(var t in E.time=e,C.scenes)if(C.scenes.hasOwnProperty(t)){var s=C.scenes[t];E.sceneId=t,E.startTime=s.startTime,E.deltaTime=null!=E.prevTime?E.time-E.prevTime:0,s.fire("tick",E,!0)}E.prevTime=e}(e),function(){const e=C.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=w[r],n||(n=w[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),P=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(_):requestAnimationFrame(_)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(_):requestAnimationFrame(_);class B{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof B))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+v.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(v.isNumeric(s)||v.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+v.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+v.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+v.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():C.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(A.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){q.set(this._viewPos),q[3]=1,A.transformPoint4(this.scene.camera.projMatrix,q,J);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+J[0]/J[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-J[1]/J[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof X?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),N(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class ${constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class ee{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class te{constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var se=A.vec3(),ne=A.vec3();class ie extends B{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new Z(s,t.origin),this._cornerMarker=new Z(s,t.corner),this._targetMarker=new Z(s,t.target),this._originWorld=A.vec3(),this._cornerWorld=A.vec3(),this._targetWorld=A.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new ee(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new ee(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new ee(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new $(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new $(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new te(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(A.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const p=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>p||f>p||I>p)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);A.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,h=t.length;u1?i.other:i.one,i?(i=le(i,[t]),s&&(i=le(i,s)),i):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];if(n)for(const e in n)if(n.hasOwnProperty(e)){n[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let n=this._eventSubs[t];n||(n={},this._eventSubs[t]=n);const i=this._eventSubIDMap.addItem();n[i]={callback:s},this._eventSubEvents[i]=t;const a=this._events[t];return void 0!==a&&s(a),i}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function re(e,t){if(t[e])return t[e];const s=e.split(".");let n=t;for(let e=0,t=s.length;n&&e1?1:e}get t(){return this._t}get tangent(){return this.getTangent(this._t)}get length(){var e=this._getLengths();return e[e.length-1]}getTangent(e){var t=1e-4;void 0===e&&(e=this._t);var s=e-t,n=e+t;s<0&&(s=0),n>1&&(n=1);var i=this.getPoint(s),a=this.getPoint(n),r=A.subVec3(a,i,[]);return A.normalizeVec3(r,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_getLengths(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,s,n=[],i=this.getPoint(0),a=0;for(n.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),a+=A.lenVec3(A.subVec3(t,i,[])),n.push(a),i=t;return this.cacheArcLengths=n,n}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,n=this._getLengths(),i=0,a=n.length;s=t||e*n[a-1];for(var r,l=0,o=a-1;l<=o;)if((r=n[i=Math.floor(l+(o-l)/2)]-s)<0)l=i+1;else{if(!(r>0)){o=i;break}o=i-1}if(n[i=o]===s)return i/(a-1);var c=n[i];return(i+(s-c)/(n[i+1]-c))/(a-1)}}class ce extends oe{constructor(e,t={}){super(e,t),this.points=t.points,this.t=t.t}set points(e){this._points=e||[]}get points(){return this._points}set t(e){e=e||0,this._t=e<0?0:e>1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=this.points;if(!(t.length<3)){var s=(t.length-1)*e,n=Math.floor(s),i=s-n,a=t[0===n?n:n-1],r=t[n],l=t[n>t.length-2?t.length-1:n+1],o=t[n>t.length-3?t.length-1:n+2],c=A.vec3();return c[0]=A.catmullRomInterpolate(a[0],r[0],l[0],o[0],i),c[1]=A.catmullRomInterpolate(a[1],r[1],l[1],o[1],i),c[2]=A.catmullRomInterpolate(a[2],r[2],l[2],o[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}getJSON(){return{points:points,t:this._t}}}const ue=A.vec3();class he extends B{get type(){return"CameraPath"}constructor(e,t={}){super(e,t),this._frames=[],this._eyeCurve=new ce(this),this._lookCurve=new ce(this),this._upCurve=new ce(this),t.frames&&(this.addFrames(t.frames),this.smoothFrameTimes(1))}get frames(){return this._frames}get eyeCurve(){return this._eyeCurve}get lookCurve(){return this._lookCurve}get upCurve(){return this._upCurve}saveFrame(e){const t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}addFrame(e,t,s,n){const i={t:e,eye:t.slice(0),look:s.slice(0),up:n.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}addFrames(e){let t;for(let s=0,n=e.length;s1?1:e,t.eye=this._eyeCurve.getPoint(e,ue),t.look=this._lookCurve.getPoint(e,ue),t.up=this._upCurve.getPoint(e,ue)}sampleFrame(e,t,s,n){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,s),this._upCurve.getPoint(e,n)}smoothFrameTimes(e){if(0===this._frames.length)return;const t=A.vec3();var s=0;this._frames[0].t=0;const n=[];for(let e=1,a=this._frames.length;e=1;e>1&&(e=1);const s=this.easing?ye._ease(e,0,1,1):e,n=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(A.subVec3(n.eye,n.look,Ie),n.eye=A.lerpVec3(s,0,1,this._eye1,this._eye2,de),n.look=A.subVec3(de,Ie,Ae)):this._flyingLook&&(n.look=A.lerpVec3(s,0,1,this._look1,this._look2,Ae),n.up=A.lerpVec3(s,0,1,this._up1,this._up2,fe)):this._flyingEyeLookUp&&(n.eye=A.lerpVec3(s,0,1,this._eye1,this._eye2,de),n.look=A.lerpVec3(s,0,1,this._look1,this._look2,Ae),n.up=A.lerpVec3(s,0,1,this._up1,this._up2,fe)),this._projection2){const t="ortho"===this._projection2?ye._easeOutExpo(e,0,1,1):ye._easeInCubic(e,0,1,1);n.customProjection.matrix=A.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else n.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return n.ortho.scale=this._orthoScale2,void this.stop();C.scheduleTask(this._update,this)}static _ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}static _easeInCubic(e,t,s,n){return s*(e/=n)*e*e+t}static _easeOutExpo(e,t,s,n){return s*(1-Math.pow(2,-10*e/n))+t}stop(){if(!this._flying)return;this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);const e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}cancel(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}set duration(e){this._duration=e?1e3*e:500,this.stop()}get duration(){return this._duration/1e3}set fit(e){this._fit=!1!==e}get fit(){return this._fit}set fitFOV(e){this._fitFOV=e||45}get fitFOV(){return this._fitFOV}set trail(e){this._trail=!!e}get trail(){return this._trail}destroy(){this.stop(),super.destroy()}}class me extends B{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new ye(this),this._t=0,this.state=me.SCRUBBING,this._playingFromT=0,this._playingToT=0,this._playingRate=t.playingRate||1,this._playingDir=1,this._lastTime=null,this.cameraPath=t.cameraPath,this._tick=this.scene.on("tick",this._updateT,this)}_updateT(){const e=this._cameraPath;if(!e)return;let t,s;const n=performance.now(),i=this._lastTime?.001*(n-this._lastTime):0;if(this._lastTime=n,0!==i)switch(this.state){case me.SCRUBBING:return;case me.PLAYING:if(this._t+=this._playingRate*i,t=this._cameraPath.frames.length,0===t||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=me.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case me.PLAYING_TO:s=this._t+this._playingRate*i*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=me.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,n){return-s*(e/=n)*(e-2)+t}set cameraPath(e){this._cameraPath=e}get cameraPath(){return this._cameraPath}set rate(e){this._playingRate=e}get rate(){return this._playingRate}play(){this._cameraPath&&(this._lastTime=null,this.state=me.PLAYING)}playToT(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=me.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const n=s.frames[e];n?(this.state=me.SCRUBBING,this._cameraFlightAnimation.flyTo(n,t)):this.error("flyToFrame - frame index out of range: "+e)}scrubToT(e){const t=this._cameraPath;if(!t)return;this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=me.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=me.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=me.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}me.STOPPED=0,me.SCRUBBING=1,me.PLAYING=2,me.PLAYING_TO=3;class ve extends B{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),f.memory.meshes++}destroy(){super.destroy(),f.memory.meshes--}}const we=new e({});class ge{constructor(e){this.id=we.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){we.removeItem(this.id)}}class Te{constructor(e,t,s,n,i,a,r,l,o){switch(this._gl=e,this.type=t,this.allocated=!1,s.constructor){case Uint8Array:this.itemType=e.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=e.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=e.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=e.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=e.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=e.INT,this.itemByteSize=4;break;default:this.itemType=e.FLOAT,this.itemByteSize=4}this.usage=a,this.length=0,this.dataLength=n,this.numItems=0,this.itemSize=i,this.normalized=!!r,this.stride=l||0,this.offset=o||0,this._allocate(s)}_allocate(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}var Ee=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=A.vec3(),u=A.vec3(),h=A.vec3(),p=A.vec3(),d=A.vec3(),f=A.vec3(),I=A.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();const be=function(){const e=A.mat4(),t=A.mat4();return function(s,n){n=n||A.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return A.identityMat4(e),A.translationMat4v(s,e),A.identityMat4(t),A.scalingMat4v([l/u,o/u,c/u],t),A.mulMat4(e,t,n),n}}();var De=function(){const e=A.mat4(),t=A.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function Ce(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function _e(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const Be={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=Re(e,l,"floor","ceil"),n=Ce(s),a=_e(e,l,n),a>r&&(i=s,r=a),s=Re(e,l,"ceil","ceil"),n=Ce(s),a=_e(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},Oe=f.memory,Se=A.AABB3();class Ne extends ve{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new ge({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=Be.getPositionsBounds(t.positions),n=Be.compressPositions(t.positions,e.min,e.max);s.positions=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=Be.getUVBounds(t.uv),n=Be.compressUVs(t.uv,e.min,e.max);s.uv=n.quantized,s.uvDecodeMatrix=n.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);t.normals&&(this._state.compressGeometry?s.normals=Be.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),Oe.meshes++,this._buildVBOs()}_buildVBOs(){const e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),Oe.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new Te(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),Oe.positions+=e.positionsBuf.numItems),e.normals){let s=e.compressGeometry;e.normalsBuf=new Te(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,s),Oe.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new Te(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),Oe.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new Te(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),Oe.uvs+=e.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=Ee(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),Oe.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=A.buildPickTriangles(e.positions,e.indices,e.compressGeometry),n=s.positions,i=s.colors;this._pickTrianglePositionsBuf=new Te(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new Te(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),Oe.positions+=this._pickTrianglePositionsBuf.numItems,Oe.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}_webglContextLost(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}_webglContextRestored(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),Be.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=Be.getPositionsBounds(e),n=Be.compressPositions(e,s.min,s.max);e=n.quantized,t.positionsDecodeMatrix=n.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),Be.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),Be.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=A.AABB3()),A.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=A.OBB3()),A.positions3ToAABB3(this._state.positions,Se,this._state.positionsDecodeMatrix),A.AABB3ToOBB3(Se,this._obb),this._obbDirty=!1),this._obb}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),Oe.meshes--}}const xe=f.memory,Le=A.AABB3();class Me extends ve{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new ge({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=A.OBB3();const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var i;if(t.positionsDecodeMatrix);else{const e=Be.getPositionsBounds(t.positions),a=Be.compressPositions(t.positions,e.min,e.max);i=a.quantized,s.positionsDecodeMatrix=a.decodeMatrix,s.positionsBuf=new Te(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),xe.positions+=s.positionsBuf.numItems,A.positions3ToAABB3(t.positions,this._aabb),A.positions3ToAABB3(i,Le,s.positionsDecodeMatrix),A.AABB3ToOBB3(Le,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new Te(n,n.ARRAY_BUFFER,e,e.length,4,n.STATIC_DRAW),xe.colors+=s.colorsBuf.numItems}if(t.uv){const e=Be.getUVBounds(t.uv),i=Be.compressUVs(t.uv,e.min,e.max),a=i.quantized;s.uvDecodeMatrix=i.decodeMatrix,s.uvBuf=new Te(n,n.ARRAY_BUFFER,a,a.length,2,n.STATIC_DRAW),xe.uvs+=s.uvBuf.numItems}if(t.normals){const e=Be.compressNormals(t.normals);let i=s.compressGeometry;s.normalsBuf=new Te(n,n.ARRAY_BUFFER,e,e.length,3,n.STATIC_DRAW,i),xe.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new Te(n,n.ELEMENT_ARRAY_BUFFER,e,e.length,1,n.STATIC_DRAW),xe.indices+=s.indicesBuf.numItems;const a=Ee(i,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new Te(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),xe.meshes++}else this.error("Config expected: indices");else this.error("Config expected: positions")}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf}get primitive(){return this._state.primitiveName}get aabb(){return this._aabb}get obb(){return this._obb}get numTriangles(){return this._numTriangles}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),xe.meshes--}}var Fe={};function He(e,t={}){return new Promise((function(s,n){t.src||(console.error("load3DSGeometry: Parameter expected: src"),n());var i=e.canvas.spinner;i.processes++,v.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,n());var a=Fe.parse.from3DS(e).edit.objects[0].mesh,r=a.vertices,l=a.uvt,o=a.indices;i.processes--,s(v.apply(t,{primitive:"triangles",positions:r,normals:null,uv:l,indices:o}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,n()}))}))}function Ue(e,t={}){return new Promise((function(s,n){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),n());var i=e.canvas.spinner;i.processes++,v.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,n());for(var a=Fe.parse.fromOBJ(e),r=Fe.edit.unwrap(a.i_verts,a.c_verts,3),l=Fe.edit.unwrap(a.i_norms,a.c_norms,3),o=Fe.edit.unwrap(a.i_uvt,a.c_uvt,2),c=new Int32Array(a.i_verts.length),u=0;u0?l:null,autoNormals:0===l.length,uv:o,indices:c}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,n()}))}))}function Ge(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return v.apply(e,{positions:[h,p,A,o,p,A,o,c,A,h,c,A,h,p,A,h,c,A,h,c,u,h,p,u,h,p,A,h,p,u,o,p,u,o,p,A,o,p,A,o,p,u,o,c,u,o,c,A,o,c,u,h,c,u,h,c,A,o,c,A,h,c,u,o,c,u,o,p,u,h,p,u],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function je(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return v.apply(e,{primitive:"lines",positions:[o,c,u,o,c,A,o,p,u,o,p,A,h,c,u,h,c,A,h,p,u,h,p,A],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function Ve(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let n=e.height||1;n<0&&(console.error("negative height not allowed - will invert"),n*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);let a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);const r=!!e.openEnded;let l=e.center;const o=l?l[0]:0,c=l?l[1]:0,u=l?l[2]:0,h=n/2,p=n/a,A=2*Math.PI/i,d=1/i,f=(t-s)/a,I=[],y=[],m=[],w=[];let g,T,E,b,D,P,R,C,_,B,O;const S=(90-180*Math.atan(n/(s-t))/Math.PI)/90;for(g=0;g<=a;g++)for(D=t-g*f,P=h-g*p,T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),y.push(D*E),y.push(S),y.push(D*b),m.push(T*d),m.push(1*g/a),I.push(D*E+o),I.push(P+c),I.push(D*b+u);for(g=0;g0){for(_=I.length/3,y.push(0),y.push(1),y.push(0),m.push(.5),m.push(.5),I.push(0+o),I.push(h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,y.push(t*E),y.push(1),y.push(t*b),m.push(B),m.push(O),I.push(t*E+o),I.push(h+c),I.push(t*b+u);for(T=0;T0){for(_=I.length/3,y.push(0),y.push(-1),y.push(0),m.push(.5),m.push(.5),I.push(0+o),I.push(0-h+c),I.push(0+u),T=0;T<=i;T++)E=Math.sin(T*A),b=Math.cos(T*A),B=.5*Math.sin(T*A)+.5,O=.5*Math.cos(T*A)+.5,y.push(s*E),y.push(-1),y.push(s*b),m.push(B),m.push(O),I.push(s*E+o),I.push(0-h+c),I.push(s*b+u);for(T=0;T65535?Uint32Array:Uint16Array)(h*p*6);for(g=0;g360&&(a=360);const r=e.center;let l=r?r[0]:0,o=r?r[1]:0;const c=r?r[2]:0,u=[],h=[],p=[],d=[];let f,I,y,m,w,g,T,E,b,D,P,R;for(E=0;E<=i;E++)for(T=0;T<=n;T++)f=T/n*a,I=.785398+E/i*Math.PI*2,l=t*Math.cos(f),o=t*Math.sin(f),y=(t+s*Math.cos(I))*Math.cos(f),m=(t+s*Math.cos(I))*Math.sin(f),w=s*Math.sin(I),u.push(y+l),u.push(m+o),u.push(w+c),p.push(1-T/n),p.push(E/i),g=A.normalizeVec3(A.subVec3([y,m,w],[l,o,c],[]),[]),h.push(g[0]),h.push(g[1]),h.push(g[2]);for(E=1;E<=i;E++)for(T=1;T<=n;T++)b=(n+1)*E+T-1,D=(n+1)*(E-1)+T-1,P=(n+1)*(E-1)+T,R=(n+1)*E+T,d.push(b),d.push(D),d.push(P),d.push(P),d.push(R),d.push(b);return v.apply(e,{positions:u,normals:h,uv:p,indices:d})}Fe.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},Fe.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(Fe.parse._buffToStr(e));window.location.href=s},Fe.clone=function(e){return JSON.parse(JSON.stringify(e))},Fe.bin={},Fe.bin.f=new Float32Array(1),Fe.bin.fb=new Uint8Array(Fe.bin.f.buffer),Fe.bin.rf=function(e,t){for(var s=Fe.bin.f,n=Fe.bin.fb,i=0;i<4;i++)n[i]=e[t+i];return s[0]},Fe.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Fe.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Fe.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},Fe.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},Fe.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},Fe.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},Fe.parse={},Fe.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",n=0;ni&&(i=o),ca&&(a=c),ur&&(r=u)}return{min:{x:t,y:s,z:n},max:{x:i,y:a,z:r}}};const Ke={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function Ye(e={}){var t=e.origin||[0,0,0],s=t[0],n=t[1],i=t[2],a=e.size||1,r=[],l=[],o=e.text;v.isNumeric(o)&&(o=""+o);for(var c,u,h,p,A,d,f,I,y,m=(o||"").split("\n"),w=0,g=0,T=.04,E=0;E0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length){const e=this._children.splice();let t;for(let s=0,n=e.length;s0,o=!!i.compressGeometry,c=[];c.push("#version 300 es"),c.push("// Lambertian drawing vertex shader"),c.push("in vec3 position;"),c.push("uniform mat4 modelMatrix;"),c.push("uniform mat4 viewMatrix;"),c.push("uniform mat4 projMatrix;"),c.push("uniform vec4 colorize;"),c.push("uniform vec3 offset;"),o&&c.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(c.push("uniform float logDepthBufFC;"),c.push("out float vFragDepth;"),c.push("bool isPerspectiveMatrix(mat4 m) {"),c.push(" return (m[2][3] == - 1.0);"),c.push("}"),c.push("out float isPerspective;"));l&&c.push("out vec4 vWorldPosition;");if(c.push("uniform vec4 lightAmbient;"),c.push("uniform vec4 materialColor;"),c.push("uniform vec3 materialEmissive;"),i.normalsBuf){c.push("in vec3 normal;"),c.push("uniform mat4 modelNormalMatrix;"),c.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=n.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),c.push(" }"),c.push(" return normalize(v);"),c.push("}"))}c.push("out vec4 vColor;"),"points"===i.primitiveName&&c.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(c.push("void billboard(inout mat4 mat) {"),c.push(" mat[0][0] = 1.0;"),c.push(" mat[0][1] = 0.0;"),c.push(" mat[0][2] = 0.0;"),"spherical"===a&&(c.push(" mat[1][0] = 0.0;"),c.push(" mat[1][1] = 1.0;"),c.push(" mat[1][2] = 0.0;")),c.push(" mat[2][0] = 0.0;"),c.push(" mat[2][1] = 0.0;"),c.push(" mat[2][2] =1.0;"),c.push("}"));c.push("void main(void) {"),c.push("vec4 localPosition = vec4(position, 1.0); "),c.push("vec4 worldPosition;"),o&&c.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(o?c.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):c.push("vec4 localNormal = vec4(normal, 0.0); "),c.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),c.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));c.push("mat4 viewMatrix2 = viewMatrix;"),c.push("mat4 modelMatrix2 = modelMatrix;"),r&&c.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(c.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),c.push("billboard(modelMatrix2);"),c.push("billboard(viewMatrix2);"),c.push("billboard(modelViewMatrix);"),i.normalsBuf&&(c.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),c.push("billboard(modelNormalMatrix2);"),c.push("billboard(viewNormalMatrix2);"),c.push("billboard(modelViewNormalMatrix);")),c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(c.push("worldPosition = modelMatrix2 * localPosition;"),c.push("worldPosition.xyz = worldPosition.xyz + offset;"),c.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&c.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(c.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),c.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),c.push("float lambertian = 1.0;"),i.normalsBuf)for(let e=0,t=n.lights.length;e0,a=t.gammaOutput,r=[];r.push("#version 300 es"),r.push("// Lambertian drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),t.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;"));if(i){r.push("in vec4 vWorldPosition;"),r.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),r.push("}")}"points"===n.primitiveName&&(r.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),r.push("float r = dot(cxy, cxy);"),r.push("if (r > 1.0) {"),r.push(" discard;"),r.push("}"));t.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?r.push("outColor = linearToGamma(vColor, gammaFactor);"):r.push("outColor = vColor;");return r.push("}"),r}(e)):(this.vertex=function(e){const t=e.scene;e._material;const s=e._state,n=t._sectionPlanesState,i=e._geometry._state,a=t._lightsState;let r;const l=s.billboard,o=s.background,c=s.stationary,u=function(e){if(!e._geometry._state.uvBuf)return!1;const t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),h=Ts(e),p=n.sectionPlanes.length>0,A=gs(e),d=!!i.compressGeometry,f=[];f.push("#version 300 es"),f.push("// Drawing vertex shader"),f.push("in vec3 position;"),d&&f.push("uniform mat4 positionsDecodeMatrix;");f.push("uniform mat4 modelMatrix;"),f.push("uniform mat4 viewMatrix;"),f.push("uniform mat4 projMatrix;"),f.push("out vec3 vViewPosition;"),f.push("uniform vec3 offset;"),p&&f.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(f.push("uniform float logDepthBufFC;"),f.push("out float vFragDepth;"),f.push("bool isPerspectiveMatrix(mat4 m) {"),f.push(" return (m[2][3] == - 1.0);"),f.push("}"),f.push("out float isPerspective;"));a.lightMaps.length>0&&f.push("out vec3 vWorldNormal;");if(h){f.push("in vec3 normal;"),f.push("uniform mat4 modelNormalMatrix;"),f.push("uniform mat4 viewNormalMatrix;"),f.push("out vec3 vViewNormal;");for(let e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),f.push(" }"),f.push(" return normalize(v);"),f.push("}"))}u&&(f.push("in vec2 uv;"),f.push("out vec2 vUV;"),d&&f.push("uniform mat3 uvDecodeMatrix;"));i.colors&&(f.push("in vec4 color;"),f.push("out vec4 vColor;"));"points"===i.primitiveName&&f.push("uniform float pointSize;");"spherical"!==l&&"cylindrical"!==l||(f.push("void billboard(inout mat4 mat) {"),f.push(" mat[0][0] = 1.0;"),f.push(" mat[0][1] = 0.0;"),f.push(" mat[0][2] = 0.0;"),"spherical"===l&&(f.push(" mat[1][0] = 0.0;"),f.push(" mat[1][1] = 1.0;"),f.push(" mat[1][2] = 0.0;")),f.push(" mat[2][0] = 0.0;"),f.push(" mat[2][1] = 0.0;"),f.push(" mat[2][2] =1.0;"),f.push("}"));if(A){f.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(let e=0,t=a.lights.length;e0&&f.push("vWorldNormal = worldNormal;"),f.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),f.push("vec3 tmpVec3;"),f.push("float lightDist;");for(let e=0,t=a.lights.length;e0,o=Ts(e),c=n.uvBuf,u="PhongMaterial"===r.type,h="MetallicMaterial"===r.type,p="SpecularMaterial"===r.type,A=gs(e);t.gammaInput;const d=t.gammaOutput,f=[];f.push("#version 300 es"),f.push("// Drawing fragment shader"),f.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),f.push("precision highp float;"),f.push("precision highp int;"),f.push("#else"),f.push("precision mediump float;"),f.push("precision mediump int;"),f.push("#endif"),t.logarithmicDepthBufferEnabled&&(f.push("in float isPerspective;"),f.push("uniform float logDepthBufFC;"),f.push("in float vFragDepth;"));A&&(f.push("float unpackDepth (vec4 color) {"),f.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),f.push(" return dot(color, bitShift);"),f.push("}"));f.push("uniform float gammaFactor;"),f.push("vec4 linearToLinear( in vec4 value ) {"),f.push(" return value;"),f.push("}"),f.push("vec4 sRGBToLinear( in vec4 value ) {"),f.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),f.push("}"),f.push("vec4 gammaToLinear( in vec4 value) {"),f.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),f.push("}"),d&&(f.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),f.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),f.push("}"));if(l){f.push("in vec4 vWorldPosition;"),f.push("uniform bool clippable;");for(var I=0;I0&&(f.push("uniform samplerCube lightMap;"),f.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&f.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("uniform mat4 viewMatrix;"),f.push("#define PI 3.14159265359"),f.push("#define RECIPROCAL_PI 0.31830988618"),f.push("#define RECIPROCAL_PI2 0.15915494"),f.push("#define EPSILON 1e-6"),f.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),f.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),f.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),f.push("}"),f.push("struct IncidentLight {"),f.push(" vec3 color;"),f.push(" vec3 direction;"),f.push("};"),f.push("struct ReflectedLight {"),f.push(" vec3 diffuse;"),f.push(" vec3 specular;"),f.push("};"),f.push("struct Geometry {"),f.push(" vec3 position;"),f.push(" vec3 viewNormal;"),f.push(" vec3 worldNormal;"),f.push(" vec3 viewEyeDir;"),f.push("};"),f.push("struct Material {"),f.push(" vec3 diffuseColor;"),f.push(" float specularRoughness;"),f.push(" vec3 specularColor;"),f.push(" float shine;"),f.push("};"),u&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = "+ws[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),f.push(" radiance *= PI;"),f.push(" reflectedLight.specular += radiance;")),f.push("}")),f.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),f.push(" vec3 irradiance = dotNL * directLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),f.push("}")),(h||p)&&(f.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),f.push(" float r = ggxRoughness + 0.0001;"),f.push(" return (2.0 / (r * r) - 2.0);"),f.push("}"),f.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),f.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),f.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),f.push("}"),a.reflectionMaps.length>0&&(f.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),f.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),f.push(" vec3 envMapColor = "+ws[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),f.push(" return envMapColor;"),f.push("}")),f.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),f.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),f.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),f.push("}"),f.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" return 1.0 / ( gl * gv );"),f.push("}"),f.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),f.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),f.push(" return 0.5 / max( gv + gl, EPSILON );"),f.push("}"),f.push("float D_GGX(const in float alpha, const in float dotNH) {"),f.push(" float a2 = ( alpha * alpha );"),f.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),f.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float alpha = ( roughness * roughness );"),f.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),f.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),f.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),f.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),f.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),f.push(" vec3 F = F_Schlick( specularColor, dotLH );"),f.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),f.push(" float D = D_GGX( alpha, dotNH );"),f.push(" return F * (G * D);"),f.push("}"),f.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),f.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),f.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),f.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),f.push(" vec4 r = roughness * c0 + c1;"),f.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),f.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),f.push(" return specularColor * AB.x + AB.y;"),f.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(f.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(f.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),f.push(" irradiance *= PI;"),f.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(f.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),f.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),f.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),f.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),f.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),f.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),f.push("}")),f.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),f.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),f.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),f.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),f.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),f.push("}")));f.push("in vec3 vViewPosition;"),n.colors&&f.push("in vec4 vColor;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._occlusionMap||s._alphaMap)&&f.push("in vec2 vUV;");o&&(a.lightMaps.length>0&&f.push("in vec3 vWorldNormal;"),f.push("in vec3 vViewNormal;"));r.ambient&&f.push("uniform vec3 materialAmbient;");r.baseColor&&f.push("uniform vec3 materialBaseColor;");void 0!==r.alpha&&null!==r.alpha&&f.push("uniform vec4 materialAlphaModeCutoff;");r.emissive&&f.push("uniform vec3 materialEmissive;");r.diffuse&&f.push("uniform vec3 materialDiffuse;");void 0!==r.glossiness&&null!==r.glossiness&&f.push("uniform float materialGlossiness;");void 0!==r.shininess&&null!==r.shininess&&f.push("uniform float materialShininess;");r.specular&&f.push("uniform vec3 materialSpecular;");void 0!==r.metallic&&null!==r.metallic&&f.push("uniform float materialMetallic;");void 0!==r.roughness&&null!==r.roughness&&f.push("uniform float materialRoughness;");void 0!==r.specularF0&&null!==r.specularF0&&f.push("uniform float materialSpecularF0;");c&&s._ambientMap&&(f.push("uniform sampler2D ambientMap;"),s._ambientMap._state.matrix&&f.push("uniform mat4 ambientMapMatrix;"));c&&s._baseColorMap&&(f.push("uniform sampler2D baseColorMap;"),s._baseColorMap._state.matrix&&f.push("uniform mat4 baseColorMapMatrix;"));c&&s._diffuseMap&&(f.push("uniform sampler2D diffuseMap;"),s._diffuseMap._state.matrix&&f.push("uniform mat4 diffuseMapMatrix;"));c&&s._emissiveMap&&(f.push("uniform sampler2D emissiveMap;"),s._emissiveMap._state.matrix&&f.push("uniform mat4 emissiveMapMatrix;"));o&&c&&s._metallicMap&&(f.push("uniform sampler2D metallicMap;"),s._metallicMap._state.matrix&&f.push("uniform mat4 metallicMapMatrix;"));o&&c&&s._roughnessMap&&(f.push("uniform sampler2D roughnessMap;"),s._roughnessMap._state.matrix&&f.push("uniform mat4 roughnessMapMatrix;"));o&&c&&s._metallicRoughnessMap&&(f.push("uniform sampler2D metallicRoughnessMap;"),s._metallicRoughnessMap._state.matrix&&f.push("uniform mat4 metallicRoughnessMapMatrix;"));o&&s._normalMap&&(f.push("uniform sampler2D normalMap;"),s._normalMap._state.matrix&&f.push("uniform mat4 normalMapMatrix;"),f.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),f.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),f.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),f.push(" vec2 st0 = dFdx( uv.st );"),f.push(" vec2 st1 = dFdy( uv.st );"),f.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),f.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),f.push(" vec3 N = normalize( surf_norm );"),f.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),f.push(" mat3 tsn = mat3( S, T, N );"),f.push(" return normalize( tsn * mapN );"),f.push("}"));c&&s._occlusionMap&&(f.push("uniform sampler2D occlusionMap;"),s._occlusionMap._state.matrix&&f.push("uniform mat4 occlusionMapMatrix;"));c&&s._alphaMap&&(f.push("uniform sampler2D alphaMap;"),s._alphaMap._state.matrix&&f.push("uniform mat4 alphaMapMatrix;"));o&&c&&s._specularMap&&(f.push("uniform sampler2D specularMap;"),s._specularMap._state.matrix&&f.push("uniform mat4 specularMapMatrix;"));o&&c&&s._glossinessMap&&(f.push("uniform sampler2D glossinessMap;"),s._glossinessMap._state.matrix&&f.push("uniform mat4 glossinessMapMatrix;"));o&&c&&s._specularGlossinessMap&&(f.push("uniform sampler2D materialSpecularGlossinessMap;"),s._specularGlossinessMap._state.matrix&&f.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));o&&(s._diffuseFresnel||s._specularFresnel||s._alphaFresnel||s._emissiveFresnel||s._reflectivityFresnel)&&(f.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),f.push(" float fr = abs(dot(eyeDir, normal));"),f.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),f.push(" return pow(finalFr, power);"),f.push("}"),s._diffuseFresnel&&(f.push("uniform float diffuseFresnelCenterBias;"),f.push("uniform float diffuseFresnelEdgeBias;"),f.push("uniform float diffuseFresnelPower;"),f.push("uniform vec3 diffuseFresnelCenterColor;"),f.push("uniform vec3 diffuseFresnelEdgeColor;")),s._specularFresnel&&(f.push("uniform float specularFresnelCenterBias;"),f.push("uniform float specularFresnelEdgeBias;"),f.push("uniform float specularFresnelPower;"),f.push("uniform vec3 specularFresnelCenterColor;"),f.push("uniform vec3 specularFresnelEdgeColor;")),s._alphaFresnel&&(f.push("uniform float alphaFresnelCenterBias;"),f.push("uniform float alphaFresnelEdgeBias;"),f.push("uniform float alphaFresnelPower;"),f.push("uniform vec3 alphaFresnelCenterColor;"),f.push("uniform vec3 alphaFresnelEdgeColor;")),s._reflectivityFresnel&&(f.push("uniform float materialSpecularF0FresnelCenterBias;"),f.push("uniform float materialSpecularF0FresnelEdgeBias;"),f.push("uniform float materialSpecularF0FresnelPower;"),f.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),f.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),s._emissiveFresnel&&(f.push("uniform float emissiveFresnelCenterBias;"),f.push("uniform float emissiveFresnelEdgeBias;"),f.push("uniform float emissiveFresnelPower;"),f.push("uniform vec3 emissiveFresnelCenterColor;"),f.push("uniform vec3 emissiveFresnelEdgeColor;")));if(f.push("uniform vec4 lightAmbient;"),o)for(let e=0,t=a.lights.length;e 0.0) { discard; }"),f.push("}")}"points"===n.primitiveName&&(f.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),f.push("float r = dot(cxy, cxy);"),f.push("if (r > 1.0) {"),f.push(" discard;"),f.push("}"));f.push("float occlusion = 1.0;"),r.ambient?f.push("vec3 ambientColor = materialAmbient;"):f.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");r.diffuse?f.push("vec3 diffuseColor = materialDiffuse;"):r.baseColor?f.push("vec3 diffuseColor = materialBaseColor;"):f.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");n.colors&&f.push("diffuseColor *= vColor.rgb;");r.emissive?f.push("vec3 emissiveColor = materialEmissive;"):f.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");r.specular?f.push("vec3 specular = materialSpecular;"):f.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==r.alpha?f.push("float alpha = materialAlphaModeCutoff[0];"):f.push("float alpha = 1.0;");n.colors&&f.push("alpha *= vColor.a;");void 0!==r.glossiness?f.push("float glossiness = materialGlossiness;"):f.push("float glossiness = 1.0;");void 0!==r.metallic?f.push("float metallic = materialMetallic;"):f.push("float metallic = 1.0;");void 0!==r.roughness?f.push("float roughness = materialRoughness;"):f.push("float roughness = 1.0;");void 0!==r.specularF0?f.push("float specularF0 = materialSpecularF0;"):f.push("float specularF0 = 1.0;");c&&(o&&s._normalMap||s._ambientMap||s._baseColorMap||s._diffuseMap||s._occlusionMap||s._emissiveMap||s._metallicMap||s._roughnessMap||s._metallicRoughnessMap||s._specularMap||s._glossinessMap||s._specularGlossinessMap||s._alphaMap)&&(f.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),f.push("vec2 textureCoord;"));c&&s._ambientMap&&(s._ambientMap._state.matrix?f.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),f.push("ambientTexel = "+ws[s._ambientMap._state.encoding]+"(ambientTexel);"),f.push("ambientColor *= ambientTexel.rgb;"));c&&s._diffuseMap&&(s._diffuseMap._state.matrix?f.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),f.push("diffuseTexel = "+ws[s._diffuseMap._state.encoding]+"(diffuseTexel);"),f.push("diffuseColor *= diffuseTexel.rgb;"),f.push("alpha *= diffuseTexel.a;"));c&&s._baseColorMap&&(s._baseColorMap._state.matrix?f.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),f.push("baseColorTexel = "+ws[s._baseColorMap._state.encoding]+"(baseColorTexel);"),f.push("diffuseColor *= baseColorTexel.rgb;"),f.push("alpha *= baseColorTexel.a;"));c&&s._emissiveMap&&(s._emissiveMap._state.matrix?f.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),f.push("emissiveTexel = "+ws[s._emissiveMap._state.encoding]+"(emissiveTexel);"),f.push("emissiveColor = emissiveTexel.rgb;"));c&&s._alphaMap&&(s._alphaMap._state.matrix?f.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("alpha *= texture(alphaMap, textureCoord).r;"));c&&s._occlusionMap&&(s._occlusionMap._state.matrix?f.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(o&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){c&&s._normalMap?(s._normalMap._state.matrix?f.push("textureCoord = (normalMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):f.push("vec3 viewNormal = normalize(vViewNormal);"),c&&s._specularMap&&(s._specularMap._state.matrix?f.push("textureCoord = (specularMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("specular *= texture(specularMap, textureCoord).rgb;")),c&&s._glossinessMap&&(s._glossinessMap._state.matrix?f.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("glossiness *= texture(glossinessMap, textureCoord).r;")),c&&s._specularGlossinessMap&&(s._specularGlossinessMap._state.matrix?f.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),f.push("specular *= specGlossRGB.rgb;"),f.push("glossiness *= specGlossRGB.a;")),c&&s._metallicMap&&(s._metallicMap._state.matrix?f.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("metallic *= texture(metallicMap, textureCoord).r;")),c&&s._roughnessMap&&(s._roughnessMap._state.matrix?f.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("roughness *= texture(roughnessMap, textureCoord).r;")),c&&s._metallicRoughnessMap&&(s._metallicRoughnessMap._state.matrix?f.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):f.push("textureCoord = texturePos.xy;"),f.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),f.push("metallic *= metalRoughRGB.b;"),f.push("roughness *= metalRoughRGB.g;")),f.push("vec3 viewEyeDir = normalize(-vViewPosition);"),s._diffuseFresnel&&(f.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),f.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),s._specularFresnel&&(f.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),f.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),s._alphaFresnel&&(f.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),f.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),s._emissiveFresnel&&(f.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),f.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),f.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),f.push(" discard;"),f.push("}"),f.push("IncidentLight light;"),f.push("Material material;"),f.push("Geometry geometry;"),f.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),f.push("vec3 viewLightDir;"),u&&(f.push("material.diffuseColor = diffuseColor;"),f.push("material.specularColor = specular;"),f.push("material.shine = materialShininess;")),p&&(f.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),f.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),f.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),f.push("material.specularColor = specular;")),h&&(f.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),f.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),f.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),f.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),f.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&f.push("geometry.worldNormal = normalize(vWorldNormal);"),f.push("geometry.viewNormal = viewNormal;"),f.push("geometry.viewEyeDir = viewEyeDir;"),u&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||h)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&f.push("computePBRLightMapping(geometry, material, reflectedLight);"),f.push("float shadow = 1.0;"),f.push("float shadowAcneRemover = 0.007;"),f.push("vec3 fragmentDepth;"),f.push("float texelSize = 1.0 / 1024.0;"),f.push("float amountInLight = 0.0;"),f.push("vec3 shadowCoord;"),f.push("vec4 rgbaDepth;"),f.push("float depth;");for(let e=0,t=a.lights.length;e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function Cs(e){console.error(e.join("\n"))}class _s{constructor(e,t){this.id=Ps.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new Es(e,e.VERTEX_SHADER,Rs(this.source.vertex)),this._fragmentShader=new Es(e,e.FRAGMENT_SHADER,Rs(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void Cs(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void Cs(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void Cs(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void Cs(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void Cs(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;s0?Bs.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?Bs.FS_MAX_FLOAT_PRECISION="mediump":Bs.FS_MAX_FLOAT_PRECISION="lowp":Bs.FS_MAX_FLOAT_PRECISION="mediump",Bs.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),Bs.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),Bs.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),Bs.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),Bs.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Bs.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),Bs.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),Bs.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),Bs.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),Bs.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){Bs.SUPPORTED_EXTENSIONS[e]=!0})))}const Ss=A.vec3(),Ns=new e({}),xs=function(e,t){this.id=Ns.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new vs(t),this._allocate(t)},Ls={};xs.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,(t.gammaInput?"gi;":";")+(t.gammaOutput?"go":""),t._lightsState.getHash(),t._sectionPlanesState.getHash(),e._geometry._state.hash,e._material._state.hash,e._state.drawHash].join(";");let n=Ls[s];if(!n){if(n=new xs(s,e),n.errors)return console.log(n.errors.join("\n")),null;Ls[s]=n,f.memory.programs++}return n._useCount++,n},xs.prototype.put=function(){0==--this._useCount&&(Ns.removeItem(this.id),this._program&&this._program.destroy(),delete Ls[this._hash],f.memory.programs--)},xs.prototype.webglContextRestored=function(){this._program=null},xs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=Bs.MAX_TEXTURE_UNITS,n=t.scene,i=t._material,a=n.canvas.gl,r=this._program,l=t._state,o=t._material._state,c=t._geometry._state,u=n.camera,h=t.origin,p=l.background;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,p&&a.depthFunc(a.LEQUAL),this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,h?e.getRTCViewMatrix(l.originHash,h):u.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,u.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(u=0,h=a.sectionPlanes.length;u0&&i.lightMaps[0].texture&&this._uLightMap&&(l.bindTexture(this._uLightMap,i.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),i.reflectionMaps.length>0&&i.reflectionMaps[0].texture&&this._uReflectionMap&&(l.bindTexture(this._uReflectionMap,i.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%t,e.bindTexture++),this._uGammaFactor&&n.uniform1f(this._uGammaFactor,s.gammaFactor),this._baseTextureUnit=e.textureUnit};class Ms{constructor(e){this.vertex=function(e){const t=e.scene,s=t._lightsState,n=function(e){const t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,r=e._state.billboard,l=e._state.stationary,o=[];o.push("#version 300 es"),o.push("// EmphasisFillShaderSource vertex shader"),o.push("in vec3 position;"),o.push("uniform mat4 modelMatrix;"),o.push("uniform mat4 viewMatrix;"),o.push("uniform mat4 projMatrix;"),o.push("uniform vec4 colorize;"),o.push("uniform vec3 offset;"),a&&o.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;"));i&&o.push("out vec4 vWorldPosition;");if(o.push("uniform vec4 lightAmbient;"),o.push("uniform vec4 fillColor;"),n){o.push("in vec3 normal;"),o.push("uniform mat4 modelNormalMatrix;"),o.push("uniform mat4 viewNormalMatrix;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"))}o.push("out vec4 vColor;"),("spherical"===r||"cylindrical"===r)&&(o.push("void billboard(inout mat4 mat) {"),o.push(" mat[0][0] = 1.0;"),o.push(" mat[0][1] = 0.0;"),o.push(" mat[0][2] = 0.0;"),"spherical"===r&&(o.push(" mat[1][0] = 0.0;"),o.push(" mat[1][1] = 1.0;"),o.push(" mat[1][2] = 0.0;")),o.push(" mat[2][0] = 0.0;"),o.push(" mat[2][1] = 0.0;"),o.push(" mat[2][2] =1.0;"),o.push("}"));o.push("void main(void) {"),o.push("vec4 localPosition = vec4(position, 1.0); "),o.push("vec4 worldPosition;"),a&&o.push("localPosition = positionsDecodeMatrix * localPosition;");n&&(a?o.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):o.push("vec4 localNormal = vec4(normal, 0.0); "),o.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),o.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));o.push("mat4 viewMatrix2 = viewMatrix;"),o.push("mat4 modelMatrix2 = modelMatrix;"),l&&o.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===r||"cylindrical"===r?(o.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),o.push("billboard(modelMatrix2);"),o.push("billboard(viewMatrix2);"),o.push("billboard(modelViewMatrix);"),n&&(o.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),o.push("billboard(modelNormalMatrix2);"),o.push("billboard(viewNormalMatrix2);"),o.push("billboard(modelViewNormalMatrix);")),o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(o.push("worldPosition = modelMatrix2 * localPosition;"),o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&o.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),n)for(let e=0,t=s.lights.length;e0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const Fs=new e({}),Hs=A.vec3(),Us=function(e,t){this.id=Fs.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Ms(t),this._allocate(t)},Gs={};Us.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Gs[t];return s||(s=new Us(t,e),Gs[t]=s,f.memory.programs++),s._useCount++,s},Us.prototype.put=function(){0==--this._useCount&&(Fs.removeItem(this.id),this._program&&this._program.destroy(),delete Gs[this._hash],f.memory.programs--)},Us.prototype.webglContextRestored=function(){this._program=null},Us.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl,r=0===s?t._xrayMaterial._state:1===s?t._highlightMaterial._state:t._selectedMaterial._state,l=t._state,o=t._geometry._state,c=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,c?e.getRTCViewMatrix(l.originHash,c):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Edges drawing vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec4 edgeColor;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));s&&r.push("out vec4 vWorldPosition;");r.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r.push("vColor = edgeColor;"),s&&r.push("vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=e.scene._sectionPlanesState,n=e.scene.gammaOutput,i=s.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));n&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");n?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(e)}}const Vs=new e({}),ks=A.vec3(),Qs=function(e,t){this.id=Vs.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new js(t),this._allocate(t)},Ws={};Qs.get=function(e){const t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=Ws[t];return s||(s=new Qs(t,e),Ws[t]=s,f.memory.programs++),s._useCount++,s},Qs.prototype.put=function(){0==--this._useCount&&(Vs.removeItem(this.id),this._program&&this._program.destroy(),delete Ws[this._hash],f.memory.programs--)},Qs.prototype.webglContextRestored=function(){this._program=null},Qs.prototype.drawMesh=function(e,t,s){this._program||this._allocate(t);const n=this._scene,i=n.camera,a=n.canvas.gl;let r;const l=t._state,o=t._geometry,c=o._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(l.originHash,u):i.viewMatrix),l.clippable){const e=n._sectionPlanesState.sectionPlanes.length;if(e>0){const s=n._sectionPlanesState.sectionPlanes,i=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh picking vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("out vec4 vViewPosition;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("uniform vec2 pickClipPos;"),r.push("vec4 remapClipPos(vec4 clipPos) {"),r.push(" clipPos.xy /= clipPos.w;"),r.push(" clipPos.xy -= pickClipPos;"),r.push(" clipPos.xy *= clipPos.w;"),r.push(" return clipPos;"),r.push("}"),r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"));r.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = remapClipPos(clipPos);"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(e)}}const Ks=A.vec3(),Ys=function(e,t){this._hash=e,this._shaderSource=new zs(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Xs={};Ys.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let s=Xs[t];if(!s){if(s=new Ys(t,e),s.errors)return console.log(s.errors.join("\n")),null;Xs[t]=s,f.memory.programs++}return s._useCount++,s},Ys.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Xs[this._hash],f.memory.programs--)},Ys.prototype.webglContextRestored=function(){this._program=null},Ys.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t>24&255,u=o>>16&255,h=o>>8&255,p=255&o;n.uniform4f(this._uPickColor,p/255,h/255,u/255,c/255),n.uniform2fv(this._uPickClipPos,e.pickClipPos),r.indicesBuf?(n.drawElements(r.primitive,r.indicesBuf.numItems,r.indicesBuf.itemType,0),e.drawElements++):r.positions&&n.drawArrays(n.TRIANGLES,0,r.positions.numItems)},Ys.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new _s(s,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0,n=!!e._geometry._state.compressGeometry,i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),s&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("uniform vec2 pickClipPos;"),i.push("vec4 remapClipPos(vec4 clipPos) {"),i.push(" clipPos.xy /= clipPos.w;"),i.push(" clipPos.xy -= pickClipPos;"),i.push(" clipPos.xy *= clipPos.w;"),i.push(" return clipPos;"),i.push("}"),i.push("out vec4 vColor;"),n&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),n&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),s&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(e)}}const Js=A.vec3(),Zs=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new qs(t),this._allocate(t)},$s={};Zs.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";");let s=$s[t];if(!s){if(s=new Zs(t,e),s.errors)return console.log(s.errors.join("\n")),null;$s[t]=s,f.memory.programs++}return s._useCount++,s},Zs.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete $s[this._hash],f.memory.programs--)},Zs.prototype.webglContextRestored=function(){this._program=null},Zs.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._state,a=t._material._state,r=t._geometry,l=t._geometry._state,o=t.origin,c=a.backfaces,u=a.frontface,h=s.camera.project,p=r._getPickTrianglePositions(),A=r._getPickTriangleColors();if(this._program.bind(),e.useProgram++,s.logarithmicDepthBufferEnabled){const e=2/(Math.log(h.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,e)}if(n.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,n=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,r=[];r.push("#version 300 es"),r.push("// Mesh occlusion vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");s&&r.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(r.push("void billboard(inout mat4 mat) {"),r.push(" mat[0][0] = 1.0;"),r.push(" mat[0][1] = 0.0;"),r.push(" mat[0][2] = 0.0;"),"spherical"===i&&(r.push(" mat[1][0] = 0.0;"),r.push(" mat[1][1] = 1.0;"),r.push(" mat[1][2] = 0.0;")),r.push(" mat[2][0] = 0.0;"),r.push(" mat[2][1] = 0.0;"),r.push(" mat[2][2] =1.0;"),r.push("}"));r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("mat4 viewMatrix2 = viewMatrix;"),r.push("mat4 modelMatrix2 = modelMatrix;"),a&&r.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(r.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),r.push("billboard(modelMatrix2);"),r.push("billboard(viewMatrix2);"),r.push("billboard(modelViewMatrix);"),r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(r.push("worldPosition = modelMatrix2 * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s&&r.push(" vWorldPosition = worldPosition;");r.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return r.push("gl_Position = clipPos;"),r.push("}"),r}(e),this.fragment=function(e){const t=e.scene,s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(e)}}const tn=A.vec3(),sn=function(e,t){this._hash=e,this._shaderSource=new en(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},nn={};sn.get=function(e){const t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";");let s=nn[t];if(!s){if(s=new sn(t,e),s.errors)return console.log(s.errors.join("\n")),null;nn[t]=s,f.memory.programs++}return s._useCount++,s},sn.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete nn[this._hash],f.memory.programs--)},sn.prototype.webglContextRestored=function(){this._program=null},sn.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene,n=s.canvas.gl,i=t._material._state,a=t._state,r=t._geometry._state,l=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){const t=i.backfaces;e.backfaces!==t&&(t?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=t);const s=i.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),this._lastMaterialId=i.id}const o=s.camera;if(n.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCViewMatrix(a.originHash,l):o.viewMatrix),a.clippable){const e=s._sectionPlanesState.sectionPlanes.length;if(e>0){const i=s._sectionPlanesState.sectionPlanes,a=t.renderFlags;for(let t=0;t0,s=!!e._geometry._state.compressGeometry,n=[];n.push("// Mesh shadow vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),n.push("uniform vec3 offset;"),s&&n.push("uniform mat4 positionsDecodeMatrix;");t&&n.push("out vec4 vWorldPosition;");n.push("void main(void) {"),n.push("vec4 localPosition = vec4(position, 1.0); "),n.push("vec4 worldPosition;"),s&&n.push("localPosition = positionsDecodeMatrix * localPosition;");n.push("worldPosition = modelMatrix * localPosition;"),n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&n.push("vWorldPosition = worldPosition;");return n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n}(e),this.fragment=function(e){const t=e.scene;t.canvas.gl;const s=t._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),n){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(e)}}const rn=function(e,t){this._hash=e,this._shaderSource=new an(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},ln={};rn.get=function(e){const t=e.scene,s=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";");let n=ln[s];if(!n){if(n=new rn(s,e),n.errors)return console.log(n.errors.join("\n")),null;ln[s]=n,f.memory.programs++}return n._useCount++,n},rn.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete ln[this._hash],f.memory.programs--)},rn.prototype.webglContextRestored=function(){this._program=null},rn.prototype.drawMesh=function(e,t){this._program||this._allocate(t);const s=this._scene.canvas.gl,n=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),n.id!==this._lastMaterialId){const t=n.backfaces;e.backfaces!==t&&(t?s.disable(s.CULL_FACE):s.enable(s.CULL_FACE),e.backfaces=t);const i=n.frontface;e.frontface!==i&&(i?s.frontFace(s.CCW):s.frontFace(s.CW),e.frontface=i),e.lineWidth!==n.lineWidth&&(s.lineWidth(n.lineWidth),e.lineWidth=n.lineWidth),this._uPointSize&&s.uniform1i(this._uPointSize,n.pointSize),this._lastMaterialId=n.id}if(s.uniformMatrix4fv(this._uModelMatrix,s.FALSE,t.worldMatrix),i.combineGeometry){const n=t.vertexBufs;n.id!==this._lastVertexBufsId&&(n.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(n.positionsBuf,n.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),this._lastVertexBufsId=n.id)}this._uClippable&&s.uniform1i(this._uClippable,t._state.clippable),s.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?s.UNSIGNED_SHORT:s.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(s.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(s.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(s.drawArrays(s.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},rn.prototype._allocate=function(e){const t=e.scene,s=t.canvas.gl;if(this._program=new _s(s,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uModelMatrix=n.getLocation("modelMatrix"),this._uShadowViewMatrix=n.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=n.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(let e=0,s=t._sectionPlanesState.sectionPlanes.length;e0){let e,t,i,a,r;for(let l=0,o=this._uSectionPlanes.length;l0)for(let s=0;s0!==e))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}const wn=function(){const e=A.vec3(),t=A.vec3(),s=A.vec3(),n=A.vec3(),i=A.vec3(),a=A.vec3(),r=A.vec4(),l=A.vec3(),o=A.vec3(),c=A.vec3(),u=A.vec3(),h=A.vec3(),p=A.vec3(),d=A.vec3(),f=A.vec3(),I=A.vec3(),y=A.vec4(),m=A.vec4(),v=A.vec4(),w=A.vec3(),g=A.vec3(),T=A.vec3(),E=A.vec3(),b=A.vec3(),D=A.vec3(),P=A.vec3(),R=A.vec3(),C=A.vec3(),_=A.vec3(),B=A.vec3();return function(O,N,x,L){var M=L.primIndex;if(null!=M&&M>-1){const G=O.geometry._state,j=O.scene,V=j.camera,k=j.canvas;if("triangles"===G.primitiveName){L.primitive="triangle";const j=M,Q=G.indices,W=G.positions;let z,K,Y;if(Q){var F=Q[j+0],H=Q[j+1],U=Q[j+2];a[0]=F,a[1]=H,a[2]=U,L.indices=a,z=3*F,K=3*H,Y=3*U}else z=3*j,K=z+3,Y=K+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],n[0]=W[K+0],n[1]=W[K+1],n[2]=W[K+2],i[0]=W[Y+0],i[1]=W[Y+1],i[2]=W[Y+2],G.compressGeometry){const e=G.positionsDecodeMatrix;e&&(Be.decompressPosition(s,e,s),Be.decompressPosition(n,e,n),Be.decompressPosition(i,e,i))}L.canvasPos?A.canvasPosToLocalRay(k.canvas,O.origin?S(N,O.origin):N,x,O.worldMatrix,L.canvasPos,e,t):L.origin&&L.direction&&A.worldRayToLocalRay(O.worldMatrix,L.origin,L.direction,e,t),A.normalizeVec3(t),A.rayPlaneIntersect(e,t,s,n,i,r),L.localPos=r,L.position=r,y[0]=r[0],y[1]=r[1],y[2]=r[2],y[3]=1,A.transformVec4(O.worldMatrix,y,m),l[0]=m[0],l[1]=m[1],l[2]=m[2],L.canvasPos&&O.origin&&(l[0]+=O.origin[0],l[1]+=O.origin[1],l[2]+=O.origin[2]),L.worldPos=l,A.transformVec4(V.matrix,m,v),o[0]=v[0],o[1]=v[1],o[2]=v[2],L.viewPos=o,A.cartesianToBarycentric(r,s,n,i,c),L.bary=c;const X=G.normals;if(X){if(G.compressGeometry){const e=3*F,t=3*H,s=3*U;Be.decompressNormal(X.subarray(e,e+2),u),Be.decompressNormal(X.subarray(t,t+2),h),Be.decompressNormal(X.subarray(s,s+2),p)}else u[0]=X[z],u[1]=X[z+1],u[2]=X[z+2],h[0]=X[K],h[1]=X[K+1],h[2]=X[K+2],p[0]=X[Y],p[1]=X[Y+1],p[2]=X[Y+2];const e=A.addVec3(A.addVec3(A.mulVec3Scalar(u,c[0],w),A.mulVec3Scalar(h,c[1],g),T),A.mulVec3Scalar(p,c[2],E),b);L.worldNormal=A.normalizeVec3(A.transformVec3(O.worldNormalMatrix,e,D))}const q=G.uv;if(q){if(d[0]=q[2*F],d[1]=q[2*F+1],f[0]=q[2*H],f[1]=q[2*H+1],I[0]=q[2*U],I[1]=q[2*U+1],G.compressGeometry){const e=G.uvDecodeMatrix;e&&(Be.decompressUV(d,e,d),Be.decompressUV(f,e,f),Be.decompressUV(I,e,I))}L.uv=A.addVec3(A.addVec3(A.mulVec2Scalar(d,c[0],P),A.mulVec2Scalar(f,c[1],R),C),A.mulVec2Scalar(I,c[2],_),B)}}}}}();class gn extends B{get type(){return"Material"}constructor(e,t={}){super(e,t),f.memory.materials++}destroy(){super.destroy(),f.memory.materials--}}const Tn={opaque:0,mask:1,blend:2},En=["opaque","mask","blend"];class bn extends gn{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new ge({type:"PhongMaterial",ambient:A.vec3([1,1,1]),diffuse:A.vec3([1,1,1]),specular:A.vec3([1,1,1]),emissive:A.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=Tn[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return En[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}function Dn(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];let s;switch(t){case"WEBGL_depth_texture":s=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":s=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":s=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=e.getExtension(t)}return e._cachedExtensions[t]=s,s}function Pn(e,t,s=null){let n;const i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===s){const t=Dn(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===i)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(n=Dn(e,"WEBGL_compressed_texture_s3tc"),null===n)return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){const t=Dn(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===i)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){const t=Dn(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){const t=Dn(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===i)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){const t=Dn(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){const t=Dn(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===i)return 3001===s?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}const Rn=new Uint8Array([0,0,0,1]);class Cn{constructor({gl:e,target:t,format:s,type:n,wrapS:i,wrapT:a,wrapR:r,encoding:l,preloadColor:o,premultiplyAlpha:c,flipY:u}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=s||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!u,this.unpackAlignment=4,this.wrapS=i||1e3,this.wrapT=a||1e3,this.wrapR=r||1e3,this.encoding=l||3001,this.texture=e.createTexture(),o&&this.setPreloadColor(o),this.allocated=!0}setPreloadColor(e){e?(Rn[0]=Math.floor(255*e[0]),Rn[1]=Math.floor(255*e[1]),Rn[2]=Math.floor(255*e[2]),Rn[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(Rn[0]=0,Rn[1]=0,Rn[2]=0,Rn[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let s=0,n=e.length;s1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=Pn(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=Pn(s,this.wrapT);if(r&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,r),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=Pn(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}i?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Bn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Bn(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Pn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Pn(s,this.magFilter)));const l=Pn(s,this.format,this.encoding),o=Pn(s,this.type),c=_n(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t>t;return e+1}class xn extends B{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new ge({texture:new Cn({gl:this.scene.canvas.gl}),matrix:A.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),minFilter:this._checkMinFilter(t.minFilter),magFilter:this._checkMagFilter(t.magFilter),wrapS:this._checkWrapS(t.wrapS),wrapT:this._checkWrapT(t.wrapT),flipY:this._checkFlipY(t.flipY),encoding:this._checkEncoding(t.encoding)}),this._src=null,this._image=null,this._translate=A.vec2([0,0]),this._scale=A.vec2([1,1]),this._rotate=A.vec2([0,0]),this._matrixDirty=!1,this.translate=t.translate,this.scale=t.scale,this.rotate=t.rotate,t.src?this.src=t.src:t.image&&(this.image=t.image),f.memory.textures++}_checkMinFilter(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}_checkMagFilter(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}_checkWrapS(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkWrapT(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this._state.texture=new Cn({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}_update(){const e=this._state;if(this._matrixDirty){let t,s;0===this._translate[0]&&0===this._translate[1]||(t=A.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=A.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?A.mulMat4(t,s):s),0!==this._rotate&&(s=A.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?A.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=On(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}get image(){return this._image}set src(e){this.scene.loading++,this.scene.canvas.spinner.processes++;const t=this;let s=new Image;s.onload=function(){s=On(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.src=e,this._src=e,this._image=null}get src(){return this._src}set translate(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}get translate(){return this._translate}set scale(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}get scale(){return this._scale}set rotate(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}get rotate(){return this._rotate}get minFilter(){return this._state.minFilter}get magFilter(){return this._state.magFilter}get wrapS(){return this._state.wrapS}get wrapT(){return this._state.wrapT}get flipY(){return this._state.flipY}get encoding(){return this._state.encoding}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),f.memory.textures--}}const Ln=A.vec3(),Mn=A.vec3();A.vec3();const Fn=A.vec3([0,-1,0]),Hn=A.vec4([0,0,0,1]);class Un extends B{constructor(e,t={}){super(e,t),this._src=null,this._image=null,this._pos=A.vec3(),this._origin=A.vec3(),this._rtcPos=A.vec3(),this._dir=A.vec3(),this._size=1,this._imageSize=A.vec2(),this._texture=new xn(this),this._plane=new vn(this,{geometry:new Ne(this,Qe({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new bn(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0}),clippable:t.clippable}),this._grid=new vn(this,{geometry:new Ne(this,ke({size:1,divisions:10})),material:new bn(this,{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:t.clippable}),this._node=new it(this,{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[this._plane,this._grid]}),this._gridVisible=!1,this.visible=!0,this.gridVisible=t.gridVisible,this.position=t.position,this.rotation=t.rotation,this.dir=t.dir,this.size=t.size,this.collidable=t.collidable,this.clippable=t.clippable,this.pickable=t.pickable,this.opacity=t.opacity,t.image?this.image=t.image:this.src=t.src}set visible(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}get visible(){return this._plane.visible}set gridVisible(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}get gridVisible(){return this._gridVisible}set image(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}get image(){return this._image}set src(e){if(this._src=e,this._src){this._image=null;const e=new Image;e.onload=()=>{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set position(e){this._pos.set(e||[0,0,0]),N(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}get position(){return this._pos}set rotation(e){this._node.rotation=e}get rotation(){return this._node.rotation}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set dir(e){if(this._dir.set(e||[0,0,-1]),e){const t=this.scene.center,s=[-this._dir[0],-this._dir[1],-this._dir[2]];A.subVec3(t,this.position,Ln);const n=-A.dotVec3(s,Ln);A.normalizeVec3(s),A.mulVec3Scalar(s,n,Mn),A.vec3PairToQuaternion(Fn,e,Hn),this._node.quaternion=Hn}}get dir(){return this._dir}set collidable(e){this._node.collidable=!1!==e}get collidable(){return this._node.collidable}set clippable(e){this._node.clippable=!1!==e}get clippable(){return this._node.clippable}set pickable(e){this._node.pickable=!1!==e}get pickable(){return this._node.pickable}set opacity(e){this._node.opacity=e}get opacity(){return this._node.opacity}destroy(){super.destroy()}_updatePlaneSizeFromImage(){const e=this._size,t=this._imageSize[0],s=this._imageSize[1];if(t>s){const n=s/t;this._node.scale=[e,1,e*n]}else{const n=t/s;this._node.scale=[e*n,1,e]}}}class Gn extends gn{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new ge({type:"LambertMaterial",ambient:A.vec3([1,1,1]),color:A.vec3([1,1,1]),emissive:A.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),this.ambient=t.ambient,this.color=t.color,this.emissive=t.emissive,this.alpha=t.alpha,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this.backfaces=t.backfaces,this.frontface=t.frontface}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set color(e){let t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get color(){return this._state.color}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}get alpha(){return this._state.alpha}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}const jn={opaque:0,mask:1,blend:2},Vn=["opaque","mask","blend"];class kn extends gn{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new ge({type:"MetallicMaterial",baseColor:A.vec4([1,1,1]),emissive:A.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.baseColor=t.baseColor,this.metallic=t.metallic,this.roughness=t.roughness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.baseColorMap&&(this._baseColorMap=this._checkComponent("Texture",t.baseColorMap)),t.metallicMap&&(this._metallicMap=this._checkComponent("Texture",t.metallicMap)),t.roughnessMap&&(this._roughnessMap=this._checkComponent("Texture",t.roughnessMap)),t.metallicRoughnessMap&&(this._metallicRoughnessMap=this._checkComponent("Texture",t.metallicRoughnessMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set baseColor(e){let t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get baseColor(){return this._state.baseColor}get baseColorMap(){return this._baseColorMap}set metallic(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}get metallic(){return this._state.metallic}get metallicMap(){return this._attached.metallicMap}set roughness(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}get roughness(){return this._state.roughness}get roughnessMap(){return this._attached.roughnessMap}get metallicRoughnessMap(){return this._attached.metallicRoughnessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._attached.emissiveMap}get occlusionMap(){return this._attached.occlusionMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._attached.alphaMap}get normalMap(){return this._attached.normalMap}set alphaMode(e){let t=jn[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Vn[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const Qn={opaque:0,mask:1,blend:2},Wn=["opaque","mask","blend"];class zn extends gn{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new ge({type:"SpecularMaterial",diffuse:A.vec3([1,1,1]),emissive:A.vec3([0,0,0]),specular:A.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.diffuse=t.diffuse,this.specular=t.specular,this.glossiness=t.glossiness,this.specularF0=t.specularF0,this.emissive=t.emissive,this.alpha=t.alpha,t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.glossinessMap&&(this._glossinessMap=this._checkComponent("Texture",t.glossinessMap)),t.specularGlossinessMap&&(this._specularGlossinessMap=this._checkComponent("Texture",t.specularGlossinessMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,this._makeHash()}_makeHash(){const e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}get diffuseMap(){return this._diffuseMap}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}get specularMap(){return this._specularMap}get specularGlossinessMap(){return this._specularGlossinessMap}set glossiness(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}get glossiness(){return this._state.glossiness}get glossinessMap(){return this._glossinessMap}set specularF0(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}get specularF0(){return this._state.specularF0}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}get emissiveMap(){return this._emissiveMap}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}get alphaMap(){return this._alphaMap}get normalMap(){return this._normalMap}get occlusionMap(){return this._occlusionMap}set alphaMode(e){let t=Qn[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Wn[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}destroy(){super.destroy(),this._state.destroy()}}const Kn={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class Yn extends gn{get type(){return"EmphasisMaterial"}get presets(){return Kn}constructor(e,t={}){super(e,t),this._state=new ge({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(e=e||"default",this._preset===e)return;const t=Kn[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Kn).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Xn={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class qn extends gn{get type(){return"EdgeMaterial"}get presets(){return Xn}constructor(e,t={}){super(e,t),this._state=new ge({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Xn[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Xn).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class Jn extends B{get type(){return"Fresnel"}constructor(e,t={}){super(e,t),this._state=new ge({edgeColor:A.vec3([0,0,0]),centerColor:A.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),this.edgeColor=t.edgeColor,this.centerColor=t.centerColor,this.edgeBias=t.edgeBias,this.centerBias=t.centerBias,this.power=t.power}set edgeColor(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set centerColor(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}get centerColor(){return this._state.centerColor}set edgeBias(e){this._state.edgeBias=e||0,this.glRedraw()}get edgeBias(){return this._state.edgeBias}set centerBias(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}get centerBias(){return this._state.centerBias}set power(e){this._state.power=null!=e?e:1,this.glRedraw()}get power(){return this._state.power}destroy(){super.destroy(),this._state.destroy()}}class Zn extends B{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=A.vec3(t.pos||[0,0,0]),this._up=A.vec3(t.up||[0,1,0]),this._normal=A.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=A.vec3(),this._rtcPos=A.vec3(),this._imageSize=A.vec2(),this._texture=new xn(this),this._image=new Image,"jpg"!==this._type&&"png"!==this._type&&(this.error('Unsupported type - defaulting to "jpg"'),this._type="jpg"),this._node=new it(this,{matrix:A.inverseMat4(A.lookAtMat4v(this._pos,A.subVec3(this._pos,this._normal,A.mat4()),this._up,A.mat4())),children:[this._bitmapMesh=new vn(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new Ne(this,Qe({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new bn(this,{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:this._texture,emissiveMap:this._texture,backfaces:!0})})]}),t.image?this.image=t.image:t.src?this.src=t.src:t.imageData&&(this.imageData=t.imageData),this.scene._bitmapCreated(this)}set visible(e){this._bitmapMesh.visible=e}get visible(){return this._bitmapMesh.visible}set image(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}get image(){return this._image}set src(e){if(e){this._image.onload=()=>{this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale()},this._image.src=e;switch(e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}}get src(){return this._image.src}set imageData(e){this._image.onload=()=>{this._texture.image=image,this._imageSize[0]=image.width,this._imageSize[1]=image.height,this._updateBitmapMeshScale()},this._image.src=e}get imageData(){const e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")}set type(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}get type(){return this._type}get pos(){return this._pos}get normal(){return this._normal}get up(){return this._up}set height(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}get height(){return this._height}set collidable(e){this._bitmapMesh.collidable=!1!==e}get collidable(){return this._bitmapMesh.collidable}set clippable(e){this._bitmapMesh.clippable=!1!==e}get clippable(){return this._bitmapMesh.clippable}set pickable(e){this._bitmapMesh.pickable=!1!==e}get pickable(){return this._bitmapMesh.pickable}set opacity(e){this._bitmapMesh.opacity=e}get opacity(){return this._bitmapMesh.opacity}destroy(){super.destroy(),this.scene._bitmapDestroyed(this)}_updateBitmapMeshScale(){const e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}class $n extends B{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],this._origin=A.vec3(t.origin||[0,0,0]),t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=n.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new ge({type:"dir",dir:A.vec3([1,1,1]),color:A.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=A.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,n=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],i=[0,1,0];A.lookAtMat4v(n,s,i,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=A.identityMat4()),A.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new si(this.scene.canvas.canvas,this.scene.canvas.gl,{size:[1024,1024]})),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}class ii extends ei{get type(){return"PointLight"}constructor(e,t={}){super(e,t);const s=this;this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const n=this.scene.camera,i=this.scene.canvas;this._onCameraViewMatrix=n.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=n.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=i.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new ge({type:"point",pos:A.vec3([1,1,1]),color:A.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=A.identityMat4());const e=s._state.pos,t=n.look,i=n.up;A.lookAtMat4v(e,t,i,s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:()=>{if(s._shadowProjMatrixDirty){s._shadowProjMatrix||(s._shadowProjMatrix=A.identityMat4());const e=s.scene.canvas.canvas;A.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1}return s._shadowProjMatrix},getShadowRenderBuf:()=>(s._shadowRenderBuf||(s._shadowRenderBuf=new si(s.scene.canvas.canvas,s.scene.canvas.gl,{size:[1024,1024]})),s._shadowRenderBuf)}),this.pos=t.pos,this.color=t.color,this.intensity=t.intensity,this.constantAttenuation=t.constantAttenuation,this.linearAttenuation=t.linearAttenuation,this.quadraticAttenuation=t.quadraticAttenuation,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set pos(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get pos(){return this._state.pos}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set constantAttenuation(e){this._state.attenuation[0]=e||0,this.glRedraw()}get constantAttenuation(){return this._state.attenuation[0]}set linearAttenuation(e){this._state.attenuation[1]=e||0,this.glRedraw()}get linearAttenuation(){return this._state.attenuation[1]}set quadraticAttenuation(e){this._state.attenuation[2]=e||0,this.glRedraw()}get quadraticAttenuation(){return this._state.attenuation[2]}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function ai(e){if(!ri(e.width)||!ri(e.height)){const t=document.createElement("canvas");t.width=li(e.width),t.height=li(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function ri(e){return 0==(e&e-1)}function li(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class oi extends B{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new ge({texture:new Cn({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),f.memory.textures++}_checkFlipY(e){return!!e}_checkEncoding(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}_webglContextRestored(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let n=!1,i=0;for(let a=0;a{this._texture.image=e,this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage()},e.src=this._src}}get src(){return this._src}set size(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}get size(){return this._size}set collidable(e){this._mesh.collidable=!1!==e}get collidable(){return this._mesh.collidable}set clippable(e){this._mesh.clippable=!1!==e}get clippable(){return this._mesh.clippable}set pickable(e){this._mesh.pickable=!1!==e}get pickable(){return this._mesh.pickable}set opacity(e){this._mesh.opacity=e}get opacity(){return this._mesh.opacity}_updatePlaneSizeFromImage(){const e=.5*this._size,t=this._imageSize[0],s=this._imageSize[1],n=s/t;this._geometry.positions=t>s?[e,e*n,0,-e,e*n,0,-e,-e*n,0,e,-e*n,0]:[e/n,e,0,-e/n,e,0,-e/n,-e,0,e/n,-e,0]}}const pi=A.vec3(),Ai=A.vec3(),di=A.mat4();class fi{constructor(){this.normal=A.vec3(),this.offset=0,this.testVertex=A.vec3()}set(e,t,s,n){const i=1/Math.sqrt(e*e+t*t+s*s);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=s*i,this.offset=n*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class Ii{constructor(){this.planes=[new fi,new fi,new fi,new fi,new fi,new fi]}}function yi(e,t,s){const n=A.mulMat4(s,t,di),i=n[0],a=n[1],r=n[2],l=n[3],o=n[4],c=n[5],u=n[6],h=n[7],p=n[8],d=n[9],f=n[10],I=n[11],y=n[12],m=n[13],v=n[14],w=n[15];e.planes[0].set(l-i,h-o,I-p,w-y),e.planes[1].set(l+i,h+o,I+p,w+y),e.planes[2].set(l-a,h-c,I-d,w-m),e.planes[3].set(l+a,h+c,I+d,w+m),e.planes[4].set(l-r,h-u,I-f,w-v),e.planes[5].set(l+r,h+u,I+f,w+v)}function mi(e,t){let s=Ii.INSIDE;const n=pi,i=Ai;n[0]=t[0],n[1]=t[1],n[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];const a=[n,i];for(let t=0;t<6;++t){const n=e.planes[t];if(n.normal[0]*a[n.testVertex[0]][0]+n.normal[1]*a[n.testVertex[1]][1]+n.normal[2]*a[n.testVertex[2]][2]+n.offset<0)return Ii.OUTSIDE;n.normal[0]*a[1-n.testVertex[0]][0]+n.normal[1]*a[1-n.testVertex[1]][1]+n.normal[2]*a[1-n.testVertex[2]][2]+n.offset<0&&(s=Ii.INTERSECT)}return s}Ii.INSIDE=0,Ii.INTERSECT=1,Ii.OUTSIDE=2;class vi{constructor(e){this._eye=A.vec3(),this._look=A.vec3(),this._up=A.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,s=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,n=this._projection;function i(){switch(n.type){case"perspective":s.perspective.fov=n.fov,s.perspective.fovAxis=n.fovAxis,s.perspective.near=n.near,s.perspective.far=n.far;break;case"ortho":s.ortho.scale=n.scale,s.ortho.near=n.near,s.ortho.far=n.far;break;case"frustum":s.frustum.left=n.left,s.frustum.right=n.right,s.frustum.top=n.top,s.frustum.bottom=n.bottom,s.frustum.near=n.near,s.frustum.far=n.far;break;case"custom":s.customProjection.matrix=n.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:n.scale,projection:n.projection},(()=>{i(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,i(),s.projection=n.projection)}}const wi=A.vec3();class gi{constructor(e){if(this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,e){const t=e.metaScene.scene;this.saveObjects(t,e)}}saveObjects(e,t,s){this.numObjects=0,this._mask=s?v.apply(s,{}):null;const n=!s||s.visible,i=!s||s.edges,a=!s||s.xrayed,r=!s||s.highlighted,l=!s||s.selected,o=!s||s.clippable,c=!s||s.pickable,u=!s||s.colorize,h=!s||s.opacity,p=t.metaObjects,A=e.objects;for(let e=0,t=p.length;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=A.vec3();return t[0]=A.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=A.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=A.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}class Di extends oe{constructor(e,t={}){super(e,t),this._cachedLengths=[],this._dirty=!0,this._curves=[],this._t=0,this._dirtySubs=[],this._destroyedSubs=[],this.curves=t.curves||[],this.t=t.t}addCurve(e){this._curves.push(e),this._dirty=!0}set curves(e){var t,s,n;for(e=e||[],s=0,n=this._curves.length;s1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}get length(){var e=this._getCurveLengths();return e[e.length-1]}getPoint(e){for(var t,s=e*this.length,n=this._getCurveLengths(),i=0;i=s){var a=1-(n[i]-s)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}_getCurveLengths(){if(!this._dirty)return this._cachedLengths;var e,t=[],s=0,n=this._curves.length;for(e=0;e1?1:e}get t(){return this._t}get point(){return this.getPoint(this._t)}getPoint(e){var t=A.vec3();return t[0]=A.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=A.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=A.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}getJSON(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}class Ri{constructor(e,t,s,n,i=null,a=0){this.model=e,this.object=null,this.parent=null,this.id=t,this._aabb=null,this.layer=i,this.portionId=a,this._color=[s[0],s[1],s[2],n],this._colorize=[s[0],s[1],s[2],n],this._colorizing=!1,this._transparent=n<255,this.numTriangles=0,this.origin=null}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const s=e<255,n=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),n&&this.layer.setTransparent(this.portionId,t,s)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,s,n){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,s,n)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex(this.portionId,e)}set aabb(e){this._aabb=e}get aabb(){return this._aabb}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const Ci=new class{constructor(){this._uint8Arrays={},this._float32Arrays={}}_clear(){this._uint8Arrays={},this._float32Arrays={}}getUInt8Array(e){let t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}getFloat32Array(e){let t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}};let _i=0;const Bi={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},Oi=new Float32Array([1,1,1,1]),Si=new Float32Array([0,0,0,1]),Ni=A.vec4(),xi=A.vec3(),Li=A.vec3(),Mi=A.mat4();class Fi{constructor(e,t=!1,{instancing:s=!1,edges:n=!1}={}){this._scene=e,this._withSAO=t,this._instancing=s,this._edges=n,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}_getHash(){return this._scene._sectionPlanesState.getHash()}_buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}_buildVertexShader(){return[""]}_buildFragmentShader(){return[""]}_addMatricesUniformBlockLines(e,t=!1){return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}_addRemapClipPosLines(e){return e.push("uniform vec2 pickClipPos;"),e.push("vec4 remapClipPos(vec4 clipPos) {"),e.push(" clipPos.xy /= clipPos.w;"),e.push(" clipPos.xy -= pickClipPos;"),e.push(" clipPos.xy *= clipPos.w;"),e.push(" return clipPos;"),e.push("}"),e}getValid(){return this._hash===this._getHash()}setSectionPlanesStateUniforms(e){const t=this._scene,{gl:s}=t.canvas,{model:n,layerIndex:i}=e,a=t._sectionPlanesState.sectionPlanes.length;if(a>0){const r=t._sectionPlanesState.sectionPlanes,l=i*a,o=n.renderFlags;for(let t=0;t0&&(this._uReflectionMap="reflectionMap"),s.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(let t=0,s=e._sectionPlanesState.sectionPlanes.length;t0&&d.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,d.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),d.lightMaps.length>0&&d.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,d.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),this._withSAO){const t=r.sao;if(t.possible){const s=l.drawingBufferWidth,n=l.drawingBufferHeight;Ni[0]=s,Ni[1]=n,Ni[2]=t.blendCutoff,Ni[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,Ni),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++}}if(n){const e=this._edges?"edgeColor":"fillColor",t=this._edges?"edgeAlpha":"fillAlpha";if(s===Bi[(this._edges?"EDGES":"SILHOUETTE")+"_XRAYED"]){const s=r.xrayMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===Bi[(this._edges?"EDGES":"SILHOUETTE")+"_HIGHLIGHTED"]){const s=r.highlightMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===Bi[(this._edges?"EDGES":"SILHOUETTE")+"_SELECTED"]){const s=r.selectedMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else l.uniform4fv(this._uColor,this._edges?Si:Oi)}this._draw({state:o,frameCtx:e,incrementDrawState:i}),l.bindVertexArray(null)}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null,f.memory.programs--}}class Hi extends Fi{constructor(e,t,{instancing:s=!1,edges:n=!1}={}){super(e,t,{instancing:s,edges:n})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;if(this._edges)t.drawElements(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0);else{const e=n.pickElementsCount||s.indicesBuf.numItems,a=n.pickElementsOffset?n.pickElementsOffset*s.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,e,s.indicesBuf.itemType,a),i&&n.drawElements++}}}class Ui extends Hi{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class Gi extends Fi{constructor(e,t,{edges:s=!1}={}){super(e,t,{instancing:!0,edges:s})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;this._edges?t.drawElementsInstanced(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances):(t.drawElementsInstanced(t.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++)}}class ji extends Gi{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class Vi extends Fi{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArrays(t.POINTS,0,s.positionsBuf.numItems),i&&n.drawArrays++}}class ki extends Fi{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArraysInstanced(t.POINTS,0,s.positionsBuf.numItems,s.numInstances),i&&n.drawArrays++}}class Qi extends Fi{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElements(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0),i&&n.drawElements++}}class Wi extends Fi{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElementsInstanced(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++}}class zi extends Hi{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i;const a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class Ki extends Hi{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching flat-shading draw vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._lightsState,s=e._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),n){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,s=t.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}class Xi extends Ui{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class qi extends Ui{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Ji extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),this._addRemapClipPosLines(s),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class Zi extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),this._addRemapClipPosLines(s),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class $i extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec3 worldNormal = octDecode(normal.xy); "),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}}class ea extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles batching occlusion fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}class ta extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching depth fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}class sa extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class na extends Hi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry shadow vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push(" int colorFlag = int(flags) & 0xF;"),s.push(" bool visible = (colorFlag > 0);"),s.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push(" if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry shadow fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = encodeFloat( gl_FragCoord.z); "),s.push("}"),s}}class ia extends Hi{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Triangles batching quality draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),r.push("uniform sampler2D uAOMap;"),r.push("in vec4 vViewPosition;"),r.push("in vec3 vViewNormal;"),r.push("in vec4 vColor;"),r.push("in vec2 vUV;"),r.push("in vec2 vMetallicRoughness;"),n.lightMaps.length>0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick flat normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out float vFlags;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags = flags;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick flat normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}}class ra extends Hi{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching color texture vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._lightsState,n=e._sectionPlanesState,i=n.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(let e=0,t=n.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(let e=0,t=n.sectionPlanes.length;e 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,t=s.lights.length;e5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]}}const ua=A.mat4(),ha=A.mat4();function pa(e,t,s){const n=e.length,i=new Uint16Array(n),a=t[0],r=t[1],l=t[2],o=t[3]-a,c=t[4]-r,u=t[5]-l,h=65525,p=h/o,d=h/c,f=h/u,I=e=>e>=0?e:0;for(let t=0;t=0?1:-1),t=(1-Math.abs(n))*(i>=0?1:-1),n=e,i=t}return new Int8Array([Math[t](127.5*n+(n<0?-1:0)),Math[s](127.5*i+(i<0?-1:0))])}function fa(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}const Ia=A.vec3(),ya=A.vec3(),ma=A.vec3(),va=A.vec3(),wa=A.mat4();class ga extends Fi{drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:h}=n,p=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Ia;let I,y;if(f[0]=A.safeInv(p[3]-p[0])*A.MAX_INT,f[1]=A.safeInv(p[4]-p[1])*A.MAX_INT,f[2]=A.safeInv(p[5]-p[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(f[0]),e.snapPickCoordinateScale[1]=A.safeInv(f[1]),e.snapPickCoordinateScale[2]=A.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=ya;if(o){const e=ma;A.transformPoint3(u,o,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=S(d,t,wa),y=va,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(h,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),l.indicesBuf.bind(),r.drawElements(r.TRIANGLES,l.indicesBuf.numItems,l.indicesBuf.itemType,0),l.indicesBuf.unbind()}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Ta=A.vec3(),Ea=A.vec3(),ba=A.vec3(),Da=A.vec3(),Pa=A.mat4();class Ra extends Fi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:h}=n,p=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=Ta;let I,y;if(f[0]=A.safeInv(p[3]-p[0])*A.MAX_INT,f[1]=A.safeInv(p[4]-p[1])*A.MAX_INT,f[2]=A.safeInv(p[5]-p[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(f[0]),e.snapPickCoordinateScale[1]=A.safeInv(f[1]),e.snapPickCoordinateScale[2]=A.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=Ea;if(o){const e=ba;A.transformPoint3(u,o,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=S(d,t,Pa),y=Da,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(h,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(l.edgeIndicesBuf.bind(),r.drawElements(r.LINES,l.edgeIndicesBuf.numItems,l.edgeIndicesBuf.itemType,0),l.edgeIndicesBuf.unbind()):r.drawArrays(r.POINTS,0,l.positionsBuf.numItems)}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0;e.pointsMaterial._state;const s=[];return s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class Ca{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new ga(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Ra(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const _a={};const Ba=A.mat4(),Oa=A.mat4(),Sa=A.vec4([0,0,0,1]),Na=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]),A.OBB3();const xa=A.vec3(),La=A.vec3(),Ma=A.vec3(),Fa=A.vec3(),Ha=A.vec3(),Ua=A.vec3(),Ga=A.vec3();class ja{constructor(e){console.info("Creating TrianglesBatchingLayer"),this.model=e.model,this.sortId="TrianglesBatchingLayer"+(e.solid?"-solid":"-surface")+(e.autoNormals?"-autonormals":"-normals")+(e.textureSet&&e.textureSet.colorTexture?"-colorTexture":"")+(e.textureSet&&e.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=oa[t];return s||(s=new la(e),oa[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete oa[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=_a[t];return s||(s=new Ca(e),_a[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete _a[t],s._destroy()}))),s}(e.model.scene),this._buffer=new ca(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ge({origin:A.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:e.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=A.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=A.mat4(e.positionsDecodeMatrix)),e.uvDecodeMatrix?(this._state.uvDecodeMatrix=A.mat3(e.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,e.origin&&this._state.origin.set(e.origin),this.aabb=A.collapseAABB3(),this.solid=!!e.solid}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(let e=0,t=i.length;e0){const e=Ba;I?A.inverseMat4(A.transposeMat4(I,Oa),e):A.identityMat4(e,e),function(e,t,s,n,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let r,l,o,c,u,h,p=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(h=0;hu&&(o=r,u=c),r=da(d,"floor","ceil"),l=fa(r),c=a(d,l),c>u&&(o=r,u=c),r=da(d,"ceil","ceil"),l=fa(r),c=a(d,l),c>u&&(o=r,u=c),n[i+h+0]=o[0],n[i+h+1]=o[1],n[i+h+2]=0}(e,n,n.length,w.normals,w.normals.length)}if(l)for(let e=0,t=l.length;e0)for(let e=0,t=a.length;e0)for(let e=0,t=r.length;e0){const n=this._state.positionsDecodeMatrix?new Uint16Array(s.positions):pa(s.positions,this._modelAABB,this._state.positionsDecodeMatrix=A.mat4());if(e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(let e=0,t=this._portions.length;e0){const n=new Int8Array(s.normals);let i=!0;e.normalsBuf=new Te(t,t.ARRAY_BUFFER,n,s.normals.length,3,t.STATIC_DRAW,i)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.uv.length>0)if(e.uvDecodeMatrix){let n=!1;e.uvBuf=new Te(t,t.ARRAY_BUFFER,s.uv,s.uv.length,2,t.STATIC_DRAW,n)}else{const n=Be.getUVBounds(s.uv),i=Be.compressUVs(s.uv,n.min,n.max),a=i.quantized;let r=!1;e.uvDecodeMatrix=A.mat3(i.decodeMatrix),e.uvBuf=new Te(t,t.ARRAY_BUFFER,a,a.length,2,t.STATIC_DRAW,r)}if(s.metallicRoughness.length>0){const n=new Uint8Array(s.metallicRoughness);let i=!1;e.metallicRoughnessBuf=new Te(t,t.ARRAY_BUFFER,n,s.metallicRoughness.length,2,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n),a=!1;e.flagsBuf=new Te(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new Te(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}if(s.edgeIndices.length>0){const n=new Uint32Array(s.edgeIndices);e.edgeIndicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,n,s.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}isEmpty(){return!this._state.indicesBuf}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=e,n=this._portions[s],i=4*n.vertsBaseIndex,a=4*n.numVerts,r=this._scratchMemory.getUInt8Array(a),l=t[0],o=t[1],c=t[2],u=t[3];for(let e=0;em)&&(m=e,n.set(v),i&&A.triangleNormal(d,f,I,i),y=!0)}}return y&&i&&(A.transformVec3(this.model.worldNormalMatrix,i,i),A.normalizeVec3(i)),y}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}class Va extends Gi{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i,a,r;const l=[];for(l.push("#version 300 es"),l.push("// Instancing geometry drawing vertex shader"),l.push("uniform int renderPass;"),l.push("in vec3 position;"),l.push("in vec2 normal;"),l.push("in vec4 color;"),l.push("in float flags;"),e.entityOffsetsEnabled&&l.push("in vec3 offset;"),l.push("in vec4 modelMatrixCol0;"),l.push("in vec4 modelMatrixCol1;"),l.push("in vec4 modelMatrixCol2;"),l.push("in vec4 modelNormalMatrixCol0;"),l.push("in vec4 modelNormalMatrixCol1;"),l.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(l,!0),e.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;")),l.push("uniform vec4 lightAmbient;"),i=0,a=s.lights.length;i= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"),n&&(l.push("out vec4 vWorldPosition;"),l.push("out float vFlags;")),l.push("out vec4 vColor;"),l.push("void main(void) {"),l.push("int colorFlag = int(flags) & 0xF;"),l.push("if (colorFlag != renderPass) {"),l.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),l.push("} else {"),l.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),l.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix * worldPosition; "),l.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),l.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),l.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),i=0,a=s.lights.length;i0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class ka extends Gi{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState;let n,i;const a=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry flat-shading drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),a){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}for(r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),n=0,i=s.lights.length;n0,s=[];return s.push("#version 300 es"),s.push("// Instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing fill fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Wa extends ji{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class za extends ji{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class Ka extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class Ya extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Xa extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec2 normal;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("in vec4 modelNormalMatrixCol0;"),s.push("in vec4 modelNormalMatrixCol1;"),s.push("in vec4 modelNormalMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}}class qa extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// TrianglesInstancingOcclusionRenderer vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesInstancingOcclusionRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}}class Ja extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}class Za extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class $a extends Gi{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}const er={3e3:"linearToLinear",3001:"sRGBToLinear"};class tr extends Gi{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Instancing geometry quality drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),r.push("#define PI 3.14159265359"),r.push("#define RECIPROCAL_PI 0.31830988618"),r.push("#define RECIPROCAL_PI2 0.15915494"),r.push("#define EPSILON 1e-6"),r.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),r.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),r.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),r.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),r.push(" return normalize(surf_norm );"),r.push(" }"),r.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),r.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),r.push(" vec2 st0 = dFdx( uv.st );"),r.push(" vec2 st1 = dFdy( uv.st );"),r.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),r.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),r.push(" vec3 N = normalize( surf_norm );"),r.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),r.push(" mat3 tsn = mat3( S, T, N );"),r.push(" return normalize( tsn * mapN );"),r.push("}"),r.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),r.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),r.push("}"),r.push("struct IncidentLight {"),r.push(" vec3 color;"),r.push(" vec3 direction;"),r.push("};"),r.push("struct ReflectedLight {"),r.push(" vec3 diffuse;"),r.push(" vec3 specular;"),r.push("};"),r.push("struct Geometry {"),r.push(" vec3 position;"),r.push(" vec3 viewNormal;"),r.push(" vec3 worldNormal;"),r.push(" vec3 viewEyeDir;"),r.push("};"),r.push("struct Material {"),r.push(" vec3 diffuseColor;"),r.push(" float specularRoughness;"),r.push(" vec3 specularColor;"),r.push(" float shine;"),r.push("};"),r.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),r.push(" float r = ggxRoughness + 0.0001;"),r.push(" return (2.0 / (r * r) - 2.0);"),r.push("}"),r.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),r.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),r.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),r.push("}"),n.reflectionMaps.length>0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = "+er[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = "+er[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),this._addRemapClipPosLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&s.push("out float vFlags;"),s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&s.push("vFlags = flags;"),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}}class nr extends Gi{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState;let i,a;const r=s.sectionPlanes.length>0,l=[];if(l.push("#version 300 es"),l.push("// Instancing geometry drawing fragment shader"),l.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),l.push("precision highp float;"),l.push("precision highp int;"),l.push("#else"),l.push("precision mediump float;"),l.push("precision mediump int;"),l.push("#endif"),e.logarithmicDepthBufferEnabled&&(l.push("in float isPerspective;"),l.push("uniform float logDepthBufFC;"),l.push("in float vFragDepth;")),l.push("uniform sampler2D uColorMap;"),this._withSAO&&(l.push("uniform sampler2D uOcclusionTexture;"),l.push("uniform vec4 uSAOParams;"),l.push("const float packUpscale = 256. / 255.;"),l.push("const float unpackDownScale = 255. / 256.;"),l.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),l.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),l.push("float unpackRGBToFloat( const in vec4 v ) {"),l.push(" return dot( v, unPackFactors );"),l.push("}")),l.push("uniform float gammaFactor;"),l.push("vec4 linearToLinear( in vec4 value ) {"),l.push(" return value;"),l.push("}"),l.push("vec4 sRGBToLinear( in vec4 value ) {"),l.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),l.push("}"),l.push("vec4 gammaToLinear( in vec4 value) {"),l.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),l.push("}"),t&&(l.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),l.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),l.push("}")),r){l.push("in vec4 vWorldPosition;"),l.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),l.push(" if (clippable) {"),l.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),l.push(" discard;"),l.push(" }"),l.push("}")}for(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),l.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),l.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),l.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),i=0,a=n.lights.length;i0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Points instancing pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const pr=A.vec3(),Ar=A.vec3(),dr=A.vec3(),fr=A.vec3(),Ir=A.mat4();class yr extends Fi{constructor(e){super(e,!1,{instancing:!0})}drawLayer(e,t,s){if(!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:h}=n,p=t.aabb,d=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?r.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(l));const f=pr;let I,y;if(f[0]=A.safeInv(p[3]-p[0])*A.MAX_INT,f[1]=A.safeInv(p[4]-p[1])*A.MAX_INT,f[2]=A.safeInv(p[5]-p[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(f[0]),e.snapPickCoordinateScale[1]=A.safeInv(f[1]),e.snapPickCoordinateScale[2]=A.safeInv(f[2]),o||0!==c[0]||0!==c[1]||0!==c[2]){const t=Ar;if(o){const e=A.transformPoint3(u,o,dr);t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=c[0],t[1]+=c[1],t[2]+=c[2],I=S(d,t,Ir),y=fr,y[0]=a.eye[0]-t[0],y[1]=a.eye[1]-t[1],y[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else I=d,y=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,y),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,f),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);let m=0;this._matricesUniformBlockBufferData.set(h,0),this._matricesUniformBlockBufferData.set(I,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(l.positionsDecodeMatrix,m+=16),r.bindBuffer(r.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),r.bufferData(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,r.DYNAMIC_DRAW),r.bindBufferBase(r.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(l.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(l.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(l.modelMatrixCol2Buf),r.vertexAttribDivisor(this._aModelMatrixCol0.location,1),r.vertexAttribDivisor(this._aModelMatrixCol1.location,1),r.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(l.flagsBuf),r.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(l.edgeIndicesBuf.bind(),r.drawElementsInstanced(r.LINES,l.edgeIndicesBuf.numItems,l.edgeIndicesBuf.itemType,0,l.numInstances),l.edgeIndicesBuf.unbind()):r.drawArraysInstanced(r.POINTS,0,l.positionsBuf.numItems,l.numInstances),r.vertexAttribDivisor(this._aModelMatrixCol0.location,0),r.vertexAttribDivisor(this._aModelMatrixCol1.location,0),r.vertexAttribDivisor(this._aModelMatrixCol2.location,0),r.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&r.vertexAttribDivisor(this._aOffset.location,0)}_allocate(){super._allocate();const e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}_bindProgram(){this._program.bind()}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// SnapInstancingDepthRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int layerNumber;"),s.push("uniform vec3 coordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push("}")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class mr{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new hr(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new yr(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const vr={};const wr=new Uint8Array(4),gr=new Float32Array(1),Tr=A.vec4([0,0,0,1]),Er=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]);const br=new Float32Array(3),Dr=A.vec3(),Pr=A.vec3(),Rr=A.vec3(),Cr=A.vec3(),_r=A.vec3(),Br=A.vec3(),Or=A.vec3();class Sr{constructor(e){console.info("Creating TrianglesInstancingLayer"),this.model=e.model,this.sortId="TrianglesInstancingLayer"+(e.solid?"-solid":"-surface")+(e.normals?"-normals":"-autoNormals"),this.layerIndex=e.layerIndex,this._instancingRenderers=function(e){const t=e.id;let s=ar[t];return s||(s=new ir(e),ar[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete ar[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=vr[t];return s||(s=new mr(e),vr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete vr[t],s._destroy()}))),s}(e.model.scene),this._aabb=A.collapseAABB3(),this._state=new ge({numInstances:0,obb:A.OBB3(),origin:A.vec3(),geometry:e.geometry,textureSet:e.textureSet,pbrSupported:!1,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],e.origin&&this._state.origin.set(e.origin),this._finalized=!1,this.aabb=A.collapseAABB3(),this.solid=!!e.solid,this.numIndices=e.geometry.numIndices}createPortion(e){const t=e.color,s=e.metallic,n=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,r=e.aabb,l=e.pickColor;if(this._finalized)throw"Already finalized";const o=t[0],c=t[1],u=t[2];if(this._colors.push(o),this._colors.push(c),this._colors.push(u),this._colors.push(i),this._metallicRoughness.push(null!=s?s:0),this._metallicRoughness.push(null!=n?n:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){let e=A.transposeMat4(a,A.mat4()),t=A.inverseMat4(e);this._modelNormalMatrixCol0.push(t[0]),this._modelNormalMatrixCol0.push(t[4]),this._modelNormalMatrixCol0.push(t[8]),this._modelNormalMatrixCol0.push(t[12]),this._modelNormalMatrixCol1.push(t[1]),this._modelNormalMatrixCol1.push(t[5]),this._modelNormalMatrixCol1.push(t[9]),this._modelNormalMatrixCol1.push(t[13]),this._modelNormalMatrixCol2.push(t[2]),this._modelNormalMatrixCol2.push(t[6]),this._modelNormalMatrixCol2.push(t[10]),this._modelNormalMatrixCol2.push(t[14])}this._pickColors.push(l[0]),this._pickColors.push(l[1]),this._pickColors.push(l[2]),this._pickColors.push(l[3]);const h=this._state.geometry.positionsCompressed.length,p=this._state.geometry.positionsCompressed,d=this._state.geometry.positionsDecodeMatrix;for(let e=0;e0){let t=!1;e.colorsBuf=new Te(n,n.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,n.DYNAMIC_DRAW,t),this._colors=[]}if(this._metallicRoughness.length>0){const t=new Uint8Array(this._metallicRoughness);let s=!1;e.metallicRoughnessBuf=new Te(n,n.ARRAY_BUFFER,t,this._metallicRoughness.length,2,n.STATIC_DRAW,s)}if(a>0){let t=!1;e.flagsBuf=new Te(n,n.ARRAY_BUFFER,new Float32Array(a),a,1,n.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;e.offsetsBuf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,n.DYNAMIC_DRAW,t),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){const s=!1;e.positionsBuf=new Te(n,n.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,n.STATIC_DRAW,s),e.positionsDecodeMatrix=A.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){const s=new Uint8Array(t.colorsCompressed),i=!1;e.colorsBuf=new Te(n,n.ARRAY_BUFFER,s,s.length,4,n.STATIC_DRAW,i)}if(t.uvCompressed&&t.uvCompressed.length>0){const s=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new Te(n,n.ARRAY_BUFFER,s,s.length,2,n.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new Te(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,n.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new Te(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,n.STATIC_DRAW)),this._modelMatrixCol0.length>0){const t=!1;e.modelMatrixCol0Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelMatrixCol1Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelMatrixCol2Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol1Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol2Buf=new Te(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){const t=!1;e.pickColorsBuf=new Te(n,n.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,n.STATIC_DRAW,t),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&s&&s.colorTexture&&s.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!s&&!!s.colorTexture,this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";wr[0]=t[0],wr[1]=t[1],wr[2]=t[2],wr[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(wr,4*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&F),i=!!(t&V),a=!!(t&k),r=!!(t&Q),l=!!(t&W),o=!!(t&U),c=!!(t&H);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Bi.NOT_RENDERED:s?Bi.COLOR_TRANSPARENT:Bi.COLOR_OPAQUE,h=!n||c?Bi.NOT_RENDERED:r?Bi.SILHOUETTE_SELECTED:a?Bi.SILHOUETTE_HIGHLIGHTED:i?Bi.SILHOUETTE_XRAYED:Bi.NOT_RENDERED;let p=0;p=!n||c?Bi.NOT_RENDERED:r?Bi.EDGES_SELECTED:a?Bi.EDGES_HIGHLIGHTED:i?Bi.EDGES_XRAYED:l?s?Bi.EDGES_COLOR_TRANSPARENT:Bi.EDGES_COLOR_OPAQUE:Bi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Bi.PICK:Bi.NOT_RENDERED)<<12,A|=(t&G?1:0)<<16,gr[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(gr,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(br[0]=t[0],br[1]=t[1],br[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(br,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}getEachVertex(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;const s=this._state,n=s.geometry,i=this._portions[e];if(!i)return void this.model.error("portion not found: "+e);const a=n.quantizedPositions,r=s.origin,l=i.offset,o=r[0]+l[0],c=r[1]+l[1],u=r[2]+l[2],h=Tr,p=i.matrix,d=this.model.sceneModelMatrix,f=s.positionsDecodeMatrix;for(let e=0,s=a.length;ev)&&(v=e,n.set(w),i&&A.triangleNormal(f,I,y,i),m=!0)}}return m&&i&&(A.transformVec3(l.normalMatrix,i,i),A.transformVec3(this.model.worldNormalMatrix,i,i),A.normalizeVec3(i)),m}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}class Nr extends Qi{drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class xr extends Qi{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class Lr{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Nr(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new xr(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Mr={};class Fr{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const Hr=A.vec4([0,0,0,1]),Ur=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]),A.OBB3();class Gr{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=Mr[t];return s||(s=new Lr(e),Mr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Mr[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new Fr(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ge({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:A.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=A.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=A.vec3(e.origin)),this.aabb=A.collapseAABB3()}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=pa(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.colors.length>0){const n=s.colors.length/4,i=new Float32Array(n);let a=!1;e.flagsBuf=new Te(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new Te(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new Te(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2],c=t[3];for(let e=0;e0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 lightAmbient;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class Vr extends Wi{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 color;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class kr{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new jr(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Vr(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Qr={};const Wr=new Uint8Array(4),zr=new Float32Array(1),Kr=A.vec4([0,0,0,1]),Yr=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]);const Xr=new Float32Array(3);class qr{constructor(e){this.model=e.model,this.material=e.material,this.sortId="LinesInstancingLayer",this.layerIndex=e.layerIndex,this._linesInstancingRenderers=function(e){const t=e.id;let s=Qr[t];return s||(s=new kr(e),Qr[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Qr[t],s._destroy()}))),s}(e.model.scene),this._aabb=A.collapseAABB3(),this._state=new ge({obb:A.OBB3(),numInstances:0,origin:null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],e.origin&&(this._state.origin=A.vec3(e.origin)),this._finalized=!1,this.aabb=A.collapseAABB3()}createPortion(e){const t=e.color,s=e.opacity,n=e.meshMatrix,i=e.aabb;if(this._finalized)throw"Already finalized";const a=t[0],r=t[1],l=t[2];t[3],this._colors.push(a),this._colors.push(r),this._colors.push(l),this._colors.push(s),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(n[0]),this._modelMatrixCol0.push(n[4]),this._modelMatrixCol0.push(n[8]),this._modelMatrixCol0.push(n[12]),this._modelMatrixCol1.push(n[1]),this._modelMatrixCol1.push(n[5]),this._modelMatrixCol1.push(n[9]),this._modelMatrixCol1.push(n[13]),this._modelMatrixCol2.push(n[2]),this._modelMatrixCol2.push(n[6]),this._modelMatrixCol2.push(n[10]),this._modelMatrixCol2.push(n[14]),A.collapseAABB3(i);const o=this._state.obb,c=o.length;for(let e=0;e0){let t=!1;this._state.colorsBuf=new Te(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,t),this._colors=[]}if(s>0){let t=!1;this._state.flagsBuf=new Te(e,e.ARRAY_BUFFER,new Float32Array(s),s,1,e.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Wr[0]=t[0],Wr[1]=t[1],Wr[2]=t[2],Wr[3]=t[3],this._state.colorsBuf.setData(Wr,4*e,4)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&F),i=!!(t&V),a=!!(t&k),r=!!(t&Q),l=!!(t&W),o=!!(t&U),c=!!(t&H);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Bi.NOT_RENDERED:s?Bi.COLOR_TRANSPARENT:Bi.COLOR_OPAQUE,h=!n||c?Bi.NOT_RENDERED:r?Bi.SILHOUETTE_SELECTED:a?Bi.SILHOUETTE_HIGHLIGHTED:i?Bi.SILHOUETTE_XRAYED:Bi.NOT_RENDERED;let p=0;p=!n||c?Bi.NOT_RENDERED:r?Bi.EDGES_SELECTED:a?Bi.EDGES_HIGHLIGHTED:i?Bi.EDGES_XRAYED:l?s?Bi.EDGES_COLOR_TRANSPARENT:Bi.EDGES_COLOR_OPAQUE:Bi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Bi.PICK:Bi.NOT_RENDERED)<<12,A|=(t&G?255:0)<<16,zr[0]=A,this._state.flagsBuf.setData(zr,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Xr[0]=t[0],Xr[1]=t[1],Xr[2]=t[2],this._state.offsetsBuf.setData(Xr,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesXRayed(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawOcclusion(e,t){}drawShadow(e,t){}drawPickMesh(e,t){}drawPickDepths(e,t){}drawPickNormals(e,t){}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}class Jr extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial,n=[];return n.push("#version 300 es"),n.push("// Points batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Zr extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}class $r extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = remapClipPos(clipPos);"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class el extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batched pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = remapClipPos(clipPos);"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batched pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class tl extends Vi{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push(" gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class sl{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Jr(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Zr(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new $r(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new el(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new tl(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const nl={};class il{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]}}const al=A.vec4(),rl=A.vec4(),ll=A.vec4([0,0,0,1]),ol=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]),A.OBB3();class cl{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=nl[t];return s||(s=new sl(e),nl[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete nl[t],s._destroy()}))),s}(e.model.scene),this._buffer=new il(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new ge({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:A.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=A.collapseAABB3(),this._portions=[],this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=A.vec3(e.origin)),this.aabb=A.collapseAABB3()}canCreatePortion(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}createPortion(e){if(this._finalized)throw"Already finalized";const t=e.positions,s=e.positionsCompressed,n=e.color,i=e.colorsCompressed,a=e.colors,r=e.meshMatrix,l=e.worldAABB,o=e.pickColor,c=this._buffer,u=c.positions.length/3;let h;if(this._preCompressedPositionsExpected){if(!s)throw"positionsCompressed expected";for(let e=0,t=s.length;e0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=pa(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new Te(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n);let a=!1;e.flagsBuf=new Te(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new Te(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new Te(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized"}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2];for(let e=0;e0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class hl extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 silhouetteColor;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class pl extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick mesh fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class Al extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = remapClipPos(clipPos);"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class dl extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class fl extends ki{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class Il extends ki{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("gl_PointSize = pointSize;"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }"),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class yl{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new ul(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new hl(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new fl(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new pl(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Al(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new dl(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new Il(this._scene)),this._shadowRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}const ml={};const vl=new Uint8Array(4),wl=new Float32Array(1),gl=A.vec4([0,0,0,1]),Tl=A.vec4([0,0,0,1]);A.vec4([0,0,0,1]);const El=new Float32Array(3);class bl{constructor(e){this.model=e.model,this.material=e.material,this.sortId="PointsInstancingLayer",this.layerIndex=e.layerIndex,this._pointsInstancingRenderers=function(e){const t=e.id;let s=ml[t];return s||(s=new yl(e),ml[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete ml[t],s._destroy()}))),s}(e.model.scene),this._aabb=A.collapseAABB3(),this._state=new ge({obb:A.OBB3(),numInstances:0,origin:e.origin?A.vec3(e.origin):null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=A.collapseAABB3()}createPortion(e){const t=e.meshMatrix,s=e.aabb,n=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(n[0]),this._pickColors.push(n[1]),this._pickColors.push(n[2]),this._pickColors.push(n[3]),A.collapseAABB3(s);const i=this._state.obb,a=i.length;for(let e=0;e0){let n=!1;s.flagsBuf=new Te(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,n)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;s.offsetsBuf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(n.positionsCompressed&&n.positionsCompressed.length>0){const t=!1;s.positionsBuf=new Te(e,e.ARRAY_BUFFER,n.positionsCompressed,n.positionsCompressed.length,3,e.STATIC_DRAW,t),s.positionsDecodeMatrix=A.mat4(n.positionsDecodeMatrix)}if(n.colorsCompressed&&n.colorsCompressed.length>0){const t=new Uint8Array(n.colorsCompressed),i=!1;s.colorsBuf=new Te(e,e.ARRAY_BUFFER,t,t.length,4,e.STATIC_DRAW,i)}if(this._modelMatrixCol0.length>0){const t=!1;s.modelMatrixCol0Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),s.modelMatrixCol1Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),s.modelMatrixCol2Buf=new Te(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){const t=!1;s.pickColorsBuf=new Te(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,t),this._pickColors=[]}s.geometry=null,this._finalized=!0}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";vl[0]=t[0],vl[1]=t[1],vl[2]=t[2],this._state.colorsBuf.setData(vl,3*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&F),i=!!(t&V),a=!!(t&k),r=!!(t&Q),l=!!(t&W),o=!!(t&U),c=!!(t&H);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?Bi.NOT_RENDERED:s?Bi.COLOR_TRANSPARENT:Bi.COLOR_OPAQUE,h=!n||c?Bi.NOT_RENDERED:r?Bi.SILHOUETTE_SELECTED:a?Bi.SILHOUETTE_HIGHLIGHTED:i?Bi.SILHOUETTE_XRAYED:Bi.NOT_RENDERED;let p=0;p=!n||c?Bi.NOT_RENDERED:r?Bi.EDGES_SELECTED:a?Bi.EDGES_HIGHLIGHTED:i?Bi.EDGES_XRAYED:l?s?Bi.EDGES_COLOR_TRANSPARENT:Bi.EDGES_COLOR_OPAQUE:Bi.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?Bi.PICK:Bi.NOT_RENDERED)<<12,A|=(t&G?255:0)<<16,wl[0]=A,this._state.flagsBuf.setData(wl,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(El[0]=t[0],El[1]=t[1],El[2]=t[2],this._state.offsetsBuf.setData(El,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawEdgesXRayed(e,t){}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Bi.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Bi.PICK)}drawPickNormals(e,t){}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}class Dl{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class Pl{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const Rl={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}};class Cl{constructor(e,t,s){this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=s}itemStart(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}itemEnd(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}itemError(e){void 0!==this.onError&&this.onError(e)}resolveURL(e){return this.urlModifier?this.urlModifier(e):e}setURLModifier(e){return this.urlModifier=e,this}addHandler(e,t){return this.handlers.push(e,t),this}removeHandler(e){const t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}getHandler(e){for(let t=0,s=this.handlers.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==Ol[e])return void Ol[e].push({onLoad:t,onProgress:s,onError:n});Ol[e]=[],Ol[e].push({onLoad:t,onProgress:s,onError:n});const a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),r=this.mimeType,l=this.responseType;fetch(a).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const s=Ol[e],n=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,r=0!==a;let l=0;const o=new ReadableStream({start(e){!function t(){n.read().then((({done:n,value:i})=>{if(n)e.close();else{l+=i.byteLength;const n=new ProgressEvent("progress",{lengthComputable:r,loaded:l,total:a});for(let e=0,t=s.length;e{switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,r)));case"json":return e.json();default:if(void 0===r)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(r),s=t&&t[1]?t[1].toLowerCase():void 0,n=new TextDecoder(s);return e.arrayBuffer().then((e=>n.decode(e)))}}})).then((t=>{Rl.add(e,t);const s=Ol[e];delete Ol[e];for(let e=0,n=s.length;e{const s=Ol[e];if(void 0===s)throw this.manager.itemError(e),t;delete Ol[e];for(let e=0,n=s.length;e{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class Nl{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e{const n=this._getIdleWorker();-1!==n?(this._initWorker(n),this.workerStatus|=1<e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let xl=0;class Ll{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new Nl,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const n=e.capabilities;this._workerConfig={astcSupported:n.astcSupported,etc1Supported:n.etc1Supported,etc2Supported:n.etc2Supported,dxtSupported:n.dxtSupported,bptcSupported:n.bptcSupported,pvrtcSupported:n.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new Sl;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new Sl;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const n=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,n]).then((([e,t])=>{const s=Ll.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(Ll.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(Ll.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(Ll.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([n])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),xl>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),xl++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((n,i)=>{const a=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e))).then((e=>{const s=e.data,{mipmaps:a,width:r,height:l,format:o,type:c,error:u,dfdTransferFn:h,dfdFlags:p}=s;if("error"===c)return i(u);t.setCompressedData({mipmaps:a,props:{format:o,minFilter:1===a.length?1006:1008,magFilter:1===a.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&p)}}),n()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),xl--}}Ll.BasisFormat={ETC1S:0,UASTC_4x4:1},Ll.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},Ll.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},Ll.BasisWorker=function(){let e,t,s;const n=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(r){const u=r.data;switch(u.type){case"init":e=u.config,h=u.transcoderBinary,t=new Promise((e=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:r,hasAlpha:h,mipmaps:p,format:A,dfdTransferFn:d,dfdFlags:f}=function(t){const r=new s.KTX2File(new Uint8Array(t));function u(){r.close(),r.delete()}if(!r.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=r.isUASTC()?a.UASTC_4x4:a.ETC1S,p=r.getWidth(),A=r.getHeight(),d=r.getLevels(),f=r.getHasAlpha(),I=r.getDFDTransferFunc(),y=r.getDFDFlags(),{transcoderFormat:m,engineFormat:v}=function(t,s,r,u){let h,p;const A=t===a.ETC1S?l:o;for(let n=0;n{delete Ml[t],s.destroy()}))),s} /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT @@ -14,7 +14,7 @@ class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){ /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT - **/let Vl=null;function kl(e,t){const s=3*e,n=3*t;let i,a,r,l,o,c;const u=Math.min(i=Vl[s],a=Vl[s+1],r=Vl[s+2]),h=Math.min(l=Vl[n],o=Vl[n+1],c=Vl[n+2]);if(u!==h)return u-h;const p=Math.max(i,a,r),A=Math.max(l,o,c);return p!==A?p-A:0}let Ql=null;function Wl(e,t){let s=Ql[2*e]-Ql[2*t];return 0!==s?s:Ql[2*e+1]-Ql[2*t+1]}function zl(e,t,s=!1){const n=e.positionsCompressed||[],i=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e>t;s.sort(kl);const n=new Int32Array(e.length);for(let t=0,i=s.length;te[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}Ql=new Int32Array(e),t.sort(Wl);const s=new Int32Array(e.length);for(let n=0,i=t.length;nt){let s=e;e=t,t=s}function s(s,n){return s!==e?e-s:n!==t?t-n:0}let n=0,i=(a.length>>1)-1;for(;n<=i;){const e=i+n>>1,t=s(a[2*e],a[2*e+1]);if(t>0)n=e+1;else{if(!(t<0))return e;i=e-1}}return-n-1}const l=new Int32Array(a.length/2);l.fill(0);const o=n.length/3;if(o>8*(1<p.maxNumPositions&&(p=h()),p.bucketNumber>8)return[e];let d;-1===c[o]&&(c[o]=p.numPositions++,p.positionsCompressed.push(n[3*o]),p.positionsCompressed.push(n[3*o+1]),p.positionsCompressed.push(n[3*o+2])),-1===c[u]&&(c[u]=p.numPositions++,p.positionsCompressed.push(n[3*u]),p.positionsCompressed.push(n[3*u+1]),p.positionsCompressed.push(n[3*u+2])),-1===c[A]&&(c[A]=p.numPositions++,p.positionsCompressed.push(n[3*A]),p.positionsCompressed.push(n[3*A+1]),p.positionsCompressed.push(n[3*A+2])),p.indices.push(c[o]),p.indices.push(c[u]),p.indices.push(c[A]),(d=r(o,u))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]])),(d=r(o,A))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]])),(d=r(u,A))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]]))}const A=t/8*2,d=t/8,f=2*n.length+(i.length+a.length)*A;let I=0,y=-n.length/3;return u.forEach((e=>{I+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*d,y+=e.positionsCompressed.length/3})),I>f?[e]:(s&&function(e,t){const s={},n={};let i=0;e.forEach((e=>{const t=e.indices,a=e.edgeIndices,r=e.positionsCompressed;for(let e=0,n=t.length;e0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl,s=e._lightsState;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uLightAmbient=n.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];const i=s.lights;let a;for(let e=0,t=i.length;e0;let i;const a=[];a.push("#version 300 es"),a.push("// TrianglesDataTextureColorRenderer vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("uniform mat4 sceneModelWorldMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),a.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),a.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),a.push("uniform highp sampler2D uTextureModelMatrices;"),a.push("uniform vec3 uCameraEyeRtc;"),a.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("out float isPerspective;")),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e> 3) & 4095;"),a.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),a.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),a.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),a.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),a.push("if (int(flags.x) != renderPass) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("} else {"),a.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),a.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),a.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),a.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),a.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),a.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),a.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),a.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),a.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),a.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),a.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),a.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),a.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),a.push("if (color.a == 0u) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("};"),a.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),a.push("vec3 position;"),a.push("position = positions[gl_VertexID % 3];"),a.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),a.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("} else {"),a.push("if (viewNormal.z < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("}"),a.push("}"),a.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),a.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),a.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const eo=new Float32Array([1,1,1]),to=A.vec3(),so=A.vec3(),no=A.vec3(),io=A.vec3(),ao=A.mat4();class ro{constructor(e,t){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=this._scene,i=n.camera,a=t.model,r=n.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=a,d=i.viewMatrix;if(!this._program&&(this._allocate(),this.errors))return;let f,I;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,l)),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const e=to;if(c){const t=so;A.transformPoint3(h,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=S(d,e,ao),I=no,I[0]=i.eye[0]-e[0],I[1]=i.eye[1]-e[1],I[2]=i.eye[2]-e[2]}else f=d,I=i.eye;if(r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s===Bi.SILHOUETTE_XRAYED){const e=n.xrayMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Bi.SILHOUETTE_HIGHLIGHTED){const e=n.highlightMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Bi.SILHOUETTE_SELECTED){const e=n.selectedMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else r.uniform4fv(this._uColor,eo);if(n.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const y=n._sectionPlanesState.sectionPlanes.length;if(y>0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uColor=s.getLocation("color"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture silhouette vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.y) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("viewNormal = -viewNormal;"),s.push("}"),s.push("} else {"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("viewNormal = -viewNormal;"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = color;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const lo=new Float32Array([0,0,0,1]),oo=A.vec3(),co=A.vec3();A.vec3();const uo=A.vec3(),ho=A.mat4();class po{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=oo;if(I){const t=co;A.transformPoint3(h,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=S(d,e,ho)}else f=d;if(r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),s===Bi.EDGES_XRAYED){const e=i.xrayMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Bi.EDGES_HIGHLIGHTED){const e=i.highlightMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Bi.EDGES_SELECTED){const e=i.selectedMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else r.uniform4fv(this._uColor,lo);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(r.LINES,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(r.LINES,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(r.LINES,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uColor=s.getLocation("color"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.z) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),e.logarithmicDepthBufferEnabled&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Ao=A.vec3(),fo=A.vec3(),Io=A.vec3(),yo=A.mat4();class mo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=a.viewMatrix;if(!this._program&&(this._allocate(),this.errors))return;let f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=Ao;if(I){const t=fo;A.transformPoint3(h,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=S(d,e,yo)}else f=d;r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(r.LINES,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(r.LINES,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(r.LINES,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureEdgesColorRenderer"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled,s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.z) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push(" vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vec4 rgb = vec4(color.rgba);"),s.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureEdgesColorRenderer"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const vo=A.vec3(),wo=A.vec3(),go=A.vec3(),To=A.mat4();class Eo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){if(!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n;let d,f;o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=vo;if(I){const t=A.transformPoint3(h,c,wo);e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],d=S(a.viewMatrix,e,To),f=go,f[0]=a.eye[0]-e[0],f[1]=a.eye[1]-e[1],f[2]=a.eye[2]-e[2]}else d=a.viewMatrix,f=a.eye;if(r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),r.uniform3fv(this._uCameraEyeRtc,f),r.uniform1i(this._uRenderPass,s),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("smooth out vec4 vWorldPosition;"),s.push("flat out uvec4 vFlags2;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uvec4 vFlags2;");for(var i=0;i 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outPickColor = vPickColor; "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const bo=A.vec3(),Do=A.vec3(),Po=A.vec3(),Ro=A.vec3(),Co=A.mat4();class _o{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=e.pickViewMatrix||a.viewMatrix;let f,I;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const t=bo;if(c){const e=Do;A.transformPoint3(h,c,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],f=S(d,t,Co),I=Po,I[0]=a.eye[0]-t[0],I[1]=a.eye[1]-t[1],I[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else f=d,I=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform1f(this._uPickZNear,e.pickZNear),r.uniform1f(this._uPickZFar,e.pickZFar),r.uniformMatrix4fv(this._uWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick depth vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var i=0;i 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outPackedDepth = packDepth(zNormalizedDepth); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Bo=A.vec3(),Oo=A.vec3(),So=A.vec3(),No=A.vec3(),xo=A.vec3(),Lo=A.mat4();class Mo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=t.aabb,f=e.pickViewMatrix||a.viewMatrix,I=Bo;let y,m;I[0]=A.safeInv(d[3]-d[0])*A.MAX_INT,I[1]=A.safeInv(d[4]-d[1])*A.MAX_INT,I[2]=A.safeInv(d[5]-d[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(I[0]),e.snapPickCoordinateScale[1]=A.safeInv(I[1]),e.snapPickCoordinateScale[2]=A.safeInv(I[2]),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const v=0!==c[0]||0!==c[1]||0!==c[2],w=0!==u[0]||0!==u[1]||0!==u[2];if(v||w){const t=Oo;if(v){const e=A.transformPoint3(h,c,So);t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],y=S(f,t,Lo),m=No,m[0]=a.eye[0]-t[0],m[1]=a.eye[1]-t[1],m[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else y=f,m=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,m),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,y),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const g=i._sectionPlanesState.sectionPlanes.length;if(g>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*g,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(T,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(T,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(T,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 uSnapVectorA;"),s.push("uniform vec2 uSnapInvVectorAB;"),s.push("vec3 positions[3];"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),s.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vViewPosition;"),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("{"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vViewPosition = clipPos;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles dataTexture pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int uLayerNumber;"),s.push("uniform vec3 uCoordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(let t=0,n=e.sectionPlanes.length;t 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, uLayerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Fo=A.vec3(),Ho=A.vec3(),Uo=A.vec3(),Go=A.vec3(),jo=A.vec3(),Vo=A.mat4();class ko{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=t.aabb,f=e.pickViewMatrix||a.viewMatrix,I=Fo;let y,m;I[0]=A.safeInv(d[3]-d[0])*A.MAX_INT,I[1]=A.safeInv(d[4]-d[1])*A.MAX_INT,I[2]=A.safeInv(d[5]-d[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(I[0]),e.snapPickCoordinateScale[1]=A.safeInv(I[1]),e.snapPickCoordinateScale[2]=A.safeInv(I[2]),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const v=0!==c[0]||0!==c[1]||0!==c[2],w=0!==u[0]||0!==u[1]||0!==u[2];if(v||w){const t=Ho;if(v){const e=Uo;A.transformPoint3(h,c,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],y=S(f,t,Vo),m=Go,m[0]=a.eye[0]-t[0],m[1]=a.eye[1]-t[1],m[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else y=f,m=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,m),r.uniform2fv(this._uVectorA,e.snapVectorA),r.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,y),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const g=i._sectionPlanesState.sectionPlanes.length;if(g>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*g,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureSnapDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 uVectorAB;"),s.push("uniform vec2 uInverseVectorAB;"),s.push("vec3 positions[3];"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),s.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("{"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (solid != 1u) {"),s.push(" if (isPerspectiveMatrix(projMatrix)) {"),s.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" viewNormal = -viewNormal;"),s.push(" }"),s.push(" } else {"),s.push(" if (viewNormal.z < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" viewNormal = -viewNormal;"),s.push(" }"),s.push(" }"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureSnapDepthBufInitRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int uLayerNumber;"),s.push("uniform vec3 uCoordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(let t=0,n=e.sectionPlanes.length;t 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Qo=A.vec3();class Wo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);let u=a.eye;const h=[u[0]-c[0],u[1]-c[1],u[2]-c[2]];if(r.uniform3fv(this._uCameraEyeRtc,h),r.uniform1i(this._uRenderPass,s),r.uniform3fv(this._uCameraEyeRtc,h),r.uniform1i(this._uPickInvisible,e.pickInvisible),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const p=i._sectionPlanesState.sectionPlanes.length;if(p>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*p,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick normals vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureCameraMatrices;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));"),s.push("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));"),s.push("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("normal = -normal;"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("normal = -normal;"),s.push("}"),s.push("}"),s.push("}"),s.push("normal = -normal;"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vWorldNormal = normal.xyz;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.w;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var i=0;i 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const zo=A.vec3(),Ko=A.vec3(),Yo=A.vec3(),Xo=A.vec3(),qo=A.mat4();class Jo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=e.pickViewMatrix||a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let f,I;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const e=zo;if(c){const t=Ko;A.transformPoint3(h,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=S(d,e,qo),I=Yo,I[0]=a.eye[0]-e[0],I[1]=a.eye[1]-e[1],I[2]=a.eye[2]-e[2]}else f=d,I=a.eye;r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out vec4 vFlags2;")),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.x) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push(" if (isPerspectiveMatrix(projMatrix)) {"),s.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix; * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" }"),s.push(" } else {"),s.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push(" if (viewNormal.z < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" }"),s.push(" }"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix; * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in vec4 vFlags2;");for(let t=0;t 0.0);"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Zo=A.vec3(),$o=A.vec3(),ec=A.vec3(),tc=A.vec3(),sc=A.mat4();class nc{constructor(e){this._scene=e,this._allocate(),this._hash=this._getHash()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=this._scene,i=n.camera,a=t.model,r=n.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=a;if(!this._program&&(this._allocate(),this.errors))return;let d,f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,l)),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=Zo;if(I){const t=A.transformPoint3(h,c,$o);e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],d=S(i.viewMatrix,e,sc),f=ec,f[0]=i.eye[0]-e[0],f[1]=i.eye[1]-e[1],f[2]=i.eye[2]-e[2]}else d=i.viewMatrix,f=i.eye;if(r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),r.uniform3fv(this._uCameraEyeRtc,f),r.uniform1i(this._uRenderPass,s),n.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const m=n._sectionPlanesState.sectionPlanes.length;if(m>0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture draw vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out highp vec2 vHighPrecisionZW;"),s&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in highp vec2 vHighPrecisionZW;"),n.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const ic=A.vec3(),ac=A.vec3(),rc=A.vec3(),lc=A.vec3(),oc=A.mat4();class cc{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:h}=n,p=a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let d,f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(t));const I=0!==o[0]||0!==o[1]||0!==o[2],y=0!==c[0]||0!==c[1]||0!==c[2];if(I||y){const e=ic;if(I){const t=ac;A.transformPoint3(u,o,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=c[0],e[1]+=c[1],e[2]+=c[2],d=S(p,e,oc),f=rc,f[0]=a.eye[0]-e[0],f[1]=a.eye[1]-e[1],f[2]=a.eye[2]-e[2]}else d=p,f=a.eye;r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,h),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),r.uniformMatrix4fv(this._uViewNormalMatrix,!1,a.viewNormalMatrix),r.uniformMatrix4fv(this._uWorldNormalMatrix,!1,n.worldNormalMatrix);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0,s=[];return s.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&s.push("#extension GL_EXT_frag_depth : enable"),s.push("uniform int renderPass;"),s.push("attribute vec3 position;"),e.entityOffsetsEnabled&&s.push("attribute vec3 offset;"),s.push("attribute vec3 normal;"),s.push("attribute vec4 color;"),s.push("attribute vec4 flags;"),s.push("attribute vec4 flags2;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 worldNormalMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 viewNormalMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("varying float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out vec4 vFlags2;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("if (int(flags.x) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth?s.push("vFragDepth = 1.0 + clipPos.w;"):(s.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),s.push("clipPos.z *= clipPos.w;")),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(let e=0;e 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const uc=A.vec3();class hc{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerObjectIdPositionsDecodeMatrix),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},1),this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerVertexIdCoordinates),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},2),this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerObjectIdColorsAndFlags),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},3),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix);const c=e.pickViewMatrix||a.viewMatrix,u=o?S(c,o):c;if(r.uniformMatrix4fv(this._uViewMatrix,!1,u),r.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const h=i._sectionPlanesState.sectionPlanes.length;if(h>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*h,a=n.renderFlags;for(let t=0;t0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds8Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices8Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds16Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices16Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds32Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices32Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick flat normals vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in uvec3 packedVertexId;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform isampler2D uTexturePerPolygonIdNormals;"),s.push("uniform usampler2D uTexturePerPolygonIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out int vFlags2;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_normal_index = polygonIndex & 4095;"),s.push("int v_normal_index = polygonIndex >> 12;"),s.push("int h_packed_object_id_index = ((polygonIndex >> 3) / 2) & 4095;"),s.push("int v_packed_object_id_index = ((polygonIndex >> 3) / 2) >> 12;"),s.push("ivec3 packedObjectId = ivec3(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).rgb);"),s.push("int objectIndex;"),s.push("if (((polygonIndex >> 3) % 2) == 0) {"),s.push(" objectIndex = (packedObjectId.r << 4) + (packedObjectId.g >> 4);"),s.push("} else {"),s.push(" objectIndex = ((packedObjectId.g & 15) << 8) + packedObjectId.b;"),s.push("}"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("int h_index = polygonIndex & 4095;"),s.push("int v_index = polygonIndex >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position1 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("vec3 position2 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("vec3 position3 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(position3 - position1, position2 - position1));"),s.push("int vertexNumber = gl_VertexID % 3;"),s.push("vec3 position;"),s.push("if (vertexNumber == 0) position = position1;"),s.push("else if (vertexNumber == 1) position = position2;"),s.push("else position = position3;"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags2 = flags2.r;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick flat normals fragment shader"),n.push("#extension GL_OES_standard_derivatives : enable"),e.logarithmicDepthBufferEnabled&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in int vFlags2;");for(var i=0;i 0;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class pc{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._vertexDepthRenderer&&!this._vertexDepthRenderer.getValid()&&(this._vertexDepthRenderer.destroy(),this._vertexDepthRenderer=null),this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new $l(this._scene,!1)),this._colorRenderer}get colorRendererWithSAO(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new $l(this._scene,!0)),this._colorRendererWithSAO}get colorQualityRendererWithSAO(){return this._colorQualityRendererWithSAO||(this._colorQualityRendererWithSAO=new TrianglesDataTextureColorQualityRenderer(this._scene,!0)),this._colorQualityRendererWithSAO}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ro(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new nc(this._scene)),this._depthRenderer}get normalsRenderer(){return this._normalsRenderer||(this._normalsRenderer=new cc(this._scene)),this._normalsRenderer}get edgesRenderer(){return this._edgesRenderer||(this._edgesRenderer=new po(this._scene)),this._edgesRenderer}get edgesColorRenderer(){return this._edgesColorRenderer||(this._edgesColorRenderer=new mo(this._scene)),this._edgesColorRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Eo(this._scene)),this._pickMeshRenderer}get pickNormalsRenderer(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Wo(this._scene)),this._pickNormalsRenderer}get pickNormalsFlatRenderer(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new hc(this._scene)),this._pickNormalsFlatRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new _o(this._scene)),this._pickDepthRenderer}get vertexDepthRenderer(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new Mo(this._scene)),this._vertexDepthRenderer}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new ko(this._scene)),this._snapDepthBufInitRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Jo(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorQualityRendererWithSAO&&this._colorQualityRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._vertexDepthRenderer&&this._vertexDepthRenderer.destroy(),this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const Ac={};class dc{constructor(){this.positionsCompressed=[],this.metallicRoughness=[],this.indices8Bits=[],this.indices16Bits=[],this.indices32Bits=[],this.edgeIndices8Bits=[],this.edgeIndices16Bits=[],this.edgeIndices32Bits=[],this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]}}class fc{constructor(){this.texturePerObjectIdColorsAndFlags=null,this.texturePerObjectIdOffsets=null,this.texturePerObjectIdPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}finalize(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}bindCommonTextures(e,t,s,n,i,a){this.texturePerObjectIdPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,s,2),this.texturePerObjectIdColorsAndFlags.bindTexture(e,n,3),this.texturePerObjectIdOffsets.bindTexture(e,a,4)}bindTriangleIndicesTextures(e,t,s,n){this.indicesPortionIdsPerBitnessTextures[n].bindTexture(e,t,5),this.indicesPerBitnessTextures[n].bindTexture(e,s,6)}bindEdgeIndicesTextures(e,t,s,n){this.edgeIndicesPortionIdsPerBitnessTextures[n].bindTexture(e,t,5),this.edgeIndicesPerBitnessTextures[n].bindTexture(e,s,6)}}class Ic{constructor(e,t,s,n,i=null){this._gl=e,this._texture=t,this._textureWidth=s,this._textureHeight=n,this._textureData=i}bindTexture(e,t,s){return e.bindTexture(t,this,s)}bind(e){return this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,this._texture),!0}unbind(e){}}const yc={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(yc,null,4));let e=0;Object.keys(yc).forEach((t=>{t.startsWith("size")&&(e+=yc[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/yc.totalPolygons).toFixed(2)}`);let t={};Object.keys(yc).forEach((s=>{s.startsWith("size")&&(t[s]=`${(yc[s]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};class mc{disableBindedTextureFiltering(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}generateTextureForColorsAndFlags(e,t,s,n,i,a,r){const l=t.length;this.numPortions=l;const o=4096,c=Math.ceil(l/512);if(0===c)throw"texture height===0";const u=new Uint8Array(16384*c);yc.sizeDataColorsAndFlags+=u.byteLength,yc.numberOfTextures++;for(let e=0;e>24&255,n[e]>>16&255,n[e]>>8&255,255&n[e]],32*e+16),u.set([i[e]>>24&255,i[e]>>16&255,i[e]>>8&255,255&i[e]],32*e+20),u.set([a[e]>>24&255,a[e]>>16&255,a[e]>>8&255,255&a[e]],32*e+24),u.set([r[e]?1:0,0,0,0],32*e+28);const h=e.createTexture();return e.bindTexture(e.TEXTURE_2D,h),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,o,c),e.texSubImage2D(e.TEXTURE_2D,0,0,0,o,c,e.RGBA_INTEGER,e.UNSIGNED_BYTE,u,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new Ic(e,h,o,c,u)}generateTextureForObjectOffsets(e,t){const s=512,n=Math.ceil(t/s);if(0===n)throw"texture height===0";const i=new Float32Array(1536*n).fill(0);yc.sizeDataTextureOffsets+=i.byteLength,yc.numberOfTextures++;const a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,s,n),e.texSubImage2D(e.TEXTURE_2D,0,0,0,s,n,e.RGB,e.FLOAT,i,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new Ic(e,a,s,n,i)}generateTextureForPositionsDecodeMatrices(e,t,s){const n=t.length;if(0===n)throw"num decode+entity matrices===0";const i=2048,a=Math.ceil(n/512),r=new Float32Array(8192*a);yc.sizeDataPositionDecodeMatrices+=r.byteLength,yc.numberOfTextures++;const l=A.mat4();for(let e=0;e{s._compile()})),e.on("destroyed",(()=>{delete Ac[t],s._destroy()}))),s}(e.scene),this.model=e,this._buffer=new dc,this._dataTextureState=new fc,this._dataTextureGenerator=new mc,this._state=new ge({origin:A.vec3(t.origin),metallicRoughnessBuf:null,positionsDecodeMatrix:A.mat4(),textureState:this._dataTextureState,numIndices8Bits:0,numIndices16Bits:0,numIndices32Bits:0,numEdgeIndices8Bits:0,numEdgeIndices16Bits:0,numEdgeIndices32Bits:0,numVertices:0}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._subPortions=[],this._portionToSubPortionsMap=[],this._bucketGeometries={},this.aabb=A.collapseAABB3(),this._numUpdatesInFrame=0,this._finalized=!1}canCreatePortion(e){if(this._finalized)throw"Already finalized";const t=e.buckets.length;this._numPortions+t>65536&&yc.cannotCreatePortion.because10BitsObjectId++;let s=this._numPortions+t<=65536;const n=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#0`:`${e.id}#0`;if(!this._bucketGeometries[n]){const t=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits);let n=0,i=0;e.buckets.forEach((e=>{n+=e.positionsCompressed.length/3,i+=e.indices.length/3})),(this._state.numVertices+n>16777216||t+i>16777216)&&yc.cannotCreatePortion.becauseTextureSize++,s&&=this._state.numVertices+n<=16777216&&t+i<=16777216}return s}createPortion(e){if(this._finalized)throw"Already finalized";const t=[],s=e.worldAABB;e.buckets.forEach(((n,i)=>{const a=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#${i}`:`${e.id}#${i}`;let r=this._bucketGeometries[a];r||(r=this._createBucketGeometry(e,n),this._bucketGeometries[a]=r);const l=A.collapseAABB3(Ec),o=this._createSubPortion(e,r,n,l);A.expandAABB3(s,l),t.push(o)}));const n=this._state.origin;0===n[0]&&0===n[1]&&0===n[2]||(s[0]+=n[0],s[1]+=n[1],s[2]+=n[2],s[3]+=n[0],s[4]+=n[1],s[5]+=n[2]),A.expandAABB3(this.aabb,s);const i=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(t),this.model.numPortions++,i}_createBucketGeometry(e,t){if(t.indices){const e=8*Math.ceil(t.indices.length/3/8)*3;yc.overheadSizeAlignementIndices+=2*(e-t.indices.length);const s=new Uint32Array(e);s.fill(0),s.set(t.indices),t.indices=s}if(t.edgeIndices){const e=8*Math.ceil(t.edgeIndices.length/2/8)*2;yc.overheadSizeAlignementEdgeIndices+=2*(e-t.edgeIndices.length);const s=new Uint32Array(e);s.fill(0),s.set(t.edgeIndices),t.edgeIndices=s}const s=t.positionsCompressed,n=t.indices,i=t.edgeIndices,a=this._buffer,r=a.positionsCompressed.length/3,l=s.length/3;for(let e=0,t=s.length;e0){let e,s=3*t.numTriangles;t.numVertices<=256?(e=c.perTriangleNumberPortionId8Bits,u.numIndices8Bits+=s,yc.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(e=c.perTriangleNumberPortionId16Bits,u.numIndices16Bits+=s,yc.totalPolygons16Bits+=t.numTriangles):(e=c.perTriangleNumberPortionId32Bits,u.numIndices32Bits+=s,yc.totalPolygons32Bits+=t.numTriangles),yc.totalPolygons+=t.numTriangles;for(let s=0;s0){let e,s=2*t.numEdges;t.numVertices<=256?(e=c.perEdgeNumberPortionId8Bits,u.numEdgeIndices8Bits+=s,yc.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(e=c.perEdgeNumberPortionId16Bits,u.numEdgeIndices16Bits+=s,yc.totalEdges16Bits+=t.numEdges):(e=c.perEdgeNumberPortionId32Bits,u.numEdgeIndices32Bits+=s,yc.totalEdges32Bits+=t.numEdges),yc.totalEdges+=t.numEdges;for(let s=0;s0&&(t.texturePerEdgeIdPortionIds8Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId8Bits)),n.perEdgeNumberPortionId16Bits.length>0&&(t.texturePerEdgeIdPortionIds16Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId16Bits)),n.perEdgeNumberPortionId32Bits.length>0&&(t.texturePerEdgeIdPortionIds32Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId32Bits)),n.indices8Bits.length>0&&(t.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(s,n.indices8Bits)),n.indices16Bits.length>0&&(t.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(s,n.indices16Bits)),n.indices32Bits.length>0&&(t.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(s,n.indices32Bits)),n.edgeIndices8Bits.length>0&&(t.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(s,n.edgeIndices8Bits)),n.edgeIndices16Bits.length>0&&(t.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(s,n.edgeIndices16Bits)),n.edgeIndices32Bits.length>0&&(t.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(s,n.edgeIndices32Bits)),t.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(()=>{this._deferredSetFlagsDirty&&this._uploadDeferredFlags(),this._numUpdatesInFrame=0}))}isEmpty(){return 0===this._numPortions}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,true),this._setFlags2(e,t,true)}flushInitFlags(){this._setDeferredFlags(),this._setDeferredFlags2()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}_beginDeferredFlags(){this._deferredSetFlagsActive=!0}_uploadDeferredFlags(){if(console.info("_uploadDeferredFlags"),this._deferredSetFlagsActive=!1,!this._deferredSetFlagsDirty)return;this._deferredSetFlagsDirty=!1;const e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdColorsAndFlags._textureWidth,t.texturePerObjectIdColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectIdColorsAndFlags._textureData),e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdOffsets._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdOffsets._textureWidth,t.texturePerObjectIdOffsets._textureHeight,e.RGB,e.FLOAT,t.texturePerObjectIdOffsets._textureData)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){const s=this._portionToSubPortionsMap[e];for(let e=0,n=s.length;e=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),n.bindTexture(n.TEXTURE_2D,s.texturePerObjectIdColorsAndFlags._texture),n.texSubImage2D(n.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,n.RGBA_INTEGER,n.UNSIGNED_BYTE,gc)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s,n=!1){const i=this._portionToSubPortionsMap[e];for(let e=0,a=i.length;e=10&&this._beginDeferredFlags(),d.bindTexture(d.TEXTURE_2D,A.texturePerObjectIdColorsAndFlags._texture),d.texSubImage2D(d.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,d.RGBA_INTEGER,d.UNSIGNED_BYTE,gc))}_setDeferredFlags(){}_setFlags2(e,t,s=!1){const n=this._portionToSubPortionsMap[e];for(let e=0,i=n.length;e=10&&this._beginDeferredFlags(),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectIdColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,gc))}_setDeferredFlags2(){}setOffset(e,t){const s=this._portionToSubPortionsMap[e];for(let e=0,n=s.length;e=10&&this._beginDeferredFlags(),n.bindTexture(n.TEXTURE_2D,s.texturePerObjectIdOffsets._texture),n.texSubImage2D(n.TEXTURE_2D,0,0,e,1,1,n.RGB,n.FLOAT,Tc))}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?this._dataTextureRenderers.colorRendererWithSAO&&this._dataTextureRenderers.colorRendererWithSAO.drawLayer(t,this,Bi.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}_updateBackfaceCull(e,t){const s=this.model.backfaces||e.sectioned;if(t.backfaces!==s){const e=t.gl;s?e.disable(e.CULL_FACE):e.enable(e.CULL_FACE),t.backfaces=s}}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_TRANSPARENT))}drawDepth(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.depthRenderer&&this._dataTextureRenderers.depthRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}drawNormals(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.normalsRenderer&&this._dataTextureRenderers.normalsRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_XRAYED))}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_HIGHLIGHTED))}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_SELECTED))}drawEdgesColorOpaque(e,t){this.model.scene.logarithmicDepthBufferEnabled?this.model.scene._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),this.model.scene._loggedWarning=!0):this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Bi.EDGES_COLOR_OPAQUE)}drawEdgesColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Bi.EDGES_COLOR_TRANSPARENT)}drawEdgesHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Bi.EDGES_HIGHLIGHTED)}drawEdgesSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Bi.EDGES_SELECTED)}drawEdgesXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Bi.EDGES_XRAYED)}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.occlusionRenderer&&this._dataTextureRenderers.occlusionRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}drawShadow(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.shadowRenderer&&this._dataTextureRenderers.shadowRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}setPickMatrices(e,t){}drawPickMesh(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickMeshRenderer&&this._dataTextureRenderers.pickMeshRenderer.drawLayer(t,this,Bi.PICK))}drawPickDepths(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,Bi.PICK))}drawSnapInitDepthBuf(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.snapDepthBufInitRenderer&&this._dataTextureRenderers.snapDepthBufInitRenderer.drawLayer(t,this,Bi.PICK))}drawSnapDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.vertexDepthRenderer&&this._dataTextureRenderers.vertexDepthRenderer.drawLayer(t,this,Bi.PICK))}drawPickNormals(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickNormalsRenderer&&this._dataTextureRenderers.pickNormalsRenderer.drawLayer(t,this,Bi.PICK))}destroy(){if(this._destroyed)return;const e=this._state;e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}const Rc=A.vec3();A.mat4();const Cc=A.vec3([1,1,1]),_c=A.vec3([0,0,0]),Bc=A.vec3([0,0,0]),Oc=A.identityQuaternion(),Sc=A.identityMat4(),Nc=new Uint8Array([255,255,255]);class xc extends B{constructor(e,t={}){super(e,t),this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!0,this._vboBatchingLayerScratchMemory=(_i++,Ci),this._textureTranscoder=t.textureTranscoder||Fl(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize,this._aabb=A.collapseAABB3(),this._aabbDirty=!0,this._quantizationRanges={},this._vboInstancingLayers={},this._vboBatchingLayers={},this._dtxLayers={},this._meshList=[],this.layerList=[],this._entityList=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this._scheduledMeshes={},this.renderFlags=new on,this.numGeometries=0,this.numPortions=0,this.numVisibleLayerPortions=0,this.numTransparentLayerPortions=0,this.numXRayedLayerPortions=0,this.numHighlightedLayerPortions=0,this.numSelectedLayerPortions=0,this.numEdgesLayerPortions=0,this.numPickableLayerPortions=0,this.numClippableLayerPortions=0,this.numCulledLayerPortions=0,this.numEntities=0,this._numTriangles=0,this._numLines=0,this._numPoints=0,this._edgeThreshold=t.edgeThreshold||10,this._origin=A.vec3(t.origin||[0,0,0]),this._position=A.vec3(t.position||[0,0,0]),this._rotation=A.vec3(t.rotation||[0,0,0]),this._quaternion=A.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=A.vec4(t.quaternion||[0,0,0,1]),t.rotation&&A.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=A.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=A.mat4(),this._worldRotationMatrixConjugate=A.mat4(),this._matrix=A.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=A.mat4(),A.inverseMat4(this._matrix,this._worldNormalMatrix),A.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=A.mat4(),this._viewNormalMatrix=A.mat4(),this._viewMatrixDirty=!0,this._matrixNonIdentity=!0),this._opacity=1,this._colorize=[1,1,1],this._saoEnabled=!1!==t.saoEnabled,this._pbrEnabled=!1!==t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{this._viewMatrixDirty=!0})),this.scene.vfc.enabled&&(this._vfcManager=this.scene.vfc.getVFCManager(this)),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_createDefaultTextureSet(){const e=new Pl({id:"defaultColorTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Pl({id:"defaultMetalRoughTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new Pl({id:"defaultNormalsTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new Pl({id:"defaultEmissiveTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new Pl({id:"defaultOcclusionTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new Dl({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}get isPerformanceModel(){return!0}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),A.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),A.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||Sc),A.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),A.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),A.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),A.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(A.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),A.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),A.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),A.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0}_setLocalAABBDirty(){for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,s=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,n=t.length;e{o.setImage(c,{minFilter:s,magFilter:n,wrapS:i,wrapT:a,wrapR:r,flipY:e.flipY,encoding:l}),this.glRedraw()},c.src=e.src;break;default:this._textureTranscoder?v.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],o).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,o).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new Pl({id:t,texture:o})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let s,n,i,a,r;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(a=this._textures[e.emissiveTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(r=this._textures[e.occlusionTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultOcclusionTexture;const l=new Dl({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:a,occlusionTexture:r});this._textureSets[t]=l}createMesh(e){if(void 0===e.id||null===e.id)return void this.error("[createMesh] SceneModel.createMesh() config missing: id");if(this._scheduledMeshes[e.id])return void this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`);if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return void this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`);if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),null;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),null;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),null;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),null;const t=!!this._dtxEnabled&&("triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive);if(e.origin=e.origin?A.addVec3(this._origin,e.origin,A.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||Cc,s=e.position||_c,n=e.rotation||Bc;A.eulerToQuaternion(n,"XYZ",Oc),e.meshMatrix=A.composeMat4(s,Oc,t,A.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Aa(e.positionsDecodeBoundary,A.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):Nc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=A.vec3(),s=[];x(e.positions,s,t)&&(e.positions=s,e.origin=A.addVec3(e.origin,t,t))}if(e.positions){const t=A.collapseAABB3();e.positionsDecodeMatrix=A.mat4(),A.expandAABB3Points3(t,e.positions),e.positionsCompressed=pa(e.positions,t,e.positionsDecodeMatrix)}e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Ee(e.positions,e.indices,null,2):e.edgeIndices=Ee(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=Lc(e,this._enableVertexWelding&&this._enableIndexBucketing))}else{if(e.type=1,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):[255,255,255],e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.positions){const t=[];x(e.positions,t,Rc)&&(e.positions=t,e.origin=A.addVec3(e.origin,Rc,A.vec3()))}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Ee(e.positions,e.indices,null,2):e.edgeIndices=Ee(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId],!e.textureSet))return void this.error(`[createMesh] Texture set not found: ${e.textureSetId} - ensure that you create it first with createTextureSet()`)}}else{if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return void this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)");if(e.geometry=this._geometries[e.geometryId],!e.geometry)return void this.error(`[createMesh] Geometry not found: ${e.geometryId} - ensure that you create it first with createGeometry()`);if(e.origin=e.origin?A.addVec3(this._origin,e.origin,A.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.matrix)e.meshMatrix=e.matrix.slice();else{const t=e.scale||Cc,s=e.position||_c,n=e.rotation||Bc;A.eulerToQuaternion(n,"XYZ",Oc),e.meshMatrix=A.composeMat4(s,Oc,t,A.mat4())}if(!!this._dtxEnabled&&("triangles"===e.geometry.primitive||"solid"===e.geometry.primitive||"surface"===e.geometry.primitive)){e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):Nc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;let t=this._dtxBuckets[e.geometryId];t||(t=Lc(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=t),e.buckets=t}else e.type=0,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):Nc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId]),function(e){if(e.obb=A.OBB3(),e.positionsCompressed&&e.positionsCompressed.length>0){const t=A.collapseAABB3();A.expandAABB3Points3(t,e.positionsCompressed),Be.decompressAABB(t,e.positionsDecodeMatrix),A.AABB3ToOBB3(t,e.obb)}else if(e.positions&&e.positions.length>0){const t=A.collapseAABB3();A.expandAABB3Points3(t,e.positions),A.AABB3ToOBB3(t,e.obb)}}(e.geometry)}e.numPrimitives=this._getNumPrimitives(e),this._vfcManager&&!this._vfcManager.finalized?this._vfcManager.addMesh(e):this._createMesh(e)}_createMesh(e){const t=new Ri(this,e.id,e.color,e.opacity);t.pickId=this.scene._renderer.getPickID(t);const s=t.pickId,n=s>>24&255,i=s>>16&255,a=s>>8&255,r=255&s;switch(e.pickColor=new Uint8Array([r,a,i,n]),e.worldAABB=A.collapseAABB3(),e.aabb=e.worldAABB,e.solid="solid"===e.primitive,t.origin=A.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e);break;case 1:t.layer=this._getVBOBatchingLayer(e);break;case 0:t.layer=this._getVBOInstancingLayer(e)}t.portionId=t.layer.createPortion(e),t.aabb=e.worldAABB,t.numPrimitives=e.numPrimitives,A.expandAABB3(this._aabb,t.aabb),this._meshes[e.id]=t,this._meshList.push(t)}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,s=e.origin,n=e.textureSetId||"-",i=e.geometryId,a=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${n}.${i}`;let r=this._vboInstancingLayers[a];if(r)return r;let l=e.textureSet;const o=e.geometry;for(;!r;)switch(o.primitive){case"triangles":case"surface":console.info(`[SceneModel ${this.id}]: creating TrianglesInstancingLayer`),r=new Sr({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0,solid:!1});break;case"solid":console.info(`[SceneModel ${this.id}]: creating TrianglesInstancingLayer`),r=new Sr({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0,solid:!0});break;case"lines":console.info(`[SceneModel ${this.id}]: creating LinesInstancingLayer`),r=new qr({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0});break;case"points":console.info(`[SceneModel ${this.id}]: creating PointsInstancingLayer`),r=new bl({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0})}return this._vboInstancingLayers[a]=r,this.layerList.push(r),r}createEntity(e){if(void 0===e.id?e.id=A.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=A.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;if(this._visible&&!1!==e.visible&&(t|=F),this._pickable&&!1!==e.pickable&&(t|=U),this._culled&&!1!==e.culled&&(t|=H),this._clippable&&!1!==e.clippable&&(t|=G),this._collidable&&!1!==e.collidable&&(t|=j),this._edges&&!1!==e.edges&&(t|=W),this._xrayed&&!1!==e.xrayed&&(t|=V),this._highlighted&&!1!==e.highlighted&&(t|=k),this._selected&&!1!==e.selected&&(t|=Q),e.flags=t,this._vfcManager&&!this._vfcManager.finalized){for(let t=0,s=e.meshIds.length;t{}));for(let e=0,t=this.layerList.length;ee.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,s=this.layerList.length;t0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s65536?16:8)}else r=[{positionsCompressed:n,indices:i,edgeIndices:a}];return r}class Mc extends xc{constructor(e,t={}){super(e,t)}}class Fc extends B{get type(){return"SectionPlane"}constructor(e,t={}){super(e,t),this._state=new ge({active:!0,pos:A.vec3(),dir:A.vec3(),dist:0}),this.active=t.active,this.pos=t.pos,this.dir=t.dir,this.scene._sectionPlaneCreated(this)}set active(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}get active(){return this._state.active}set pos(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-A.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos)}get pos(){return this._state.pos}set dir(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-A.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir)}get dir(){return this._state.dir}get dist(){return this._state.dist}flipDir(){const e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-A.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}destroy(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),super.destroy()}}class Hc extends B{constructor(e,t={}){super(e,t),this._skyboxMesh=new vn(this,{geometry:new Ne(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new bn(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new xn(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}class Uc{transcode(e,t,s={}){}destroy(){}}class Gc{constructor(e,t){this.primLODLevels=e,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=t,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}initializeLodState(e){const t=Object.values(e.objects);if(0===t.length)return;const s={},n={};for(let e=0,i=t.length;e=this.primLODLevels[r]);r++);const l=this.primLODLevels[r]||0;l in s||(s[l]=[]),s[l].push(i),l in n||(n[l]=0),n[l]+=i.numPrimitives}this.entitiesInLOD=s,this.primCountInLOD=n}}class jc{constructor(e,t,s,n){this.id=t.id,this.scene=e,this.sceneModel=t,this.lodState=new Gc(s,n),this.lodState.initializeLodState(t)}_increaseLODLevelIndex(){const e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;const t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[];for(let e=0,s=t.length;e0&&(t.consecutiveFramesWithoutTargetFps=0,s=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,s=this._decreaseLODLevelIndex()),s}resetLodCulling(){let e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}class Vc extends B{constructor(e,t={}){super(e,t),this._scene=e,this._lodLevels=[2e3,600,150,80,20],this._lodManagers={},this._lodManagerList=[],this.enabled=t.enabled,this.targetFPS=t.targetFPS,this._init()}_init(){const e=new Array(4);let t=0,s=-1,n=Date.now(),i=0,a=0,r=a;this._scene.on("rendering",(()=>{if(-1!==s)for(let e=0,t=this._lodManagerList.length;e{n=Date.now(),window.requestAnimationFrame((()=>{t++;const a=Date.now();i=a-n,n=a,e[t%4]=i;let r=0;if(t>4){for(let t=0;t<4;t++)r+=e[t];s=4/r*1e3}}))})),this._scene.camera.on("matrix",(()=>{r=a})),this._scene.on("tick",(()=>{if(a-r>3)for(let e=0,t=this._lodManagerList.length;e=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},s.boxRayIntersects=function(e,t,s,n,i,a,r){var l=(e.minX-t)*i,o=(e.maxX-t)*i,c=(e.minY-s)*a,u=(e.maxY-s)*a,h=(e.minZ-n)*r,p=(e.maxZ-n)*r,A=Math.min(h,p),d=Math.max(h,p),f=Math.min(c,u),I=Math.max(c,u),y=Math.min(l,o),m=Math.max(l,o),v=Math.max(0,y,f,A);return Math.min(m,I,d)>=v?v:1/0};var g=function(e,t,s,i,a){for(var r,l=[t,s];l.length;)(s=l.pop())-(t=l.pop())<=i||(r=t+Math.ceil((s-t)/i/2)*i,n(e,r,t,s,a),l.push(t,r,r,s))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var s=this.data,n=[];if(!e(s,h(s)))return n;for(var i=[];s;){for(var a=0,r=s.children.length;a1){for(d=0,f=(u=u[u.length-1]).length;d=t)break;var i=n+1;if(i0;){var n=s-1>>1;if(A[n].dist<=A[s].dist)break;d(s,n),s=n}},y=l;A.length&&A[0].dist=t;l--){o=e.children[l];f(a,o),r+=y(a)}return r},e.prototype.adjustParentBBoxes=function(e,t,s){for(var n=s;n>=0;n--)f(t[n],e)},e.prototype.condense=function(e){for(var t=e.length-1,s=void 0;t>=0;t--)0===e[t].children.length?t>0?((s=e[t-1].children).splice(s.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,s){var n=[],i=this.chooseSubtree(e,this.data,t,n);for(i.children.push(e),f(i,e);t>=0&&n[t].children.length>this.maxEntries;)this.split(n,t),t--;this.adjustParentBBoxes(e,n,t)},e.pool=[],e}();s.RBush3D=D},{quickselect:2}],2:[function(e,t,s){!function(e,n){"object"==typeof s&&void 0!==t?t.exports=n():e.quickselect=n()}(this,(function(){function e(s,n,i,a,r){for(;a>i;){if(a-i>600){var l=a-i+1,o=n-i+1,c=Math.log(l),u=.5*Math.exp(2*c/3),h=.5*Math.sqrt(c*u*(l-u)/l)*(o-l/2<0?-1:1);e(s,n,Math.max(i,Math.floor(n-o*u/l+h)),Math.min(a,Math.floor(n+(l-o)*u/l+h)),r)}var p=s[n],A=i,d=a;for(t(s,i,n),r(s[a],p)>0&&t(s,i,a);A0;)d--}0===r(s[i],p)?t(s,i,d):t(s,++d,a),d<=n&&(i=d+1),n<=d&&(a=d-1)}}function t(e,t,s){var n=e[t];e[t]=e[s],e[s]=n}function s(e,t){return et?1:0}return function(t,n,i,a,r){e(t,n,i||0,a||t.length-1,r||s)}}))},{}]},{},[1])(1)}));var Wc=kc.exports.RBush3D,zc=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function s(e,t){var s={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function n(){(0==s.dir&&s.pos.x+1>=s.right||1==s.dir&&s.pos.y+1>=s.bottom||2==s.dir&&s.pos.x-1<=s.left-1||3==s.dir&&s.pos.y-1<=s.top-1)&&(s.dir=(s.dir+1)%4,0==s.dir&&s.left++,1==s.dir&&s.top++,2==s.dir&&s.right--,3==s.dir&&s.bottom--),0==s.dir&&s.pos.x++,1==s.dir&&s.pos.y++,2==s.dir&&s.pos.x--,3==s.dir&&s.pos.y--}for(var i=[],a=e*t;i.lengthp&&(u.push(h),h=[],p=l),h.push(d),p-=f}}while(Ap&&(u.push(A),A=[],p=l),A.push(e),p-=s})),A.length&&u.push(A);var d={};return u.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:u,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,n.maxPolygonsPerCluster),{clusters:{total:r.clusters.length},clusteringResult:r});l+=o.clusters.total,console.log("Total clusters: "+l);var c=[];return o.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){c.push(e.id)}))})),o.orderedEntityIds=c,o}; + **/let Vl=null;function kl(e,t){const s=3*e,n=3*t;let i,a,r,l,o,c;const u=Math.min(i=Vl[s],a=Vl[s+1],r=Vl[s+2]),h=Math.min(l=Vl[n],o=Vl[n+1],c=Vl[n+2]);if(u!==h)return u-h;const p=Math.max(i,a,r),A=Math.max(l,o,c);return p!==A?p-A:0}let Ql=null;function Wl(e,t){let s=Ql[2*e]-Ql[2*t];return 0!==s?s:Ql[2*e+1]-Ql[2*t+1]}function zl(e,t,s=!1){const n=e.positionsCompressed||[],i=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e>t;s.sort(kl);const n=new Int32Array(e.length);for(let t=0,i=s.length;te[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}Ql=new Int32Array(e),t.sort(Wl);const s=new Int32Array(e.length);for(let n=0,i=t.length;nt){let s=e;e=t,t=s}function s(s,n){return s!==e?e-s:n!==t?t-n:0}let n=0,i=(a.length>>1)-1;for(;n<=i;){const e=i+n>>1,t=s(a[2*e],a[2*e+1]);if(t>0)n=e+1;else{if(!(t<0))return e;i=e-1}}return-n-1}const l=new Int32Array(a.length/2);l.fill(0);const o=n.length/3;if(o>8*(1<p.maxNumPositions&&(p=h()),p.bucketNumber>8)return[e];let d;-1===c[o]&&(c[o]=p.numPositions++,p.positionsCompressed.push(n[3*o]),p.positionsCompressed.push(n[3*o+1]),p.positionsCompressed.push(n[3*o+2])),-1===c[u]&&(c[u]=p.numPositions++,p.positionsCompressed.push(n[3*u]),p.positionsCompressed.push(n[3*u+1]),p.positionsCompressed.push(n[3*u+2])),-1===c[A]&&(c[A]=p.numPositions++,p.positionsCompressed.push(n[3*A]),p.positionsCompressed.push(n[3*A+1]),p.positionsCompressed.push(n[3*A+2])),p.indices.push(c[o]),p.indices.push(c[u]),p.indices.push(c[A]),(d=r(o,u))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]])),(d=r(o,A))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]])),(d=r(u,A))>=0&&0===l[d]&&(l[d]=1,p.edgeIndices.push(c[a[2*d]]),p.edgeIndices.push(c[a[2*d+1]]))}const A=t/8*2,d=t/8,f=2*n.length+(i.length+a.length)*A;let I=0,y=-n.length/3;return u.forEach((e=>{I+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*d,y+=e.positionsCompressed.length/3})),I>f?[e]:(s&&function(e,t){const s={},n={};let i=0;e.forEach((e=>{const t=e.indices,a=e.edgeIndices,r=e.positionsCompressed;for(let e=0,n=t.length;e0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl,s=e._lightsState;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uLightAmbient=n.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];const i=s.lights;let a;for(let e=0,t=i.length;e0;let i;const a=[];a.push("#version 300 es"),a.push("// TrianglesDataTextureColorRenderer vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("uniform mat4 sceneModelWorldMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),a.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),a.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),a.push("uniform highp sampler2D uTextureModelMatrices;"),a.push("uniform vec3 uCameraEyeRtc;"),a.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("out float isPerspective;")),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e> 3) & 4095;"),a.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),a.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),a.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),a.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),a.push("if (int(flags.x) != renderPass) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("} else {"),a.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),a.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),a.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),a.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),a.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),a.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),a.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),a.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),a.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),a.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),a.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),a.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),a.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),a.push("if (color.a == 0u) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("};"),a.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),a.push("vec3 position;"),a.push("position = positions[gl_VertexID % 3];"),a.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),a.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("} else {"),a.push("if (viewNormal.z < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("}"),a.push("}"),a.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),a.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),a.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const eo=new Float32Array([1,1,1]),to=A.vec3(),so=A.vec3(),no=A.vec3(),io=A.vec3(),ao=A.mat4();class ro{constructor(e,t){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=this._scene,i=n.camera,a=t.model,r=n.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=a,d=i.viewMatrix;if(!this._program&&(this._allocate(),this.errors))return;let f,I;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,l)),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const e=to;if(c){const t=so;A.transformPoint3(h,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=S(d,e,ao),I=no,I[0]=i.eye[0]-e[0],I[1]=i.eye[1]-e[1],I[2]=i.eye[2]-e[2]}else f=d,I=i.eye;if(r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s===Bi.SILHOUETTE_XRAYED){const e=n.xrayMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Bi.SILHOUETTE_HIGHLIGHTED){const e=n.highlightMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Bi.SILHOUETTE_SELECTED){const e=n.selectedMaterial._state,t=e.fillColor,s=e.fillAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else r.uniform4fv(this._uColor,eo);if(n.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const y=n._sectionPlanesState.sectionPlanes.length;if(y>0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uColor=s.getLocation("color"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture silhouette vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.y) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("viewNormal = -viewNormal;"),s.push("}"),s.push("} else {"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("viewNormal = -viewNormal;"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = color;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const lo=new Float32Array([0,0,0,1]),oo=A.vec3(),co=A.vec3();A.vec3();const uo=A.vec3(),ho=A.mat4();class po{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=oo;if(I){const t=co;A.transformPoint3(h,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=S(d,e,ho)}else f=d;if(r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),s===Bi.EDGES_XRAYED){const e=i.xrayMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Bi.EDGES_HIGHLIGHTED){const e=i.highlightMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else if(s===Bi.EDGES_SELECTED){const e=i.selectedMaterial._state,t=e.edgeColor,s=e.edgeAlpha;r.uniform4f(this._uColor,t[0],t[1],t[2],s)}else r.uniform4fv(this._uColor,lo);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(r.LINES,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(r.LINES,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(r.LINES,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uColor=s.getLocation("color"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.z) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),e.logarithmicDepthBufferEnabled&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Ao=A.vec3(),fo=A.vec3(),Io=A.vec3(),yo=A.mat4();class mo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=a.viewMatrix;if(!this._program&&(this._allocate(),this.errors))return;let f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=Ao;if(I){const t=fo;A.transformPoint3(h,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=S(d,e,yo)}else f=d;r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(r.LINES,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(r.LINES,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(r.LINES,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureEdgesColorRenderer"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled,s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.z) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push(" vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vec4 rgb = vec4(color.rgba);"),s.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureEdgesColorRenderer"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vColor;"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const vo=A.vec3(),wo=A.vec3(),go=A.vec3(),To=A.mat4();class Eo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){if(!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n;let d,f;o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=vo;if(I){const t=A.transformPoint3(h,c,wo);e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],d=S(a.viewMatrix,e,To),f=go,f[0]=a.eye[0]-e[0],f[1]=a.eye[1]-e[1],f[2]=a.eye[2]-e[2]}else d=a.viewMatrix,f=a.eye;if(r.uniform2fv(this._uPickClipPos,e.pickClipPos),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),r.uniform3fv(this._uCameraEyeRtc,f),r.uniform1i(this._uRenderPass,s),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPickClipPos=s.getLocation("pickClipPos"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("uniform vec2 pickClipPos;"),s.push("vec4 remapClipPos(vec4 clipPos) {"),s.push(" clipPos.xy /= clipPos.w;"),s.push(" clipPos.xy -= pickClipPos;"),s.push(" clipPos.xy *= clipPos.w;"),s.push(" return clipPos;"),s.push("}"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("smooth out vec4 vWorldPosition;"),s.push("flat out uvec4 vFlags2;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uvec4 vFlags2;");for(var i=0;i 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outPickColor = vPickColor; "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const bo=A.vec3(),Do=A.vec3(),Po=A.vec3(),Ro=A.vec3(),Co=A.mat4();class _o{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=e.pickViewMatrix||a.viewMatrix;let f,I;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const t=bo;if(c){const e=Do;A.transformPoint3(h,c,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],f=S(d,t,Co),I=Po,I[0]=a.eye[0]-t[0],I[1]=a.eye[1]-t[1],I[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else f=d,I=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform2fv(this._uPickClipPos,e.pickClipPos),r.uniform1f(this._uPickZNear,e.pickZNear),r.uniform1f(this._uPickZFar,e.pickZFar),r.uniformMatrix4fv(this._uWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPickClipPos=s.getLocation("pickClipPos"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick depth vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("uniform vec2 pickClipPos;"),s.push("vec4 remapClipPos(vec4 clipPos) {"),s.push(" clipPos.xy /= clipPos.w;"),s.push(" clipPos.xy -= pickClipPos;"),s.push(" clipPos.xy *= clipPos.w;"),s.push(" return clipPos;"),s.push("}"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("}"),s.push("}"),s.push("}"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var i=0;i 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outPackedDepth = packDepth(zNormalizedDepth); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Bo=A.vec3(),Oo=A.vec3(),So=A.vec3(),No=A.vec3(),xo=A.vec3(),Lo=A.mat4();class Mo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){if(!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=t.aabb,f=e.pickViewMatrix||a.viewMatrix,I=Bo;let y,m;I[0]=A.safeInv(d[3]-d[0])*A.MAX_INT,I[1]=A.safeInv(d[4]-d[1])*A.MAX_INT,I[2]=A.safeInv(d[5]-d[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(I[0]),e.snapPickCoordinateScale[1]=A.safeInv(I[1]),e.snapPickCoordinateScale[2]=A.safeInv(I[2]),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const v=0!==c[0]||0!==c[1]||0!==c[2],w=0!==u[0]||0!==u[1]||0!==u[2];if(v||w){const t=Oo;if(v){const e=A.transformPoint3(h,c,So);t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],y=S(f,t,Lo),m=No,m[0]=a.eye[0]-t[0],m[1]=a.eye[1]-t[1],m[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else y=f,m=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,m),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,y),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const g=i._sectionPlanesState.sectionPlanes.length;if(g>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*g,a=n.renderFlags;for(let t=0;t0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),r.drawArrays(T,0,l.numEdgeIndices8Bits)),l.numEdgeIndices16Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),r.drawArrays(T,0,l.numEdgeIndices16Bits)),l.numEdgeIndices32Bits>0&&(o.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),r.drawArrays(T,0,l.numEdgeIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),s.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 uSnapVectorA;"),s.push("uniform vec2 uSnapInvVectorAB;"),s.push("vec3 positions[3];"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),s.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec4 vViewPosition;"),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int edgeIndex = gl_VertexID / 2;"),s.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("{"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),s.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),s.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),s.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),s.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.r;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),s.push("vViewPosition = clipPos;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push("gl_PointSize = 1.0;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Triangles dataTexture pick depth fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int uLayerNumber;"),s.push("uniform vec3 uCoordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(let t=0,n=e.sectionPlanes.length;t 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, uLayerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Fo=A.vec3(),Ho=A.vec3(),Uo=A.vec3(),Go=A.vec3(),jo=A.vec3(),Vo=A.mat4();class ko{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=t.aabb,f=e.pickViewMatrix||a.viewMatrix,I=Fo;let y,m;I[0]=A.safeInv(d[3]-d[0])*A.MAX_INT,I[1]=A.safeInv(d[4]-d[1])*A.MAX_INT,I[2]=A.safeInv(d[5]-d[2])*A.MAX_INT,e.snapPickCoordinateScale[0]=A.safeInv(I[0]),e.snapPickCoordinateScale[1]=A.safeInv(I[1]),e.snapPickCoordinateScale[2]=A.safeInv(I[2]),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const v=0!==c[0]||0!==c[1]||0!==c[2],w=0!==u[0]||0!==u[1]||0!==u[2];if(v||w){const t=Ho;if(v){const e=Uo;A.transformPoint3(h,c,e),t[0]=e[0],t[1]=e[1],t[2]=e[2]}else t[0]=0,t[1]=0,t[2]=0;t[0]+=u[0],t[1]+=u[1],t[2]+=u[2],y=S(f,t,Vo),m=Go,m[0]=a.eye[0]-t[0],m[1]=a.eye[1]-t[1],m[2]=a.eye[2]-t[2],e.snapPickOrigin[0]=t[0],e.snapPickOrigin[1]=t[1],e.snapPickOrigin[2]=t[2]}else y=f,m=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;r.uniform3fv(this._uCameraEyeRtc,m),r.uniform2fv(this._uVectorA,e.snapVectorA),r.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),r.uniform3fv(this._uCoordinateScaler,I),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,y),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);{const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const g=i._sectionPlanesState.sectionPlanes.length;if(g>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*g,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureSnapDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 uVectorAB;"),s.push("uniform vec2 uInverseVectorAB;"),s.push("vec3 positions[3];"),s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),s.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("{"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (solid != 1u) {"),s.push(" if (isPerspectiveMatrix(projMatrix)) {"),s.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" viewNormal = -viewNormal;"),s.push(" }"),s.push(" } else {"),s.push(" if (viewNormal.z < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" viewNormal = -viewNormal;"),s.push(" }"),s.push(" }"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureSnapDepthBufInitRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"),s.push("uniform int uLayerNumber;"),s.push("uniform vec3 uCoordinateScaler;"),t){s.push("in vec4 vWorldPosition;"),s.push("flat in uint vFlags2;");for(let t=0,n=e.sectionPlanes.length;t 0u;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Qo=A.vec3();class Wo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);let u=a.eye;const h=[u[0]-c[0],u[1]-c[1],u[2]-c[2]];if(r.uniform3fv(this._uCameraEyeRtc,h),r.uniform1i(this._uRenderPass,s),r.uniform3fv(this._uCameraEyeRtc,h),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform2fv(this._uPickClipPos,e.pickClipPos),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const p=i._sectionPlanesState.sectionPlanes.length;if(p>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*p,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPickClipPos=s.getLocation("pickClipPos"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick normals vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform bool pickInvisible;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureCameraMatrices;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("uniform vec2 pickClipPos;"),s.push("vec4 remapClipPos(vec4 clipPos) {"),s.push(" clipPos.xy /= clipPos.w;"),s.push(" clipPos.xy -= pickClipPos;"),s.push(" clipPos.xy *= clipPos.w;"),s.push(" return clipPos;"),s.push("}"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("flat out uint vFlags2;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));"),s.push("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));"),s.push("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("} else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push("if (isPerspectiveMatrix(projMatrix)) {"),s.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("normal = -normal;"),s.push("}"),s.push("} else {"),s.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push("if (viewNormal.z < 0.0) {"),s.push("position = positions[2 - (gl_VertexID % 3)];"),s.push("normal = -normal;"),s.push("}"),s.push("}"),s.push("}"),s.push("normal = -normal;"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vWorldNormal = normal.xyz;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2.w;")),s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var i=0;i 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(` outNormal = ivec4(vWorldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const zo=A.vec3(),Ko=A.vec3(),Yo=A.vec3(),Xo=A.vec3(),qo=A.mat4();class Jo{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=n,d=e.pickViewMatrix||a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let f,I;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),c||0!==u[0]||0!==u[1]||0!==u[2]){const e=zo;if(c){const t=Ko;A.transformPoint3(h,c,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],f=S(d,e,qo),I=Yo,I[0]=a.eye[0]-e[0],I[1]=a.eye[1]-e[1],I[2]=a.eye[2]-e[2]}else f=d,I=a.eye;r.uniform3fv(this._uCameraEyeRtc,I),r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,a=n.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform mat4 sceneModelWorldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),s.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),s.push("uniform highp sampler2D uTextureModelMatrices;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("vec3 positions[3];"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out vec4 vFlags2;")),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),s.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),s.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("if (int(flags.x) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),s.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),s.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),s.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),s.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),s.push("if (color.a == 0u) {"),s.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),s.push(" return;"),s.push("};"),s.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),s.push("vec3 position;"),s.push("position = positions[gl_VertexID % 3];"),s.push("if (solid != 1u) {"),s.push(" if (isPerspectiveMatrix(projMatrix)) {"),s.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix; * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),s.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" }"),s.push(" } else {"),s.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),s.push(" if (viewNormal.z < 0.0) {"),s.push(" position = positions[2 - (gl_VertexID % 3)];"),s.push(" }"),s.push(" }"),s.push("}"),s.push("vec4 worldPosition = sceneModelWorldMatrix; * (positionsDecodeMatrix * vec4(position, 1.0)); "),s.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),s.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags2 = flags2.r;")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// TrianglesDataTextureColorRenderer fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in vec4 vFlags2;");for(let t=0;t 0.0);"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(let t=0;t 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),s.push("}"),s}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Zo=A.vec3(),$o=A.vec3(),ec=A.vec3(),tc=A.vec3(),sc=A.mat4();class nc{constructor(e){this._scene=e,this._allocate(),this._hash=this._getHash()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=this._scene,i=n.camera,a=t.model,r=n.canvas.gl,l=t._state,o=l.textureState,c=t._state.origin,{position:u,rotationMatrix:h,rotationMatrixConjugate:p}=a;if(!this._program&&(this._allocate(),this.errors))return;let d,f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,l)),o.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);const I=0!==c[0]||0!==c[1]||0!==c[2],y=0!==u[0]||0!==u[1]||0!==u[2];if(I||y){const e=Zo;if(I){const t=A.transformPoint3(h,c,$o);e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=u[0],e[1]+=u[1],e[2]+=u[2],d=S(i.viewMatrix,e,sc),f=ec,f[0]=i.eye[0]-e[0],f[1]=i.eye[1]-e[1],f[2]=i.eye[2]-e[2]}else d=i.viewMatrix,f=i.eye;if(r.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),r.uniform3fv(this._uCameraEyeRtc,f),r.uniform1i(this._uRenderPass,s),n.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const m=n._sectionPlanesState.sectionPlanes.length;if(m>0){const e=n._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,i=a.renderFlags;for(let t=0;t0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(o.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uSceneModelWorldMatrix=s.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture draw vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out highp vec2 vHighPrecisionZW;"),s&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in highp vec2 vHighPrecisionZW;"),n.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(let e=0,s=t.sectionPlanes.length;e 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const ic=A.vec3(),ac=A.vec3(),rc=A.vec3(),lc=A.vec3(),oc=A.mat4();class cc{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin,{position:c,rotationMatrix:u,rotationMatrixConjugate:h}=n,p=a.viewMatrix;if(!this._program&&(this._allocate(t),this.errors))return;let d,f;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(t));const I=0!==o[0]||0!==o[1]||0!==o[2],y=0!==c[0]||0!==c[1]||0!==c[2];if(I||y){const e=ic;if(I){const t=ac;A.transformPoint3(u,o,t),e[0]=t[0],e[1]=t[1],e[2]=t[2]}else e[0]=0,e[1]=0,e[2]=0;e[0]+=c[0],e[1]+=c[1],e[2]+=c[2],d=S(p,e,oc),f=rc,f[0]=a.eye[0]-e[0],f[1]=a.eye[1]-e[1],f[2]=a.eye[2]-e[2]}else d=p,f=a.eye;r.uniform1i(this._uRenderPass,s),r.uniformMatrix4fv(this._uWorldMatrix,!1,h),r.uniformMatrix4fv(this._uViewMatrix,!1,d),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),r.uniformMatrix4fv(this._uViewNormalMatrix,!1,a.viewNormalMatrix),r.uniformMatrix4fv(this._uWorldNormalMatrix,!1,n.worldNormalMatrix);const m=i._sectionPlanesState.sectionPlanes.length;if(m>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*m,a=n.renderFlags;for(let t=0;t0,s=[];return s.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&s.push("#extension GL_EXT_frag_depth : enable"),s.push("uniform int renderPass;"),s.push("attribute vec3 position;"),e.entityOffsetsEnabled&&s.push("attribute vec3 offset;"),s.push("attribute vec3 normal;"),s.push("attribute vec4 color;"),s.push("attribute vec4 flags;"),s.push("attribute vec4 flags2;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 worldNormalMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 viewNormalMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("varying float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out vec4 vFlags2;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("if (int(flags.x) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags2 = flags2;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth?s.push("vFragDepth = 1.0 + clipPos.w;"):(s.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),s.push("clipPos.z *= clipPos.w;")),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(let e=0;e 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&Bs.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const uc=A.vec3();class hc{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerObjectIdPositionsDecodeMatrix),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},1),this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerVertexIdCoordinates),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},2),this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerObjectIdColorsAndFlags),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},3),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform2fv(this._uPickClipPos,e.pickClipPos),r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix);const c=e.pickViewMatrix||a.viewMatrix,u=o?S(c,o):c;if(r.uniformMatrix4fv(this._uViewMatrix,!1,u),r.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),i.logarithmicDepthBufferEnabled){const e=2/(Math.log(a.project.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,e)}const h=i._sectionPlanesState.sectionPlanes.length;if(h>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*h,a=n.renderFlags;for(let t=0;t0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds8Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices8Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices8Bits)),l.numIndices16Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds16Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices16Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices16Bits)),l.numIndices32Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdPortionIds32Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,l.texturePerPolygonIdIndices32Bits),!0},unbind:function(e){r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,null)}},5),r.drawArrays(r.TRIANGLES,0,l.numIndices32Bits)),e.drawElements++}_allocate(){const e=this._scene,t=e.canvas.gl;if(this._program=new _s(t,this._buildShader()),this._program.errors)return void(this.errors=this._program.errors);const s=this._program;this._uRenderPass=s.getLocation("renderPass"),this._uPickInvisible=s.getLocation("pickInvisible"),this._uPickClipPos=s.getLocation("pickClipPos"),this._uPositionsDecodeMatrix=s.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=s.getLocation("worldMatrix"),this._uViewMatrix=s.getLocation("viewMatrix"),this._uProjMatrix=s.getLocation("projMatrix"),this._uSectionPlanes=[];for(let t=0,n=e._sectionPlanesState.sectionPlanes.length;t0,s=[];return s.push("#version 300 es"),s.push("// Triangles dataTexture pick flat normals vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in uvec3 packedVertexId;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),s.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;"),s.push("uniform usampler2D uTexturePerVertexIdCoordinates;"),s.push("uniform usampler2D uTexturePerPolygonIdIndices;"),s.push("uniform isampler2D uTexturePerPolygonIdNormals;"),s.push("uniform usampler2D uTexturePerPolygonIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("uniform vec2 pickClipPos;"),s.push("vec4 remapClipPos(vec4 clipPos) {"),s.push(" clipPos.xy /= clipPos.w;"),s.push(" clipPos.xy -= pickClipPos;"),s.push(" clipPos.xy *= clipPos.w;"),s.push(" return clipPos;"),s.push("}"),s.push("out vec4 vWorldPosition;"),t&&s.push("out int vFlags2;"),s.push("void main(void) {"),s.push("int polygonIndex = gl_VertexID / 3;"),s.push("int h_normal_index = polygonIndex & 4095;"),s.push("int v_normal_index = polygonIndex >> 12;"),s.push("int h_packed_object_id_index = ((polygonIndex >> 3) / 2) & 4095;"),s.push("int v_packed_object_id_index = ((polygonIndex >> 3) / 2) >> 12;"),s.push("ivec3 packedObjectId = ivec3(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).rgb);"),s.push("int objectIndex;"),s.push("if (((polygonIndex >> 3) % 2) == 0) {"),s.push(" objectIndex = (packedObjectId.r << 4) + (packedObjectId.g >> 4);"),s.push("} else {"),s.push(" objectIndex = ((packedObjectId.g & 15) << 8) + packedObjectId.b;"),s.push("}"),s.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),s.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),s.push("int h_index = polygonIndex & 4095;"),s.push("int v_index = polygonIndex >> 12;"),s.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),s.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),s.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),s.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),s.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),s.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),s.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),s.push("vec3 position1 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),s.push("vec3 position2 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),s.push("vec3 position3 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),s.push("vec3 normal = normalize(cross(position3 - position1, position2 - position1));"),s.push("int vertexNumber = gl_VertexID % 3;"),s.push("vec3 position;"),s.push("if (vertexNumber == 0) position = position1;"),s.push("else if (vertexNumber == 1) position = position2;"),s.push("else position = position3;"),s.push("if (int(flags.w) != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags2 = flags2.r;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = remapClipPos(clipPos);"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick flat normals fragment shader"),n.push("#extension GL_OES_standard_derivatives : enable"),e.logarithmicDepthBufferEnabled&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in int vFlags2;");for(var i=0;i 0;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(` outNormal = ivec4(worldNormal * float(${A.MAX_INT}), 1.0);`),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class pc{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._vertexDepthRenderer&&!this._vertexDepthRenderer.getValid()&&(this._vertexDepthRenderer.destroy(),this._vertexDepthRenderer=null),this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new $l(this._scene,!1)),this._colorRenderer}get colorRendererWithSAO(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new $l(this._scene,!0)),this._colorRendererWithSAO}get colorQualityRendererWithSAO(){return this._colorQualityRendererWithSAO||(this._colorQualityRendererWithSAO=new TrianglesDataTextureColorQualityRenderer(this._scene,!0)),this._colorQualityRendererWithSAO}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ro(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new nc(this._scene)),this._depthRenderer}get normalsRenderer(){return this._normalsRenderer||(this._normalsRenderer=new cc(this._scene)),this._normalsRenderer}get edgesRenderer(){return this._edgesRenderer||(this._edgesRenderer=new po(this._scene)),this._edgesRenderer}get edgesColorRenderer(){return this._edgesColorRenderer||(this._edgesColorRenderer=new mo(this._scene)),this._edgesColorRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Eo(this._scene)),this._pickMeshRenderer}get pickNormalsRenderer(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Wo(this._scene)),this._pickNormalsRenderer}get pickNormalsFlatRenderer(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new hc(this._scene)),this._pickNormalsFlatRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new _o(this._scene)),this._pickDepthRenderer}get vertexDepthRenderer(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new Mo(this._scene)),this._vertexDepthRenderer}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new ko(this._scene)),this._snapDepthBufInitRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Jo(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorQualityRendererWithSAO&&this._colorQualityRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._vertexDepthRenderer&&this._vertexDepthRenderer.destroy(),this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const Ac={};class dc{constructor(){this.positionsCompressed=[],this.metallicRoughness=[],this.indices8Bits=[],this.indices16Bits=[],this.indices32Bits=[],this.edgeIndices8Bits=[],this.edgeIndices16Bits=[],this.edgeIndices32Bits=[],this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]}}class fc{constructor(){this.texturePerObjectIdColorsAndFlags=null,this.texturePerObjectIdOffsets=null,this.texturePerObjectIdPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}finalize(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}bindCommonTextures(e,t,s,n,i,a){this.texturePerObjectIdPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,s,2),this.texturePerObjectIdColorsAndFlags.bindTexture(e,n,3),this.texturePerObjectIdOffsets.bindTexture(e,a,4)}bindTriangleIndicesTextures(e,t,s,n){this.indicesPortionIdsPerBitnessTextures[n].bindTexture(e,t,5),this.indicesPerBitnessTextures[n].bindTexture(e,s,6)}bindEdgeIndicesTextures(e,t,s,n){this.edgeIndicesPortionIdsPerBitnessTextures[n].bindTexture(e,t,5),this.edgeIndicesPerBitnessTextures[n].bindTexture(e,s,6)}}class Ic{constructor(e,t,s,n,i=null){this._gl=e,this._texture=t,this._textureWidth=s,this._textureHeight=n,this._textureData=i}bindTexture(e,t,s){return e.bindTexture(t,this,s)}bind(e){return this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,this._texture),!0}unbind(e){}}const yc={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(yc,null,4));let e=0;Object.keys(yc).forEach((t=>{t.startsWith("size")&&(e+=yc[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/yc.totalPolygons).toFixed(2)}`);let t={};Object.keys(yc).forEach((s=>{s.startsWith("size")&&(t[s]=`${(yc[s]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};class mc{disableBindedTextureFiltering(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}generateTextureForColorsAndFlags(e,t,s,n,i,a,r){const l=t.length;this.numPortions=l;const o=4096,c=Math.ceil(l/512);if(0===c)throw"texture height===0";const u=new Uint8Array(16384*c);yc.sizeDataColorsAndFlags+=u.byteLength,yc.numberOfTextures++;for(let e=0;e>24&255,n[e]>>16&255,n[e]>>8&255,255&n[e]],32*e+16),u.set([i[e]>>24&255,i[e]>>16&255,i[e]>>8&255,255&i[e]],32*e+20),u.set([a[e]>>24&255,a[e]>>16&255,a[e]>>8&255,255&a[e]],32*e+24),u.set([r[e]?1:0,0,0,0],32*e+28);const h=e.createTexture();return e.bindTexture(e.TEXTURE_2D,h),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,o,c),e.texSubImage2D(e.TEXTURE_2D,0,0,0,o,c,e.RGBA_INTEGER,e.UNSIGNED_BYTE,u,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new Ic(e,h,o,c,u)}generateTextureForObjectOffsets(e,t){const s=512,n=Math.ceil(t/s);if(0===n)throw"texture height===0";const i=new Float32Array(1536*n).fill(0);yc.sizeDataTextureOffsets+=i.byteLength,yc.numberOfTextures++;const a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,s,n),e.texSubImage2D(e.TEXTURE_2D,0,0,0,s,n,e.RGB,e.FLOAT,i,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new Ic(e,a,s,n,i)}generateTextureForPositionsDecodeMatrices(e,t,s){const n=t.length;if(0===n)throw"num decode+entity matrices===0";const i=2048,a=Math.ceil(n/512),r=new Float32Array(8192*a);yc.sizeDataPositionDecodeMatrices+=r.byteLength,yc.numberOfTextures++;const l=A.mat4();for(let e=0;e{s._compile()})),e.on("destroyed",(()=>{delete Ac[t],s._destroy()}))),s}(e.scene),this.model=e,this._buffer=new dc,this._dataTextureState=new fc,this._dataTextureGenerator=new mc,this._state=new ge({origin:A.vec3(t.origin),metallicRoughnessBuf:null,positionsDecodeMatrix:A.mat4(),textureState:this._dataTextureState,numIndices8Bits:0,numIndices16Bits:0,numIndices32Bits:0,numEdgeIndices8Bits:0,numEdgeIndices16Bits:0,numEdgeIndices32Bits:0,numVertices:0}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._subPortions=[],this._portionToSubPortionsMap=[],this._bucketGeometries={},this.aabb=A.collapseAABB3(),this._numUpdatesInFrame=0,this._finalized=!1}canCreatePortion(e){if(this._finalized)throw"Already finalized";const t=e.buckets.length;this._numPortions+t>65536&&yc.cannotCreatePortion.because10BitsObjectId++;let s=this._numPortions+t<=65536;const n=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#0`:`${e.id}#0`;if(!this._bucketGeometries[n]){const t=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits);let n=0,i=0;e.buckets.forEach((e=>{n+=e.positionsCompressed.length/3,i+=e.indices.length/3})),(this._state.numVertices+n>16777216||t+i>16777216)&&yc.cannotCreatePortion.becauseTextureSize++,s&&=this._state.numVertices+n<=16777216&&t+i<=16777216}return s}createPortion(e){if(this._finalized)throw"Already finalized";const t=[],s=e.worldAABB;e.buckets.forEach(((n,i)=>{const a=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#${i}`:`${e.id}#${i}`;let r=this._bucketGeometries[a];r||(r=this._createBucketGeometry(e,n),this._bucketGeometries[a]=r);const l=A.collapseAABB3(Ec),o=this._createSubPortion(e,r,n,l);A.expandAABB3(s,l),t.push(o)}));const n=this._state.origin;0===n[0]&&0===n[1]&&0===n[2]||(s[0]+=n[0],s[1]+=n[1],s[2]+=n[2],s[3]+=n[0],s[4]+=n[1],s[5]+=n[2]),A.expandAABB3(this.aabb,s);const i=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(t),this.model.numPortions++,i}_createBucketGeometry(e,t){if(t.indices){const e=8*Math.ceil(t.indices.length/3/8)*3;yc.overheadSizeAlignementIndices+=2*(e-t.indices.length);const s=new Uint32Array(e);s.fill(0),s.set(t.indices),t.indices=s}if(t.edgeIndices){const e=8*Math.ceil(t.edgeIndices.length/2/8)*2;yc.overheadSizeAlignementEdgeIndices+=2*(e-t.edgeIndices.length);const s=new Uint32Array(e);s.fill(0),s.set(t.edgeIndices),t.edgeIndices=s}const s=t.positionsCompressed,n=t.indices,i=t.edgeIndices,a=this._buffer,r=a.positionsCompressed.length/3,l=s.length/3;for(let e=0,t=s.length;e0){let e,s=3*t.numTriangles;t.numVertices<=256?(e=c.perTriangleNumberPortionId8Bits,u.numIndices8Bits+=s,yc.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(e=c.perTriangleNumberPortionId16Bits,u.numIndices16Bits+=s,yc.totalPolygons16Bits+=t.numTriangles):(e=c.perTriangleNumberPortionId32Bits,u.numIndices32Bits+=s,yc.totalPolygons32Bits+=t.numTriangles),yc.totalPolygons+=t.numTriangles;for(let s=0;s0){let e,s=2*t.numEdges;t.numVertices<=256?(e=c.perEdgeNumberPortionId8Bits,u.numEdgeIndices8Bits+=s,yc.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(e=c.perEdgeNumberPortionId16Bits,u.numEdgeIndices16Bits+=s,yc.totalEdges16Bits+=t.numEdges):(e=c.perEdgeNumberPortionId32Bits,u.numEdgeIndices32Bits+=s,yc.totalEdges32Bits+=t.numEdges),yc.totalEdges+=t.numEdges;for(let s=0;s0&&(t.texturePerEdgeIdPortionIds8Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId8Bits)),n.perEdgeNumberPortionId16Bits.length>0&&(t.texturePerEdgeIdPortionIds16Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId16Bits)),n.perEdgeNumberPortionId32Bits.length>0&&(t.texturePerEdgeIdPortionIds32Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(s,n.perEdgeNumberPortionId32Bits)),n.indices8Bits.length>0&&(t.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(s,n.indices8Bits)),n.indices16Bits.length>0&&(t.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(s,n.indices16Bits)),n.indices32Bits.length>0&&(t.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(s,n.indices32Bits)),n.edgeIndices8Bits.length>0&&(t.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(s,n.edgeIndices8Bits)),n.edgeIndices16Bits.length>0&&(t.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(s,n.edgeIndices16Bits)),n.edgeIndices32Bits.length>0&&(t.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(s,n.edgeIndices32Bits)),t.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(()=>{this._deferredSetFlagsDirty&&this._uploadDeferredFlags(),this._numUpdatesInFrame=0}))}isEmpty(){return 0===this._numPortions}initFlags(e,t,s){t&F&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&k&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Q&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&G&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&W&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&U&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&H&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,true),this._setFlags2(e,t,true)}flushInitFlags(){this._setDeferredFlags(),this._setDeferredFlags2()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&W?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&G?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}_beginDeferredFlags(){this._deferredSetFlagsActive=!0}_uploadDeferredFlags(){if(console.info("_uploadDeferredFlags"),this._deferredSetFlagsActive=!1,!this._deferredSetFlagsDirty)return;this._deferredSetFlagsDirty=!1;const e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdColorsAndFlags._textureWidth,t.texturePerObjectIdColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectIdColorsAndFlags._textureData),e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdOffsets._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdOffsets._textureWidth,t.texturePerObjectIdOffsets._textureHeight,e.RGB,e.FLOAT,t.texturePerObjectIdOffsets._textureData)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){const s=this._portionToSubPortionsMap[e];for(let e=0,n=s.length;e=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),n.bindTexture(n.TEXTURE_2D,s.texturePerObjectIdColorsAndFlags._texture),n.texSubImage2D(n.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,n.RGBA_INTEGER,n.UNSIGNED_BYTE,gc)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s,n=!1){const i=this._portionToSubPortionsMap[e];for(let e=0,a=i.length;e=10&&this._beginDeferredFlags(),d.bindTexture(d.TEXTURE_2D,A.texturePerObjectIdColorsAndFlags._texture),d.texSubImage2D(d.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,d.RGBA_INTEGER,d.UNSIGNED_BYTE,gc))}_setDeferredFlags(){}_setFlags2(e,t,s=!1){const n=this._portionToSubPortionsMap[e];for(let e=0,i=n.length;e=10&&this._beginDeferredFlags(),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectIdColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,gc))}_setDeferredFlags2(){}setOffset(e,t){const s=this._portionToSubPortionsMap[e];for(let e=0,n=s.length;e=10&&this._beginDeferredFlags(),n.bindTexture(n.TEXTURE_2D,s.texturePerObjectIdOffsets._texture),n.texSubImage2D(n.TEXTURE_2D,0,0,e,1,1,n.RGB,n.FLOAT,Tc))}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?this._dataTextureRenderers.colorRendererWithSAO&&this._dataTextureRenderers.colorRendererWithSAO.drawLayer(t,this,Bi.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}_updateBackfaceCull(e,t){const s=this.model.backfaces||e.sectioned;if(t.backfaces!==s){const e=t.gl;s?e.disable(e.CULL_FACE):e.enable(e.CULL_FACE),t.backfaces=s}}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Bi.COLOR_TRANSPARENT))}drawDepth(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.depthRenderer&&this._dataTextureRenderers.depthRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}drawNormals(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.normalsRenderer&&this._dataTextureRenderers.normalsRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_XRAYED))}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_HIGHLIGHTED))}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Bi.SILHOUETTE_SELECTED))}drawEdgesColorOpaque(e,t){this.model.scene.logarithmicDepthBufferEnabled?this.model.scene._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),this.model.scene._loggedWarning=!0):this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Bi.EDGES_COLOR_OPAQUE)}drawEdgesColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Bi.EDGES_COLOR_TRANSPARENT)}drawEdgesHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Bi.EDGES_HIGHLIGHTED)}drawEdgesSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Bi.EDGES_SELECTED)}drawEdgesXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Bi.EDGES_XRAYED)}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.occlusionRenderer&&this._dataTextureRenderers.occlusionRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}drawShadow(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.shadowRenderer&&this._dataTextureRenderers.shadowRenderer.drawLayer(t,this,Bi.COLOR_OPAQUE))}setPickMatrices(e,t){}drawPickMesh(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickMeshRenderer&&this._dataTextureRenderers.pickMeshRenderer.drawLayer(t,this,Bi.PICK))}drawPickDepths(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,Bi.PICK))}drawSnapInitDepthBuf(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.snapDepthBufInitRenderer&&this._dataTextureRenderers.snapDepthBufInitRenderer.drawLayer(t,this,Bi.PICK))}drawSnapDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.vertexDepthRenderer&&this._dataTextureRenderers.vertexDepthRenderer.drawLayer(t,this,Bi.PICK))}drawPickNormals(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickNormalsRenderer&&this._dataTextureRenderers.pickNormalsRenderer.drawLayer(t,this,Bi.PICK))}destroy(){if(this._destroyed)return;const e=this._state;e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}const Rc=A.vec3();A.mat4();const Cc=A.vec3([1,1,1]),_c=A.vec3([0,0,0]),Bc=A.vec3([0,0,0]),Oc=A.identityQuaternion(),Sc=A.identityMat4(),Nc=new Uint8Array([255,255,255]);class xc extends B{constructor(e,t={}){super(e,t),this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!0,this._vboBatchingLayerScratchMemory=(_i++,Ci),this._textureTranscoder=t.textureTranscoder||Fl(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize,this._aabb=A.collapseAABB3(),this._aabbDirty=!0,this._quantizationRanges={},this._vboInstancingLayers={},this._vboBatchingLayers={},this._dtxLayers={},this._meshList=[],this.layerList=[],this._entityList=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this._scheduledMeshes={},this.renderFlags=new on,this.numGeometries=0,this.numPortions=0,this.numVisibleLayerPortions=0,this.numTransparentLayerPortions=0,this.numXRayedLayerPortions=0,this.numHighlightedLayerPortions=0,this.numSelectedLayerPortions=0,this.numEdgesLayerPortions=0,this.numPickableLayerPortions=0,this.numClippableLayerPortions=0,this.numCulledLayerPortions=0,this.numEntities=0,this._numTriangles=0,this._numLines=0,this._numPoints=0,this._edgeThreshold=t.edgeThreshold||10,this._origin=A.vec3(t.origin||[0,0,0]),this._position=A.vec3(t.position||[0,0,0]),this._rotation=A.vec3(t.rotation||[0,0,0]),this._quaternion=A.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=A.vec4(t.quaternion||[0,0,0,1]),t.rotation&&A.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=A.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=A.mat4(),this._worldRotationMatrixConjugate=A.mat4(),this._matrix=A.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=A.mat4(),A.inverseMat4(this._matrix,this._worldNormalMatrix),A.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=A.mat4(),this._viewNormalMatrix=A.mat4(),this._viewMatrixDirty=!0,this._matrixNonIdentity=!0),this._opacity=1,this._colorize=[1,1,1],this._saoEnabled=!1!==t.saoEnabled,this._pbrEnabled=!1!==t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{this._viewMatrixDirty=!0})),this.scene.vfc.enabled&&(this._vfcManager=this.scene.vfc.getVFCManager(this)),this._createDefaultTextureSet(),this.visible=t.visible,this.culled=t.culled,this.pickable=t.pickable,this.clippable=t.clippable,this.collidable=t.collidable,this.castsShadow=t.castsShadow,this.receivesShadow=t.receivesShadow,this.xrayed=t.xrayed,this.highlighted=t.highlighted,this.selected=t.selected,this.edges=t.edges,this.colorize=t.colorize,this.opacity=t.opacity,this.backfaces=t.backfaces}_createDefaultTextureSet(){const e=new Pl({id:"defaultColorTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Pl({id:"defaultMetalRoughTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),s=new Pl({id:"defaultNormalsTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),n=new Pl({id:"defaultEmissiveTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new Pl({id:"defaultOcclusionTexture",texture:new Cn({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=s,this._textures.defaultEmissiveTexture=n,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new Dl({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:s,emissiveTexture:n,occlusionTexture:i})}get isPerformanceModel(){return!0}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),A.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),A.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||Sc),A.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),A.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),A.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),A.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}get matrix(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(A.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),A.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),A.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),A.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}get rotationMatrixConjugate(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0}_setLocalAABBDirty(){for(let e=0,t=this._entityList.length;e0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,s=this._entityList.length;t0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,n=t.length;e{o.setImage(c,{minFilter:s,magFilter:n,wrapS:i,wrapT:a,wrapR:r,flipY:e.flipY,encoding:l}),this.glRedraw()},c.src=e.src;break;default:this._textureTranscoder?v.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],o).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,o).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new Pl({id:t,texture:o})}createTextureSet(e){const t=e.id;if(null==t)return void this.error("[createTextureSet] Config missing: id");if(this._textureSets[t])return void this.error(`[createTextureSet] Texture set already created: ${t}`);let s,n,i,a,r;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(s=this._textures[e.colorTextureId],!s)return void this.error(`[createTextureSet] Texture not found: ${e.colorTextureId} - ensure that you create it first with createTexture()`)}else s=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(n=this._textures[e.metallicRoughnessTextureId],!n)return void this.error(`[createTextureSet] Texture not found: ${e.metallicRoughnessTextureId} - ensure that you create it first with createTexture()`)}else n=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(i=this._textures[e.normalsTextureId],!i)return void this.error(`[createTextureSet] Texture not found: ${e.normalsTextureId} - ensure that you create it first with createTexture()`)}else i=this._textures.defaultNormalsTexture;if(void 0!==e.emissiveTextureId&&null!==e.emissiveTextureId){if(a=this._textures[e.emissiveTextureId],!a)return void this.error(`[createTextureSet] Texture not found: ${e.emissiveTextureId} - ensure that you create it first with createTexture()`)}else a=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(r=this._textures[e.occlusionTextureId],!r)return void this.error(`[createTextureSet] Texture not found: ${e.occlusionTextureId} - ensure that you create it first with createTexture()`)}else r=this._textures.defaultOcclusionTexture;const l=new Dl({id:t,model:this,colorTexture:s,metallicRoughnessTexture:n,normalsTexture:i,emissiveTexture:a,occlusionTexture:r});this._textureSets[t]=l}createMesh(e){if(void 0===e.id||null===e.id)return void this.error("[createMesh] SceneModel.createMesh() config missing: id");if(this._scheduledMeshes[e.id])return void this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`);if(!(void 0!==e.geometryId)){if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"!==e.primitive&&"lines"!==e.primitive&&"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive)return void this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`);if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),null;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),null;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`Param expected: indices (required for '${e.primitive}' primitive type)`),null;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),null;const t=!!this._dtxEnabled&&("triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive);if(e.origin=e.origin?A.addVec3(this._origin,e.origin,A.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){const t=e.scale||Cc,s=e.position||_c,n=e.rotation||Bc;A.eulerToQuaternion(n,"XYZ",Oc),e.meshMatrix=A.composeMat4(s,Oc,t,A.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Aa(e.positionsDecodeBoundary,A.mat4())),t){if(e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):Nc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){const t=A.vec3(),s=[];x(e.positions,s,t)&&(e.positions=s,e.origin=A.addVec3(e.origin,t,t))}if(e.positions){const t=A.collapseAABB3();e.positionsDecodeMatrix=A.mat4(),A.expandAABB3Points3(t,e.positions),e.positionsCompressed=pa(e.positions,t,e.positionsDecodeMatrix)}e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Ee(e.positions,e.indices,null,2):e.edgeIndices=Ee(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=Lc(e,this._enableVertexWelding&&this._enableIndexBucketing))}else{if(e.type=1,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):[255,255,255],e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.positions){const t=[];x(e.positions,t,Rc)&&(e.positions=t,e.origin=A.addVec3(e.origin,Rc,A.vec3()))}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Ee(e.positions,e.indices,null,2):e.edgeIndices=Ee(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId],!e.textureSet))return void this.error(`[createMesh] Texture set not found: ${e.textureSetId} - ensure that you create it first with createTextureSet()`)}}else{if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return void this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)");if(e.geometry=this._geometries[e.geometryId],!e.geometry)return void this.error(`[createMesh] Geometry not found: ${e.geometryId} - ensure that you create it first with createGeometry()`);if(e.origin=e.origin?A.addVec3(this._origin,e.origin,A.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.matrix)e.meshMatrix=e.matrix.slice();else{const t=e.scale||Cc,s=e.position||_c,n=e.rotation||Bc;A.eulerToQuaternion(n,"XYZ",Oc),e.meshMatrix=A.composeMat4(s,Oc,t,A.mat4())}if(!!this._dtxEnabled&&("triangles"===e.geometry.primitive||"solid"===e.geometry.primitive||"surface"===e.geometry.primitive)){e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):Nc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;let t=this._dtxBuckets[e.geometryId];t||(t=Lc(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=t),e.buckets=t}else e.type=0,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):Nc,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId]),function(e){if(e.obb=A.OBB3(),e.positionsCompressed&&e.positionsCompressed.length>0){const t=A.collapseAABB3();A.expandAABB3Points3(t,e.positionsCompressed),Be.decompressAABB(t,e.positionsDecodeMatrix),A.AABB3ToOBB3(t,e.obb)}else if(e.positions&&e.positions.length>0){const t=A.collapseAABB3();A.expandAABB3Points3(t,e.positions),A.AABB3ToOBB3(t,e.obb)}}(e.geometry)}e.numPrimitives=this._getNumPrimitives(e),this._vfcManager&&!this._vfcManager.finalized?this._vfcManager.addMesh(e):this._createMesh(e)}_createMesh(e){const t=new Ri(this,e.id,e.color,e.opacity);t.pickId=this.scene._renderer.getPickID(t);const s=t.pickId,n=s>>24&255,i=s>>16&255,a=s>>8&255,r=255&s;switch(e.pickColor=new Uint8Array([r,a,i,n]),e.worldAABB=A.collapseAABB3(),e.aabb=e.worldAABB,e.solid="solid"===e.primitive,t.origin=A.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e);break;case 1:t.layer=this._getVBOBatchingLayer(e);break;case 0:t.layer=this._getVBOInstancingLayer(e)}t.portionId=t.layer.createPortion(e),t.aabb=e.worldAABB,t.numPrimitives=e.numPrimitives,A.expandAABB3(this._aabb,t.aabb),this._meshes[e.id]=t,this._meshList.push(t)}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let s=0,n=e.buckets.length;s>>0).toString(16)}_getVBOInstancingLayer(e){const t=this,s=e.origin,n=e.textureSetId||"-",i=e.geometryId,a=`${Math.round(s[0])}.${Math.round(s[1])}.${Math.round(s[2])}.${n}.${i}`;let r=this._vboInstancingLayers[a];if(r)return r;let l=e.textureSet;const o=e.geometry;for(;!r;)switch(o.primitive){case"triangles":case"surface":console.info(`[SceneModel ${this.id}]: creating TrianglesInstancingLayer`),r=new Sr({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0,solid:!1});break;case"solid":console.info(`[SceneModel ${this.id}]: creating TrianglesInstancingLayer`),r=new Sr({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0,solid:!0});break;case"lines":console.info(`[SceneModel ${this.id}]: creating LinesInstancingLayer`),r=new qr({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0});break;case"points":console.info(`[SceneModel ${this.id}]: creating PointsInstancingLayer`),r=new bl({model:t,textureSet:l,geometry:o,origin:s,layerIndex:0})}return this._vboInstancingLayers[a]=r,this.layerList.push(r),r}createEntity(e){if(void 0===e.id?e.id=A.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=A.createUUID()),void 0===e.meshIds)return void this.error("Config missing: meshIds");let t=0;if(this._visible&&!1!==e.visible&&(t|=F),this._pickable&&!1!==e.pickable&&(t|=U),this._culled&&!1!==e.culled&&(t|=H),this._clippable&&!1!==e.clippable&&(t|=G),this._collidable&&!1!==e.collidable&&(t|=j),this._edges&&!1!==e.edges&&(t|=W),this._xrayed&&!1!==e.xrayed&&(t|=V),this._highlighted&&!1!==e.highlighted&&(t|=k),this._selected&&!1!==e.selected&&(t|=Q),e.flags=t,this._vfcManager&&!this._vfcManager.finalized){for(let t=0,s=e.meshIds.length;t{}));for(let e=0,t=this.layerList.length;ee.sortIdt.sortId?1:0));for(let e=0,t=this.layerList.length;e0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,s=this.layerList.length;t0)for(let e=0;e0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}drawColorOpaque(e){const t=this.renderFlags;for(let s=0,n=t.visibleLayers.length;s65536?16:8)}else r=[{positionsCompressed:n,indices:i,edgeIndices:a}];return r}class Mc extends xc{constructor(e,t={}){super(e,t)}}class Fc extends B{get type(){return"SectionPlane"}constructor(e,t={}){super(e,t),this._state=new ge({active:!0,pos:A.vec3(),dir:A.vec3(),dist:0}),this.active=t.active,this.pos=t.pos,this.dir=t.dir,this.scene._sectionPlaneCreated(this)}set active(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}get active(){return this._state.active}set pos(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-A.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos)}get pos(){return this._state.pos}set dir(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-A.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir)}get dir(){return this._state.dir}get dist(){return this._state.dist}flipDir(){const e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-A.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}destroy(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),super.destroy()}}class Hc extends B{constructor(e,t={}){super(e,t),this._skyboxMesh=new vn(this,{geometry:new Ne(this,{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new bn(this,{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new xn(this,{src:t.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:t.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),this.size=t.size,this.active=t.active}set size(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}get size(){return this._size}set active(e){this._skyboxMesh.visible=e}get active(){return this._skyboxMesh.visible}}class Uc{transcode(e,t,s={}){}destroy(){}}class Gc{constructor(e,t){this.primLODLevels=e,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=t,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}initializeLodState(e){const t=Object.values(e.objects);if(0===t.length)return;const s={},n={};for(let e=0,i=t.length;e=this.primLODLevels[r]);r++);const l=this.primLODLevels[r]||0;l in s||(s[l]=[]),s[l].push(i),l in n||(n[l]=0),n[l]+=i.numPrimitives}this.entitiesInLOD=s,this.primCountInLOD=n}}class jc{constructor(e,t,s,n){this.id=t.id,this.scene=e,this.sceneModel=t,this.lodState=new Gc(s,n),this.lodState.initializeLodState(t)}_increaseLODLevelIndex(){const e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;const t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[];for(let e=0,s=t.length;e0&&(t.consecutiveFramesWithoutTargetFps=0,s=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,s=this._decreaseLODLevelIndex()),s}resetLodCulling(){let e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}class Vc extends B{constructor(e,t={}){super(e,t),this._scene=e,this._lodLevels=[2e3,600,150,80,20],this._lodManagers={},this._lodManagerList=[],this.enabled=t.enabled,this.targetFPS=t.targetFPS,this._init()}_init(){const e=new Array(4);let t=0,s=-1,n=Date.now(),i=0,a=0,r=a;this._scene.on("rendering",(()=>{if(-1!==s)for(let e=0,t=this._lodManagerList.length;e{n=Date.now(),window.requestAnimationFrame((()=>{t++;const a=Date.now();i=a-n,n=a,e[t%4]=i;let r=0;if(t>4){for(let t=0;t<4;t++)r+=e[t];s=4/r*1e3}}))})),this._scene.camera.on("matrix",(()=>{r=a})),this._scene.on("tick",(()=>{if(a-r>3)for(let e=0,t=this._lodManagerList.length;e=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},s.boxRayIntersects=function(e,t,s,n,i,a,r){var l=(e.minX-t)*i,o=(e.maxX-t)*i,c=(e.minY-s)*a,u=(e.maxY-s)*a,h=(e.minZ-n)*r,p=(e.maxZ-n)*r,A=Math.min(h,p),d=Math.max(h,p),f=Math.min(c,u),I=Math.max(c,u),y=Math.min(l,o),m=Math.max(l,o),v=Math.max(0,y,f,A);return Math.min(m,I,d)>=v?v:1/0};var g=function(e,t,s,i,a){for(var r,l=[t,s];l.length;)(s=l.pop())-(t=l.pop())<=i||(r=t+Math.ceil((s-t)/i/2)*i,n(e,r,t,s,a),l.push(t,r,r,s))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var s=this.data,n=[];if(!e(s,h(s)))return n;for(var i=[];s;){for(var a=0,r=s.children.length;a1){for(d=0,f=(u=u[u.length-1]).length;d=t)break;var i=n+1;if(i0;){var n=s-1>>1;if(A[n].dist<=A[s].dist)break;d(s,n),s=n}},y=l;A.length&&A[0].dist=t;l--){o=e.children[l];f(a,o),r+=y(a)}return r},e.prototype.adjustParentBBoxes=function(e,t,s){for(var n=s;n>=0;n--)f(t[n],e)},e.prototype.condense=function(e){for(var t=e.length-1,s=void 0;t>=0;t--)0===e[t].children.length?t>0?((s=e[t-1].children).splice(s.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,s){var n=[],i=this.chooseSubtree(e,this.data,t,n);for(i.children.push(e),f(i,e);t>=0&&n[t].children.length>this.maxEntries;)this.split(n,t),t--;this.adjustParentBBoxes(e,n,t)},e.pool=[],e}();s.RBush3D=D},{quickselect:2}],2:[function(e,t,s){!function(e,n){"object"==typeof s&&void 0!==t?t.exports=n():e.quickselect=n()}(this,(function(){function e(s,n,i,a,r){for(;a>i;){if(a-i>600){var l=a-i+1,o=n-i+1,c=Math.log(l),u=.5*Math.exp(2*c/3),h=.5*Math.sqrt(c*u*(l-u)/l)*(o-l/2<0?-1:1);e(s,n,Math.max(i,Math.floor(n-o*u/l+h)),Math.min(a,Math.floor(n+(l-o)*u/l+h)),r)}var p=s[n],A=i,d=a;for(t(s,i,n),r(s[a],p)>0&&t(s,i,a);A0;)d--}0===r(s[i],p)?t(s,i,d):t(s,++d,a),d<=n&&(i=d+1),n<=d&&(a=d-1)}}function t(e,t,s){var n=e[t];e[t]=e[s],e[s]=n}function s(e,t){return et?1:0}return function(t,n,i,a,r){e(t,n,i||0,a||t.length-1,r||s)}}))},{}]},{},[1])(1)}));var Wc=kc.exports.RBush3D,zc=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function s(e,t){var s={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function n(){(0==s.dir&&s.pos.x+1>=s.right||1==s.dir&&s.pos.y+1>=s.bottom||2==s.dir&&s.pos.x-1<=s.left-1||3==s.dir&&s.pos.y-1<=s.top-1)&&(s.dir=(s.dir+1)%4,0==s.dir&&s.left++,1==s.dir&&s.top++,2==s.dir&&s.right--,3==s.dir&&s.bottom--),0==s.dir&&s.pos.x++,1==s.dir&&s.pos.y++,2==s.dir&&s.pos.x--,3==s.dir&&s.pos.y--}for(var i=[],a=e*t;i.lengthp&&(u.push(h),h=[],p=l),h.push(d),p-=f}}while(Ap&&(u.push(A),A=[],p=l),A.push(e),p-=s})),A.length&&u.push(A);var d={};return u.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:u,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,n.maxPolygonsPerCluster),{clusters:{total:r.clusters.length},clusteringResult:r});l+=o.clusters.total,console.log("Total clusters: "+l);var c=[];return o.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){c.push(e.id)}))})),o.orderedEntityIds=c,o}; /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT @@ -23,7 +23,7 @@ class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){ * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT */ -function Kc(e,t){t.length;const s=e.length,n=[],i=[],a=e=>{for(let s=0,n=e.meshIds.length;s{const s=t[e];let n,i;if(s.positionsCompressed){const e=Be.getPositionsBounds(s.positionsCompressed);n=Be.decompressPosition(e.min,s.positionsDecodeMatrix,[]),i=Be.decompressPosition(e.max,s.positionsDecodeMatrix,[])}else{const e=Be.getPositionsBounds(s.positions);n=e.min,i=e.max}n[0]+=s.origin[0],n[1]+=s.origin[1],n[2]+=s.origin[2],i[0]+=s.origin[0],i[1]+=s.origin[1],i[2]+=s.origin[2],A.expandAABB3Point3(l,n),A.expandAABB3Point3(l,i),o+=s.numPrimitives})),n[r]={aabb:l,numPrimitives:o,entityId:s.id}}let r,l=[],o={};if(Object.keys(n).length>0){r=function(e){const t=[];for(let s=0,n=e.length;s{s=Math.max(s,e.entity.id)}));const n=new Array(s+1);t.forEach((t=>{n[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=n,this._lastVisibleFrameOfNodes=new Array(n.length),this._lastVisibleFrameOfNodes.fill(0)}_searchVisibleNodesWithFrustumCulling(){return this._aabbTree.searchCustom(((e,t)=>this._aabbIntersectsCameraFrustum(e,t)),(e=>this._aabbContainedInCameraFrustum(e)))}_markVisibleFrameOfVisibleNodes(e,t){const s=this._lastVisibleFrameOfNodes;for(let n=0,i=e.length;nthis._frustumProps.CAM_FACTOR_1?(s|=r<0?64:128,s&=-17):s&=-33;const l=Jc(A.dotVec3(i,this._frustumProps.up),a);Math.abs(l)>this._frustumProps.CAM_FACTOR_2?(s|=l<0?1024:2048,s&=-257):s&=-513}return 4&s&&8&s&&(s|=4096),64&s&&128&s&&(s|=8192),1024&s&&2048&s&&(s|=16384),e._check=s,s}}class $c{constructor(e,t){this.sceneModel=t,this.entities=[],this.meshes=[],this.finalized=!1}addEntity(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}addMesh(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}finalize(e){if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new Zc,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(()=>this.applyViewFrustumCulling.call(this)))}applyViewFrustumCulling(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}destroy(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}class eu extends B{constructor(e,t={}){super(e,t),this._scene=e,this._vfcManagers={},this._vfcManagerList=[],this.enabled=t.enabled,this._init()}_init(){this._scene.on("rendering",(()=>{for(let e=0,t=this._vfcManagerList.length;e
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const su=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class nu extends B{constructor(e,t={}){super(e,t),this._backgroundColor=A.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new tu(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+A.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new ru(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new ru(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new _s(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=A.mat4();return()=>(e&&A.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,h=this._getInverseProjectMat(),p=Math.random(),d="perspective"===n.camera.projection;uu[0]=a,uu[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,h),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,uu),t.uniform1f(this._uRandomSeed,p);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new _s(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new Te(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new Te(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new Te(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const pu=new Float32Array(mu(17,[0,1])),Au=new Float32Array(mu(17,[1,0])),du=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(yu(n,t));return s}(17,4)),fu=new Float32Array(2);class Iu{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new _s(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new Te(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new Te(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new Te(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=A.mat4();return()=>(e&&A.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),fu[0]=r,fu[1]=l,n.uniform2fv(this._uViewport,fu),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,Au):n.uniform2fv(this._uSampleOffsets,pu),n.uniform1fv(this._uSampleWeights,du);const h=e.getDepthTexture(),p=t.getTexture();i.bindTexture(this._uDepthTexture,h,0),i.bindTexture(this._uOcclusionTexture,p,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function yu(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function mu(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class vu{constructor(e){this.scene=e,this._renderBuffersBasic={},this._renderBuffersScaled={}}getRenderBuffer(e,t){const s=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled;let n=s[e];return n||(n=new si(this.scene.canvas.canvas,this.scene.canvas.gl,t),s[e]=n),n}destroy(){for(let e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(let e in this._renderBuffersScaled)this._renderBuffersScaled[e].destroy()}}const wu=function(t,s){s=s||{};const n=new iu(t),i=t.canvas.canvas,a=t.canvas.gl,r=!!s.transparent,l=s.alphaDepthMask,o=new e({});let c={},u={},h=!0,p=!0,d=!0,I=!0,y=!0,m=!0,v=!0,w=!0;const g=new vu(t);let T=!1;const E=new hu(t),b=new Iu(t);function D(){h&&(!function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e],s=t.drawableMap,n=t.drawableListPreCull;let i=0;for(let e in s)s.hasOwnProperty(e)&&(n[i++]=s[e]);n.length=i}}(),h=!1,p=!0),p&&(!function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),p=!1,d=!0),d&&function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e],s=t.drawableListPreCull,n=t.drawableList;let i=0;for(let e=0,t=s.length;e0)for(n.withSAO=!0,S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||k>0||H>0||U>0){if(a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):(a.blendEquation(a.FUNC_ADD),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,l||a.depthMask(!1),(H>0||U>0)&&a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),U>0)for(S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||W>0){if(n.lastProgramId=null,t.highlightMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),W>0)for(S=0;S0)for(S=0;S0||K>0||Q>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.enable(a.CULL_FACE),K>0)for(S=0;S0)for(S=0;S0||X>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),X>0)for(S=0;S0)for(S=0;S0||J>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),J>0)for(S=0;S0)for(S=0;S0){const t=Math.floor(e/4),s=l.size[0],n=t%s-Math.floor(s/2),a=Math.floor(t/s)-Math.floor(s/2),o=Math.sqrt(Math.pow(n,2)+Math.pow(a,2));v.push({x:n,y:a,dist:o,isVertex:i&&r?f[e+3]>d.length/2:i,result:[f[e+0],f[e+1],f[e+2],f[e+3]]})}let w=null,T=null;if(v.length>0){v.sort(((e,t)=>e.isVertex!==t.isVertex?e.isVertex?-1:1:e.dist-t.dist)),T=v[0].isVertex?"vertex":"edge",v=v[0].result;const e=d[v[3]],t=e.origin,s=e.coordinateScale;w=[v[0]*s[0]+t[0],v[1]*s[1]+t[1],v[2]*s[2]+t[2]]}if(null===I&&null==w)return null;let E=null;return null!==w&&(E=t.camera.projectWorldPos(w)),{snapType:T,snappedToVertex:"vertex"===T,snappedToEdge:"edge"===T,worldPos:I,snappedWorldPos:w,snappedCanvasPos:E}},this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new cu(t,g),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){D(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight),a.clearColor(0,0,0,0),a.enable(a.DEPTH_TEST),a.disable(a.CULL_FACE),a.disable(a.BLEND),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT);for(let e in c)if(c.hasOwnProperty(e)){const t=c[e].drawableList;for(let e=0,s=t.length;e{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("mousemove",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=(e,t)=>{if(!this.enabled)return;const s=Math.max(-1,Math.min(1,40*-e.deltaY));this.fire("mousewheel",s,!0)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(n=>{e>=n[0]-s&&e<=n[0]+s&&t>=n[1]-s&&t<=n[1]+s&&this.fire("mouseclicked",n,!0)}))}this._eventsBound=!0}}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getMouseCanvasPos(e){if(e){let t=e.target,s=0,n=0;for(;t.offsetParent;)s+=t.offsetLeft,n+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-s,this.mouseCanvasPos[1]=e.pageY-n}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}class Tu extends B{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new ge({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class Eu extends B{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ge({matrix:A.mat4(),inverseMatrix:A.mat4(),transposedMatrix:A.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.canvas.boundary,t=e[2]/e[3],s=this._fovAxis;let n=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(n/=t),n=Math.min(n,120),A.perspectiveMat4(n*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(A.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(A.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,A.mulMat4v4(this.inverseMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,A.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class bu extends B{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ge({matrix:A.mat4(),inverseMatrix:A.mat4(),transposedMatrix:A.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.canvas.boundary,n=s[2],i=s[3],a=n/i;let r,l,o,c;n>i?(r=-t,l=t,o=t/a,c=-t/a):(r=-t*a,l=t*a,o=t,c=-t),A.orthoMat4c(r,l,c,o,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(A.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(A.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,A.mulMat4v4(this.inverseMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,A.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class Du extends B{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ge({matrix:A.mat4(),inverseMatrix:A.mat4(),transposedMatrix:A.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){A.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(A.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(A.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,A.mulMat4v4(this.inverseMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,A.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class Pu extends B{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ge({matrix:A.mat4(),inverseMatrix:A.mat4(),transposedMatrix:A.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(A.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(A.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,A.mulMat4v4(this.inverseMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,A.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy()}}const Ru=A.vec3(),Cu=A.vec3(),_u=A.vec3(),Bu=A.vec3(),Ou=A.vec3(),Su=A.vec3(),Nu=A.vec4(),xu=A.vec4(),Lu=A.vec4(),Mu=A.mat4(),Fu=A.mat4(),Hu=A.vec3(),Uu=A.vec3(),Gu=A.vec3(),ju=A.vec3();class Vu extends B{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new ge({deviceMatrix:A.mat4(),hasDeviceMatrix:!1,matrix:A.mat4(),normalMatrix:A.mat4(),inverseMatrix:A.mat4()}),this._perspective=new Eu(this),this._ortho=new bu(this),this._frustum=new Du(this),this._customProjection=new Pu(this),this._project=this._perspective,this._eye=A.vec3([0,0,10]),this._look=A.vec3([0,0,0]),this._up=A.vec3([0,1,0]),this._worldUp=A.vec3([0,1,0]),this._worldRight=A.vec3([1,0,0]),this._worldForward=A.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection?(A.subVec3(this._eye,this._look,Hu),A.normalizeVec3(Hu,Uu),A.mulVec3Scalar(Uu,1e3,Gu),A.addVec3(this._look,Gu,ju),t=ju):t=this._eye,e.hasDeviceMatrix?(A.lookAtMat4v(t,this._look,this._up,Fu),A.mulMat4(e.deviceMatrix,Fu,e.matrix)):A.lookAtMat4v(t,this._look,this._up,e.matrix),A.inverseMat4(this._state.matrix,this._state.inverseMatrix),A.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=A.subVec3(this._eye,this._look,Ru);A.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Mu),t=A.transformPoint3(Mu,t,Cu),this.eye=A.addVec3(this._look,t,_u),this.up=A.transformPoint3(Mu,this._up,Bu)}orbitPitch(e){if(this._constrainPitch&&(e=A.dotVec3(this._up,this._worldUp)/A.DEGTORAD)<1)return;let t=A.subVec3(this._eye,this._look,Ru);const s=A.cross3Vec3(A.normalizeVec3(t,Cu),A.normalizeVec3(this._up,_u));A.rotationMat4v(.0174532925*e,s,Mu),t=A.transformPoint3(Mu,t,Bu),this.up=A.transformPoint3(Mu,this._up,Ou),this.eye=A.addVec3(t,this._look,Su)}yaw(e){let t=A.subVec3(this._look,this._eye,Ru);A.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Mu),t=A.transformPoint3(Mu,t,Cu),this.look=A.addVec3(t,this._eye,_u),this._gimbalLock&&(this.up=A.transformPoint3(Mu,this._up,Bu))}pitch(e){if(this._constrainPitch&&(e=A.dotVec3(this._up,this._worldUp)/A.DEGTORAD)<1)return;let t=A.subVec3(this._look,this._eye,Ru);const s=A.cross3Vec3(A.normalizeVec3(t,Cu),A.normalizeVec3(this._up,_u));A.rotationMat4v(.0174532925*e,s,Mu),this.up=A.transformPoint3(Mu,this._up,Su),t=A.transformPoint3(Mu,t,Bu),this.look=A.addVec3(t,this._eye,Ou)}pan(e){const t=A.subVec3(this._eye,this._look,Ru),s=[0,0,0];let n;if(0!==e[0]){const i=A.cross3Vec3(A.normalizeVec3(t,[]),A.normalizeVec3(this._up,Cu));n=A.mulVec3Scalar(i,e[0]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]}0!==e[1]&&(n=A.mulVec3Scalar(A.normalizeVec3(this._up,_u),e[1]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),0!==e[2]&&(n=A.mulVec3Scalar(A.normalizeVec3(t,Bu),e[2]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),this.eye=A.addVec3(this._eye,s,Ou),this.look=A.addVec3(this._look,s,Su)}zoom(e){const t=A.subVec3(this._eye,this._look,Ru),s=Math.abs(A.lenVec3(t,Cu)),n=Math.abs(s+e);if(n<.5)return;const i=A.normalizeVec3(t,_u);this.eye=A.addVec3(this._look,A.mulVec3Scalar(i,n),Bu)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=A.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return A.lenVec3(A.subVec3(this._look,this._eye,Ru))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}projectWorldPos(e){const t=Nu,s=xu,n=Lu;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,A.mulMat4v4(this.viewMatrix,t,s),A.mulMat4v4(this.projMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1;const i=this.scene.canvas.canvas,a=i.offsetWidth/2,r=i.offsetHeight/2;return[n[0]*a+a,n[1]*r+r]}destroy(){super.destroy(),this._state.destroy()}}const ku={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class Qu extends B{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=A.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return ku}set units(e){e||(e="meters");ku[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=A.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=A.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class Wu extends B{constructor(e,t={}){super(e,t),this._supported=Bs.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}const zu={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class Ku extends gn{get type(){return"PointsMaterial"}get presets(){return zu}constructor(e,t={}){super(e,t),this._state=new ge({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=zu[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(zu).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const Yu={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class Xu extends gn{get type(){return"LinesMaterial"}get presets(){return Yu}constructor(e,t={}){super(e,t),this._state=new ge({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Yu[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Yu).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}function qu(e,t){const s={};let n,i;for(let a=0,r=t.length;a{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new wu(this,{transparent:n,alphaDepthMask:i}),this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;let e=null;this.getHash=function(){if(e)return e;const t=this.sectionPlanes;if(0===t.length)return this.hash=";";const s=[];for(let e=0,n=t.length;e0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),n=null,s=null},this.removeLight=function(e){for(let t=0,i=this.lights.length;t{this._renderer.imageDirty()})),this.lod=new Vc(this,{enabled:t.lodEnabled}),this.vfc=new eu(this,{enabled:t.vfcEnabled})}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+v.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=A.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const n=this.types[s];n&&(delete n[t],v.isEmptyObject(n)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_objectHighlightedUpdated(e,t=!0){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_webglContextLost(){this.canvas.spinner.processes++;for(const e in this.components)if(this.components.hasOwnProperty(e)){const t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}_webglContextRestored(){const e=this.canvas.gl;for(const t in this.components)if(this.components.hasOwnProperty(t)){const s=this.components[t];s._webglContextRestored&&s._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get pickSurfacePrecisionEnabled(){return!1}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&C.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),!e&&!this._renderer.needsRender())return;t.sceneId=this.id;const s=this._passes,n=this._clearEachPass;let i,a;for(i=0;ii&&(i=e[3]),e[4]>a&&(a=e[4]),e[5]>r&&(r=e[5]),c=!0}c||(t=-100,s=-100,n=-100,i=100,a=100,r=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=n,this._aabb[3]=i,this._aabb[4]=a,this._aabb[5]=r,this._aabbDirty=!1}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=qu(this,s));const n=e.excludeEntities||e.exclude;return n&&(e.excludeEntityIds=qu(this,n)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}snapPick(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge)}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t{if(e.collidable){const o=e.aabb;o[0]a&&(a=o[3]),o[4]>r&&(r=o[4]),o[5]>l&&(l=o[5]),t=!0}})),t){const e=A.AABB3();return e[0]=s,e[1]=n,e[2]=i,e[3]=a,e[4]=r,e[5]=l,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){v.isString(e)&&(e=[e]);let s=!1;for(let n=0,i=e.length;n{this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=A.vec3();A.decomposeMat4(A.inverseMat4(this._scene.viewer.camera.viewMatrix,A.mat4()),t,A.vec4(),A.vec3());const s=A.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),N(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Me(this._scene,We({radius:n})),this._pivotSphere=new vn(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){A.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,A.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let a=t._lastBoundingClientRect;if(!a||t._canvasSizeChanged){const e=t.canvas;a=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(a.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(a.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(N(this.getPivotPos(),this._rtcCenter,this._rtcPos),A.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new bn(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=A.lookAtMat4v(e.eye,e.look,e.worldUp);A.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=A.distVec3(e.eye,s),t=A.inverseMat4(t);const n=A.transformVec3(t,this._cameraOffset),i=A.vec3();if(A.subVec3(e.eye,s,i),A.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=A.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=A.normalizeVec3(A.subVec3(e.look,e.eye,lh)),s=A.cross3Vec3(t,e.worldUp,oh);return A.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(A.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),a=n.subarray(12),r=[0,0,-1,1],l=A.dotVec4(r,i)/A.dotVec4(r,a),o=uh;t.project.unproject(e,l,hh,ph,o);const c=A.normalizeVec3(A.subVec3(o,t.eye,lh)),u=A.addVec3(t.eye,A.mulVec3Scalar(c,s,oh),ch);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=A.clamp(this._polar,.001,Math.PI-.001);const a=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===s.worldUp[2]){const e=a[1];a[1]=a[2],a[2]=e}const r=A.lenVec3(A.subVec3(s.look,s.eye,A.vec3())),l=this.getPivotPos();A.addVec3(a,l);let o=A.lookAtMat4v(a,l,s.worldUp);o=A.inverseMat4(o);const c=A.transformVec3(o,this._cameraOffset);o[12]-=c[0],o[13]-=c[1],o[14]-=c[2];const u=[o[8],o[9],o[10]];s.eye=[o[12],o[13],o[14]],A.subVec3(s.eye,A.mulVec3Scalar(u,r),s.look),s.up=[o[4],o[5],o[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class dh{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=A.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._needFireEvents=!1}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1,this._needFireEvents=!1;const e=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.snapPick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&e.snappedWorldPos?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents=!0):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const t=this.pickResult.canvasPos;if(t[0]===this.pickCursorPos[0]&&t[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents=e,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents=!0):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents=!0)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!0)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,cursorPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new au;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.snappedWorldPos,e.cursorPos=this.pickCursorPos,e.canvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=!1}}destroy(){}}const fh=A.vec2();class Ih{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController;let r,l,o,c=0,u=0,h=0,p=0,d=!1;const f=A.vec3();let I=!0;const y=this._scene.canvas.canvas,m=[];function v(e=!0){y.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],h=n.pointerCanvasPos[0],p=n.pointerCanvasPos[1],e&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.picked&&a.pickedSurface&&a.pickResult&&a.pickResult.worldPos?(d=!0,f.set(a.pickResult.worldPos)):d=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;m[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;m[n]=!1}),y.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:m[e.input.KEY_SHIFT]||s.planView?(r=!0,v()):(r=!0,v(!1));break;case 2:l=!0,v();break;case 3:o=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!r&&!l&&!o)return;const t=e.canvas.boundary,a=t[2],h=t[3],p=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(m[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&l||s.panRightClick&&o){const t=p-c,s=I-u,n=e.camera;if("perspective"===n.projection){const a=Math.abs(d?A.lenVec3(A.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*a/h,i.panDeltaY+=1.5*s*a/h}else i.panDeltaX+=.5*n.ortho.scale*(t/h),i.panDeltaY+=.5*n.ortho.scale*(s/h)}else!r||l||o||s.planView||(s.firstPerson?(i.rotateDeltaY-=(p-c)/a*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/h*(s.dragRotationRate/4)):(i.rotateDeltaY-=(p-c)/a*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/h*(1.5*s.dragRotationRate)));c=p,u=I}),y.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:r=!1,l=!1,o=!1}}),y.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,a=0,r=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,a+=s.scrollLeft,r+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+a-n,t[1]=e.pageY+r-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,fh);const s=fh[0],n=fh[1];Math.abs(s-h)<3&&Math.abs(n-p)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:fh,event:e},!0)}y.style.removeProperty("cursor")}}),y.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;y.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var a=null!==g?t-g:0;g=t,a>.05&&(a=.05),a{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const r=i._isKeyDownForAction(i.AXIS_VIEW_RIGHT),l=i._isKeyDownForAction(i.AXIS_VIEW_BACK),o=i._isKeyDownForAction(i.AXIS_VIEW_LEFT),c=i._isKeyDownForAction(i.AXIS_VIEW_FRONT),u=i._isKeyDownForAction(i.AXIS_VIEW_TOP),h=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(r||l||o||c||u||h))return;const p=e.aabb,d=A.getAABB3Diag(p);A.getAABB3Center(p,yh);const f=Math.abs(d/Math.tan(t.cameraFlight.fitFOV*A.DEGTORAD)),I=1.1*d;Th.orthoScale=I,r?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldRight,f,mh),gh)),Th.look.set(yh),Th.up.set(a.worldUp)):l?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldForward,f,mh),gh)),Th.look.set(yh),Th.up.set(a.worldUp)):o?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldRight,-f,mh),gh)),Th.look.set(yh),Th.up.set(a.worldUp)):c?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldForward,-f,mh),gh)),Th.look.set(yh),Th.up.set(a.worldUp)):u?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldUp,f,mh),gh)),Th.look.set(yh),Th.up.set(A.normalizeVec3(A.mulVec3Scalar(a.worldForward,1,vh),wh))):h&&(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldUp,-f,mh),gh)),Th.look.set(yh),Th.up.set(A.normalizeVec3(A.mulVec3Scalar(a.worldForward,-1,vh)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(yh),t.cameraFlight.duration>0?t.cameraFlight.flyTo(Th,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(Th),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class bh{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController,r=t.pivotController,l=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let o=!1,c=!1;const u=this._scene.canvas.canvas,h=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;A.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};u.addEventListener("mousemove",this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(o||c)return;const i=l.hasSubs("hover"),r=l.hasSubs("hoverOut"),u=l.hasSubs("hoverOff"),h=l.hasSubs("hoverSurface"),p=l.hasSubs("hoverSnapOrSurface");if(i||r||u||h||p)if(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=h,a.scheduleSnapOrPick=p,a.update(),a.pickResult){if(a.pickResult.entity){const t=a.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&l.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),l.fire("hoverEnter",a.pickResult,!0),this._lastPickedEntityId=t)}l.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&l.fire("hoverSurface",a.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(l.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),l.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(o=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===t.which))){const t=a.pickResult;t&&t.worldPos?(r.setPivotPos(t.worldPos),r.startPivot()):(s.smartPivot?r.setCanvasPivotPos(n.pointerCanvasPos):r.setPivotPos(e.camera.look),r.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(o=!1),3===e.which&&(c=!1),r.getPivoting()&&r.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(r.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const o=l.hasSubs("picked"),c=l.hasSubs("pickedNothing"),u=l.hasSubs("pickedSurface"),p=l.hasSubs("doublePicked"),d=l.hasSubs("doublePickedSurface"),f=l.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||p||d||f))return(o||c||u)&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=u,a.update(),a.pickResult?(l.fire("picked",a.pickResult,!0),a.pickedSurface&&l.fire("pickedSurface",a.pickResult,!0)):l.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo,a.schedulePickSurface=u,a.update();const e=a.pickResult,i=a.pickedSurface;this._timeout=setTimeout((()=>{e?(l.fire("picked",e,!0),i&&(l.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):l.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo||p||d,a.schedulePickSurface=a.schedulePickEntity&&d,a.update(),a.pickResult){if(l.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&l.fire("doublePickedSurface",a.pickResult,!0),s.doublePickFlyTo&&(h(a.pickResult),!s.firstPerson&&s.followPointer)){const e=a.pickResult.entity.aabb,s=A.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(l.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(h(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=A.getAABB3Center(s);t.pivotController.setPivotPos(n),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class Dh{constructor(e,t,s,n,i){this._scene=e;const a=e.input,r=[],l=e.canvas.canvas;let o=!0;this._onSceneMouseMove=a.on("mousemove",(()=>{o=!0})),this._onSceneKeyDown=a.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(r[t]=!0,t===a.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=a.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(r[n]=!1,n===a.KEY_SHIFT&&(l.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(l=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=l.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,r),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,r),a=c._isKeyDownForAction(c.ROTATE_X_POS,r),l=c._isKeyDownForAction(c.ROTATE_X_NEG,r),o=u*s.keyboardRotationRate;(e||n||a||l)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=o:n&&(i.rotateDeltaY-=o),a?i.rotateDeltaX+=o:l&&(i.rotateDeltaX-=o),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!r[a.KEY_CTRL]&&!r[a.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,r),a=c._isKeyDownForAction(c.DOLLY_FORWARDS,r);if(e||a){const r=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),a?i.dollyDelta-=r:e&&(i.dollyDelta+=r),o&&(n.followPointerDirty=!0,o=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,r),p=c._isKeyDownForAction(c.PAN_BACKWARDS,r),A=c._isKeyDownForAction(c.PAN_LEFT,r),d=c._isKeyDownForAction(c.PAN_RIGHT,r),f=c._isKeyDownForAction(c.PAN_UP,r),I=c._isKeyDownForAction(c.PAN_DOWN,r),y=(r[a.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||A||d||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=y:f&&(i.panDeltaY+=-y),d?i.panDeltaX+=-y:A&&(i.panDeltaX+=y),p?i.panDeltaZ+=y:h&&(i.panDeltaZ+=-y))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const Ph=A.vec3();class Rh{constructor(e,t,s,n,i){this._scene=e;const a=e.camera,r=t.pickController,l=t.pivotController,o=t.panController;let c=1,u=1,h=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.pickResult&&r.pickResult.worldPos?h=r.pickResult.worldPos:(u=1,h=null),n.followPointerDirty=!1),h){const t=Math.abs(A.lenVec3(A.subVec3(h,e.camera.eye,Ph)));u=t/s.dollyProximityThreshold}u{n.mouseover=!0}),a.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{n.mouseover=!1,a.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{_h(e,a,n.pointerCanvasPos)}),a.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(_h(e,a,n.pointerCanvasPos),n.mouseover=!0)}),a.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function _h(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const Bh=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class Oh{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController,r=t.pivotController,l=A.vec2(),o=A.vec2(),c=A.vec2(),u=A.vec2(),h=[],p=this._scene.canvas.canvas;let d=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),p.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,o=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===o.length&&(Bh(i[0],l),s.followPointer&&(a.pickCursorPos=l,a.schedulePickSurface=!0,a.update(),s.planView||(a.picked&&a.pickedSurface&&a.pickResult&&a.pickResult.worldPos?(r.setPivotPos(a.pickResult.worldPos),!s.firstPerson&&r.startPivot()&&r.showPivot()):(s.smartPivot?r.setCanvasPivotPos(n.pointerCanvasPos):r.setPivotPos(e.camera.look),!s.firstPerson&&r.startPivot()&&r.showPivot()))));h.length{r.getPivoting()&&r.endPivot()}),p.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const r=e.canvas.boundary,l=r[2],p=r[3],I=t.touches;if(t.touches.length===d){if(1===d){Bh(I[0],o),A.subVec2(o,h[0],u);const t=u[0],a=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(a)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const r=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*r/p*s.touchPanRate,i.panDeltaY+=a*r/p*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/p)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(a/p)*s.touchPanRate}else i.rotateDeltaY-=t/l*(1*s.dragRotationRate),i.rotateDeltaX+=a/p*(1.5*s.dragRotationRate)}else if(2===d){const t=I[0],r=I[1];Bh(t,o),Bh(r,c);const l=A.geometricMeanVec2(h[0],h[1]),u=A.geometricMeanVec2(o,c),d=A.vec2();A.subVec2(l,u,d);const f=d[0],y=d[1],m=e.camera,v=A.distVec2([t.pageX,t.pageY],[r.pageX,r.pageY]),w=(A.distVec2(h[0],h[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===m.projection){const t=a.pickResult?a.pickResult.worldPos:e.center,n=Math.abs(A.lenVec3(A.subVec3(t,e.camera.eye,[])))*Math.tan(m.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/p*s.touchPanRate,i.panDeltaY-=y*n/p*s.touchPanRate}else i.panDeltaX-=.5*m.ortho.scale*(f/p)*s.touchPanRate,i.panDeltaY-=.5*m.ortho.scale*(y/p)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e{let n;s&&s.worldPos&&(n=s.worldPos);const i=s?s.entity.aabb:e.aabb;if(n){const s=e.camera;A.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};p.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,a=e.changedTouches;if(l=Date.now(),1===i.length&&1===a.length){u=l,Sh(i[0],c);const a=c[0],r=c[1],o=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(o),Math.round(h)],canvasPos:[Math.round(a),Math.round(r)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;o.length{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,l=e.changedTouches,p=r.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===l.length&&u>-1&&t-u<150&&(h>-1&&u-h<325?(Sh(l[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=p,a.update(),a.pickResult?(a.pickResult.touchInput=!0,r.fire("doublePicked",a.pickResult),a.pickedSurface&&r.fire("doublePickedSurface",a.pickResult),s.doublePickFlyTo&&d(a.pickResult)):(r.fire("doublePickedNothing"),s.doublePickFlyTo&&d()),h=-1):A.distVec2(o[0],c)<4&&(Sh(l[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=p,a.update(),a.pickResult?(a.pickResult.touchInput=!0,r.fire("picked",a.pickResult),a.pickedSurface&&r.fire("pickedSurface",a.pickResult)):r.fire("pickedNothing"),h=t),u=-1),o.length=i.length;for(let e=0,t=i.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:A.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:A.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new dh(this,this._configs),pivotController:new Ah(s,this._configs),panController:new rh(s),cameraFlight:new ye(this,{duration:.5})},this._handlers=[new Ch(this.scene,this._controllers,this._configs,this._states,this._updates),new Oh(this.scene,this._controllers,this._configs,this._states,this._updates),new Ih(this.scene,this._controllers,this._configs,this._states,this._updates),new Eh(this.scene,this._controllers,this._configs,this._states,this._updates),new bh(this.scene,this._controllers,this._configs,this._states,this._updates),new Nh(this.scene,this._controllers,this._configs,this._states,this._updates),new Dh(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new Rh(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",v.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;e0?Gh(t):null,r=s&&s.length>0?Gh(s):null,l=e=>{if(!e)return;var t=!0;(r&&r[e.type]||a&&!a[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,o=s.length;i{for(let s=0,n=e.meshIds.length;s{const s=t[e];let n,i;if(s.positionsCompressed){const e=Be.getPositionsBounds(s.positionsCompressed);n=Be.decompressPosition(e.min,s.positionsDecodeMatrix,[]),i=Be.decompressPosition(e.max,s.positionsDecodeMatrix,[])}else{const e=Be.getPositionsBounds(s.positions);n=e.min,i=e.max}n[0]+=s.origin[0],n[1]+=s.origin[1],n[2]+=s.origin[2],i[0]+=s.origin[0],i[1]+=s.origin[1],i[2]+=s.origin[2],A.expandAABB3Point3(l,n),A.expandAABB3Point3(l,i),o+=s.numPrimitives})),n[r]={aabb:l,numPrimitives:o,entityId:s.id}}let r,l=[],o={};if(Object.keys(n).length>0){r=function(e){const t=[];for(let s=0,n=e.length;s{s=Math.max(s,e.entity.id)}));const n=new Array(s+1);t.forEach((t=>{n[t.entity.id]=e.objects[t.entity.xeokitId]})),this._internalNodesList=n,this._lastVisibleFrameOfNodes=new Array(n.length),this._lastVisibleFrameOfNodes.fill(0)}_searchVisibleNodesWithFrustumCulling(){return this._aabbTree.searchCustom(((e,t)=>this._aabbIntersectsCameraFrustum(e,t)),(e=>this._aabbContainedInCameraFrustum(e)))}_markVisibleFrameOfVisibleNodes(e,t){const s=this._lastVisibleFrameOfNodes;for(let n=0,i=e.length;nthis._frustumProps.CAM_FACTOR_1?(s|=r<0?64:128,s&=-17):s&=-33;const l=Jc(A.dotVec3(i,this._frustumProps.up),a);Math.abs(l)>this._frustumProps.CAM_FACTOR_2?(s|=l<0?1024:2048,s&=-257):s&=-513}return 4&s&&8&s&&(s|=4096),64&s&&128&s&&(s|=8192),1024&s&&2048&s&&(s|=16384),e._check=s,s}}class $c{constructor(e,t){this.sceneModel=t,this.entities=[],this.meshes=[],this.finalized=!1}addEntity(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}addMesh(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}finalize(e){if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new Zc,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(()=>this.applyViewFrustumCulling.call(this)))}applyViewFrustumCulling(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}destroy(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}class eu extends B{constructor(e,t={}){super(e,t),this._scene=e,this._vfcManagers={},this._vfcManagerList=[],this.enabled=t.enabled,this._init()}_init(){this._scene.on("rendering",(()=>{for(let e=0,t=this._vfcManagerList.length;e
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const su=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class nu extends B{constructor(e,t={}){super(e,t),this._backgroundColor=A.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new tu(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+A.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new ru(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new ru(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new _s(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=A.mat4();return()=>(e&&A.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,h=this._getInverseProjectMat(),p=Math.random(),d="perspective"===n.camera.projection;uu[0]=a,uu[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,h),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,uu),t.uniform1f(this._uRandomSeed,p);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new _s(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new Te(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new Te(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new Te(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const pu=new Float32Array(mu(17,[0,1])),Au=new Float32Array(mu(17,[1,0])),du=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(yu(n,t));return s}(17,4)),fu=new Float32Array(2);class Iu{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new _s(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new Te(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new Te(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new Te(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=A.mat4();return()=>(e&&A.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),fu[0]=r,fu[1]=l,n.uniform2fv(this._uViewport,fu),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,Au):n.uniform2fv(this._uSampleOffsets,pu),n.uniform1fv(this._uSampleWeights,du);const h=e.getDepthTexture(),p=t.getTexture();i.bindTexture(this._uDepthTexture,h,0),i.bindTexture(this._uOcclusionTexture,p,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function yu(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function mu(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class vu{constructor(e){this.scene=e,this._renderBuffersBasic={},this._renderBuffersScaled={}}getRenderBuffer(e,t){const s=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled;let n=s[e];return n||(n=new si(this.scene.canvas.canvas,this.scene.canvas.gl,t),s[e]=n),n}destroy(){for(let e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(let e in this._renderBuffersScaled)this._renderBuffersScaled[e].destroy()}}const wu=function(t,s){s=s||{};const n=new iu(t),i=t.canvas.canvas,a=t.canvas.gl,r=!!s.transparent,l=s.alphaDepthMask,o=new e({});let c={},u={},h=!0,p=!0,d=!0,I=!0,y=!0,m=!0,v=!0,w=!0;const g=new vu(t);let T=!1;const E=new hu(t),b=new Iu(t);function D(){h&&(!function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e],s=t.drawableMap,n=t.drawableListPreCull;let i=0;for(let e in s)s.hasOwnProperty(e)&&(n[i++]=s[e]);n.length=i}}(),h=!1,p=!0),p&&(!function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),p=!1,d=!0),d&&function(){for(let e in c)if(c.hasOwnProperty(e)){const t=c[e],s=t.drawableListPreCull,n=t.drawableList;let i=0;for(let e=0,t=s.length;e0)for(n.withSAO=!0,S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||k>0||H>0||U>0){if(a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):(a.blendEquation(a.FUNC_ADD),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,l||a.depthMask(!1),(H>0||U>0)&&a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),U>0)for(S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||W>0){if(n.lastProgramId=null,t.highlightMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),W>0)for(S=0;S0)for(S=0;S0||K>0||Q>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.enable(a.CULL_FACE),K>0)for(S=0;S0)for(S=0;S0||X>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),X>0)for(S=0;S0)for(S=0;S0||J>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),J>0)for(S=0;S0)for(S=0;S0){const t=Math.floor(e/4),s=l.size[0],n=t%s-Math.floor(s/2),a=Math.floor(t/s)-Math.floor(s/2),o=Math.sqrt(Math.pow(n,2)+Math.pow(a,2));y.push({x:n,y:a,dist:o,isVertex:i&&r?A[e+3]>p.length/2:i,result:[A[e+0],A[e+1],A[e+2],A[e+3]]})}let m=null,v=null;if(y.length>0){y.sort(((e,t)=>e.isVertex!==t.isVertex?e.isVertex?-1:1:e.dist-t.dist)),v=y[0].isVertex?"vertex":"edge",y=y[0].result;const e=p[y[3]],t=e.origin,s=e.coordinateScale;m=[y[0]*s[0]+t[0],y[1]*s[1]+t[1],y[2]*s[2]+t[2]]}if(null===d&&null==m)return null;let w=null;return null!==m&&(w=t.camera.projectWorldPos(m)),{snapType:v,snappedToVertex:"vertex"===v,snappedToEdge:"edge"===v,worldPos:d,snappedWorldPos:m,snappedCanvasPos:w}},this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new cu(t,g),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){D(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight),a.clearColor(0,0,0,0),a.enable(a.DEPTH_TEST),a.disable(a.CULL_FACE),a.disable(a.BLEND),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT);for(let e in c)if(c.hasOwnProperty(e)){const t=c[e].drawableList;for(let e=0,s=t.length;e{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("mousemove",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=(e,t)=>{if(!this.enabled)return;const s=Math.max(-1,Math.min(1,40*-e.deltaY));this.fire("mousewheel",s,!0)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(n=>{e>=n[0]-s&&e<=n[0]+s&&t>=n[1]-s&&t<=n[1]+s&&this.fire("mouseclicked",n,!0)}))}this._eventsBound=!0}}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getMouseCanvasPos(e){if(e){let t=e.target,s=0,n=0;for(;t.offsetParent;)s+=t.offsetLeft,n+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-s,this.mouseCanvasPos[1]=e.pageY-n}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}class Tu extends B{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new ge({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class Eu extends B{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ge({matrix:A.mat4(),inverseMatrix:A.mat4(),transposedMatrix:A.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.canvas.boundary,t=e[2]/e[3],s=this._fovAxis;let n=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(n/=t),n=Math.min(n,120),A.perspectiveMat4(n*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(A.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(A.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,A.mulMat4v4(this.inverseMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,A.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class bu extends B{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ge({matrix:A.mat4(),inverseMatrix:A.mat4(),transposedMatrix:A.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.canvas.boundary,n=s[2],i=s[3],a=n/i;let r,l,o,c;n>i?(r=-t,l=t,o=t/a,c=-t/a):(r=-t*a,l=t*a,o=t,c=-t),A.orthoMat4c(r,l,c,o,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(A.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(A.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,A.mulMat4v4(this.inverseMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,A.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class Du extends B{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ge({matrix:A.mat4(),inverseMatrix:A.mat4(),transposedMatrix:A.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){A.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(A.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(A.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,A.mulMat4v4(this.inverseMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,A.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class Pu extends B{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new ge({matrix:A.mat4(),inverseMatrix:A.mat4(),transposedMatrix:A.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(A.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(A.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,A.mulMat4v4(this.inverseMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,A.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy()}}const Ru=A.vec3(),Cu=A.vec3(),_u=A.vec3(),Bu=A.vec3(),Ou=A.vec3(),Su=A.vec3(),Nu=A.vec4(),xu=A.vec4(),Lu=A.vec4(),Mu=A.mat4(),Fu=A.mat4(),Hu=A.vec3(),Uu=A.vec3(),Gu=A.vec3(),ju=A.vec3();class Vu extends B{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new ge({deviceMatrix:A.mat4(),hasDeviceMatrix:!1,matrix:A.mat4(),normalMatrix:A.mat4(),inverseMatrix:A.mat4()}),this._perspective=new Eu(this),this._ortho=new bu(this),this._frustum=new Du(this),this._customProjection=new Pu(this),this._project=this._perspective,this._eye=A.vec3([0,0,10]),this._look=A.vec3([0,0,0]),this._up=A.vec3([0,1,0]),this._worldUp=A.vec3([0,1,0]),this._worldRight=A.vec3([1,0,0]),this._worldForward=A.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection?(A.subVec3(this._eye,this._look,Hu),A.normalizeVec3(Hu,Uu),A.mulVec3Scalar(Uu,1e3,Gu),A.addVec3(this._look,Gu,ju),t=ju):t=this._eye,e.hasDeviceMatrix?(A.lookAtMat4v(t,this._look,this._up,Fu),A.mulMat4(e.deviceMatrix,Fu,e.matrix)):A.lookAtMat4v(t,this._look,this._up,e.matrix),A.inverseMat4(this._state.matrix,this._state.inverseMatrix),A.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=A.subVec3(this._eye,this._look,Ru);A.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Mu),t=A.transformPoint3(Mu,t,Cu),this.eye=A.addVec3(this._look,t,_u),this.up=A.transformPoint3(Mu,this._up,Bu)}orbitPitch(e){if(this._constrainPitch&&(e=A.dotVec3(this._up,this._worldUp)/A.DEGTORAD)<1)return;let t=A.subVec3(this._eye,this._look,Ru);const s=A.cross3Vec3(A.normalizeVec3(t,Cu),A.normalizeVec3(this._up,_u));A.rotationMat4v(.0174532925*e,s,Mu),t=A.transformPoint3(Mu,t,Bu),this.up=A.transformPoint3(Mu,this._up,Ou),this.eye=A.addVec3(t,this._look,Su)}yaw(e){let t=A.subVec3(this._look,this._eye,Ru);A.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Mu),t=A.transformPoint3(Mu,t,Cu),this.look=A.addVec3(t,this._eye,_u),this._gimbalLock&&(this.up=A.transformPoint3(Mu,this._up,Bu))}pitch(e){if(this._constrainPitch&&(e=A.dotVec3(this._up,this._worldUp)/A.DEGTORAD)<1)return;let t=A.subVec3(this._look,this._eye,Ru);const s=A.cross3Vec3(A.normalizeVec3(t,Cu),A.normalizeVec3(this._up,_u));A.rotationMat4v(.0174532925*e,s,Mu),this.up=A.transformPoint3(Mu,this._up,Su),t=A.transformPoint3(Mu,t,Bu),this.look=A.addVec3(t,this._eye,Ou)}pan(e){const t=A.subVec3(this._eye,this._look,Ru),s=[0,0,0];let n;if(0!==e[0]){const i=A.cross3Vec3(A.normalizeVec3(t,[]),A.normalizeVec3(this._up,Cu));n=A.mulVec3Scalar(i,e[0]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]}0!==e[1]&&(n=A.mulVec3Scalar(A.normalizeVec3(this._up,_u),e[1]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),0!==e[2]&&(n=A.mulVec3Scalar(A.normalizeVec3(t,Bu),e[2]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),this.eye=A.addVec3(this._eye,s,Ou),this.look=A.addVec3(this._look,s,Su)}zoom(e){const t=A.subVec3(this._eye,this._look,Ru),s=Math.abs(A.lenVec3(t,Cu)),n=Math.abs(s+e);if(n<.5)return;const i=A.normalizeVec3(t,_u);this.eye=A.addVec3(this._look,A.mulVec3Scalar(i,n),Bu)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=A.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return A.lenVec3(A.subVec3(this._look,this._eye,Ru))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}projectWorldPos(e){const t=Nu,s=xu,n=Lu;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,A.mulMat4v4(this.viewMatrix,t,s),A.mulMat4v4(this.projMatrix,s,n),A.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1;const i=this.scene.canvas.canvas,a=i.offsetWidth/2,r=i.offsetHeight/2;return[n[0]*a+a,n[1]*r+r]}destroy(){super.destroy(),this._state.destroy()}}const ku={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class Qu extends B{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=A.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return ku}set units(e){e||(e="meters");ku[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=A.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=A.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class Wu extends B{constructor(e,t={}){super(e,t),this._supported=Bs.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}const zu={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class Ku extends gn{get type(){return"PointsMaterial"}get presets(){return zu}constructor(e,t={}){super(e,t),this._state=new ge({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=zu[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(zu).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const Yu={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class Xu extends gn{get type(){return"LinesMaterial"}get presets(){return Yu}constructor(e,t={}){super(e,t),this._state=new ge({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Yu[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Yu).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}function qu(e,t){const s={};let n,i;for(let a=0,r=t.length;a{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new wu(this,{transparent:n,alphaDepthMask:i}),this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;let e=null;this.getHash=function(){if(e)return e;const t=this.sectionPlanes;if(0===t.length)return this.hash=";";const s=[];for(let e=0,n=t.length;e0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),n=null,s=null},this.removeLight=function(e){for(let t=0,i=this.lights.length;t{this._renderer.imageDirty()})),this.lod=new Vc(this,{enabled:t.lodEnabled}),this.vfc=new eu(this,{enabled:t.vfcEnabled})}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+v.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=A.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const n=this.types[s];n&&(delete n[t],v.isEmptyObject(n)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_objectHighlightedUpdated(e,t=!0){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_webglContextLost(){this.canvas.spinner.processes++;for(const e in this.components)if(this.components.hasOwnProperty(e)){const t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}_webglContextRestored(){const e=this.canvas.gl;for(const t in this.components)if(this.components.hasOwnProperty(t)){const s=this.components[t];s._webglContextRestored&&s._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get pickSurfacePrecisionEnabled(){return!1}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&C.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),!e&&!this._renderer.needsRender())return;t.sceneId=this.id;const s=this._passes,n=this._clearEachPass;let i,a;for(i=0;ii&&(i=e[3]),e[4]>a&&(a=e[4]),e[5]>r&&(r=e[5]),c=!0}c||(t=-100,s=-100,n=-100,i=100,a=100,r=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=n,this._aabb[3]=i,this._aabb[4]=a,this._aabb[5]=r,this._aabbDirty=!1}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=qu(this,s));const n=e.excludeEntities||e.exclude;return n&&(e.excludeEntityIds=qu(this,n)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}snapPick(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge)}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t{if(e.collidable){const o=e.aabb;o[0]a&&(a=o[3]),o[4]>r&&(r=o[4]),o[5]>l&&(l=o[5]),t=!0}})),t){const e=A.AABB3();return e[0]=s,e[1]=n,e[2]=i,e[3]=a,e[4]=r,e[5]=l,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){v.isString(e)&&(e=[e]);let s=!1;for(let n=0,i=e.length;n{this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=A.vec3();A.decomposeMat4(A.inverseMat4(this._scene.viewer.camera.viewMatrix,A.mat4()),t,A.vec4(),A.vec3());const s=A.distVec3(t,e);let n=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(n/=this._scene.camera.ortho.scale/2),N(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Me(this._scene,We({radius:n})),this._pivotSphere=new vn(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){A.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,A.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,n=s[2],i=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*n/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);let a=t._lastBoundingClientRect;if(!a||t._canvasSizeChanged){const e=t.canvas;a=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(a.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(a.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(N(this.getPivotPos(),this._rtcCenter,this._rtcPos),A.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new bn(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;const e=this._scene.camera;let t=A.lookAtMat4v(e.eye,e.look,e.worldUp);A.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=A.distVec3(e.eye,s),t=A.inverseMat4(t);const n=A.transformVec3(t,this._cameraOffset),i=A.vec3();if(A.subVec3(e.eye,s,i),A.addVec3(i,n),e.zUp){const e=i[1];i[1]=i[2],i[2]=e}this._radius=A.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=A.normalizeVec3(A.subVec3(e.look,e.eye,lh)),s=A.cross3Vec3(t,e.worldUp,oh);return A.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(A.distVec3(this._scene.center,t.eye)),n=t.project.transposedMatrix,i=n.subarray(8,12),a=n.subarray(12),r=[0,0,-1,1],l=A.dotVec4(r,i)/A.dotVec4(r,a),o=uh;t.project.unproject(e,l,hh,ph,o);const c=A.normalizeVec3(A.subVec3(o,t.eye,lh)),u=A.addVec3(t.eye,A.mulVec3Scalar(c,s,oh),ch);this.setPivotPos(u)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var n=-e;const i=-t;1===s.worldUp[2]&&(n=-n),this._azimuth+=.01*-n,this._polar+=.01*i,this._polar=A.clamp(this._polar,.001,Math.PI-.001);const a=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===s.worldUp[2]){const e=a[1];a[1]=a[2],a[2]=e}const r=A.lenVec3(A.subVec3(s.look,s.eye,A.vec3())),l=this.getPivotPos();A.addVec3(a,l);let o=A.lookAtMat4v(a,l,s.worldUp);o=A.inverseMat4(o);const c=A.transformVec3(o,this._cameraOffset);o[12]-=c[0],o[13]-=c[1],o[14]-=c[2];const u=[o[8],o[9],o[10]];s.eye=[o[12],o[13],o[14]],A.subVec3(s.eye,A.mulVec3Scalar(u,r),s.look),s.up=[o[4],o[5],o[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class dh{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=A.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._needFireEvents=!1}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1,this._needFireEvents=!1;const e=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.snapPick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&e.snappedWorldPos?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents=!0):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const t=this.pickResult.canvasPos;if(t[0]===this.pickCursorPos[0]&&t[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents=e,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents=!0):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents=!0)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!0)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,cursorPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new au;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.snappedWorldPos,e.cursorPos=this.pickCursorPos,e.canvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=!1}}destroy(){}}const fh=A.vec2();class Ih{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController;let r,l,o,c=0,u=0,h=0,p=0,d=!1;const f=A.vec3();let I=!0;const y=this._scene.canvas.canvas,m=[];function v(e=!0){y.style.cursor="move",c=n.pointerCanvasPos[0],u=n.pointerCanvasPos[1],h=n.pointerCanvasPos[0],p=n.pointerCanvasPos[1],e&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.picked&&a.pickedSurface&&a.pickResult&&a.pickResult.worldPos?(d=!0,f.set(a.pickResult.worldPos)):d=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;m[n]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const n=t.keyCode;m[n]=!1}),y.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:m[e.input.KEY_SHIFT]||s.planView?(r=!0,v()):(r=!0,v(!1));break;case 2:l=!0,v();break;case 3:o=!0,s.panRightClick&&v()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=()=>{if(!s.active||!s.pointerEnabled)return;if(!r&&!l&&!o)return;const t=e.canvas.boundary,a=t[2],h=t[3],p=n.pointerCanvasPos[0],I=n.pointerCanvasPos[1];if(m[e.input.KEY_SHIFT]||s.planView||!s.panRightClick&&l||s.panRightClick&&o){const t=p-c,s=I-u,n=e.camera;if("perspective"===n.projection){const a=Math.abs(d?A.lenVec3(A.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=1.5*t*a/h,i.panDeltaY+=1.5*s*a/h}else i.panDeltaX+=.5*n.ortho.scale*(t/h),i.panDeltaY+=.5*n.ortho.scale*(s/h)}else!r||l||o||s.planView||(s.firstPerson?(i.rotateDeltaY-=(p-c)/a*s.dragRotationRate/2,i.rotateDeltaX+=(I-u)/h*(s.dragRotationRate/4)):(i.rotateDeltaY-=(p-c)/a*(1.5*s.dragRotationRate),i.rotateDeltaX+=(I-u)/h*(1.5*s.dragRotationRate)));c=p,u=I}),y.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&n.mouseover&&(I=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{if(s.active&&s.pointerEnabled)switch(e.which){case 1:case 2:case 3:r=!1,l=!1,o=!1}}),y.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){!function(e,t){if(e){let s=e.target,n=0,i=0,a=0,r=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,a+=s.scrollLeft,r+=s.scrollTop,s=s.offsetParent;t[0]=e.pageX+a-n,t[1]=e.pageY+r-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,fh);const s=fh[0],n=fh[1];Math.abs(s-h)<3&&Math.abs(n-p)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:fh,event:e},!0)}y.style.removeProperty("cursor")}}),y.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const w=1/60;let g=null;y.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=performance.now()/1e3;var a=null!==g?t-g:0;g=t,a>.05&&(a=.05),a{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const r=i._isKeyDownForAction(i.AXIS_VIEW_RIGHT),l=i._isKeyDownForAction(i.AXIS_VIEW_BACK),o=i._isKeyDownForAction(i.AXIS_VIEW_LEFT),c=i._isKeyDownForAction(i.AXIS_VIEW_FRONT),u=i._isKeyDownForAction(i.AXIS_VIEW_TOP),h=i._isKeyDownForAction(i.AXIS_VIEW_BOTTOM);if(!(r||l||o||c||u||h))return;const p=e.aabb,d=A.getAABB3Diag(p);A.getAABB3Center(p,yh);const f=Math.abs(d/Math.tan(t.cameraFlight.fitFOV*A.DEGTORAD)),I=1.1*d;Th.orthoScale=I,r?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldRight,f,mh),gh)),Th.look.set(yh),Th.up.set(a.worldUp)):l?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldForward,f,mh),gh)),Th.look.set(yh),Th.up.set(a.worldUp)):o?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldRight,-f,mh),gh)),Th.look.set(yh),Th.up.set(a.worldUp)):c?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldForward,-f,mh),gh)),Th.look.set(yh),Th.up.set(a.worldUp)):u?(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldUp,f,mh),gh)),Th.look.set(yh),Th.up.set(A.normalizeVec3(A.mulVec3Scalar(a.worldForward,1,vh),wh))):h&&(Th.eye.set(A.addVec3(yh,A.mulVec3Scalar(a.worldUp,-f,mh),gh)),Th.look.set(yh),Th.up.set(A.normalizeVec3(A.mulVec3Scalar(a.worldForward,-1,vh)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(yh),t.cameraFlight.duration>0?t.cameraFlight.flyTo(Th,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(Th),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class bh{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController,r=t.pivotController,l=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;let o=!1,c=!1;const u=this._scene.canvas.canvas,h=s=>{let n;s&&s.worldPos&&(n=s.worldPos);const i=s&&s.entity?s.entity.aabb:e.aabb;if(n){const s=e.camera;A.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};u.addEventListener("mousemove",this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(o||c)return;const i=l.hasSubs("hover"),r=l.hasSubs("hoverOut"),u=l.hasSubs("hoverOff"),h=l.hasSubs("hoverSurface"),p=l.hasSubs("hoverSnapOrSurface");if(i||r||u||h||p)if(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=h,a.scheduleSnapOrPick=p,a.update(),a.pickResult){if(a.pickResult.entity){const t=a.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&l.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),l.fire("hoverEnter",a.pickResult,!0),this._lastPickedEntityId=t)}l.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&l.fire("hoverSurface",a.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(l.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),l.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}),u.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(o=!0),3===t.which&&(c=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(n.mouseDownClientX=t.clientX,n.mouseDownClientY=t.clientY,n.mouseDownCursorX=n.pointerCanvasPos[0],n.mouseDownCursorY=n.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===t.which))){const t=a.pickResult;t&&t.worldPos?(r.setPivotPos(t.worldPos),r.startPivot()):(s.smartPivot?r.setCanvasPivotPos(n.pointerCanvasPos):r.setPivotPos(e.camera.look),r.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(o=!1),3===e.which&&(c=!1),r.getPivoting()&&r.endPivot()}),u.addEventListener("mouseup",this._canvasMouseUpHandler=i=>{if(!s.active||!s.pointerEnabled)return;if(!(1===i.which))return;if(r.hidePivot(),Math.abs(i.clientX-n.mouseDownClientX)>3||Math.abs(i.clientY-n.mouseDownClientY)>3)return;const o=l.hasSubs("picked"),c=l.hasSubs("pickedNothing"),u=l.hasSubs("pickedSurface"),p=l.hasSubs("doublePicked"),d=l.hasSubs("doublePickedSurface"),f=l.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||p||d||f))return(o||c||u)&&(a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=u,a.update(),a.pickResult?(l.fire("picked",a.pickResult,!0),a.pickedSurface&&l.fire("pickedSurface",a.pickResult,!0)):l.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo,a.schedulePickSurface=u,a.update();const e=a.pickResult,i=a.pickedSurface;this._timeout=setTimeout((()=>{e?(l.fire("picked",e,!0),i&&(l.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):l.fire("pickedNothing",{canvasPos:n.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),a.pickCursorPos=n.pointerCanvasPos,a.schedulePickEntity=s.doublePickFlyTo||p||d,a.schedulePickSurface=a.schedulePickEntity&&d,a.update(),a.pickResult){if(l.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&l.fire("doublePickedSurface",a.pickResult,!0),s.doublePickFlyTo&&(h(a.pickResult),!s.firstPerson&&s.followPointer)){const e=a.pickResult.entity.aabb,s=A.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(l.fire("doublePickedNothing",{canvasPos:n.pointerCanvasPos},!0),s.doublePickFlyTo&&(h(),!s.firstPerson&&s.followPointer)){const s=e.aabb,n=A.getAABB3Center(s);t.pivotController.setPivotPos(n),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class Dh{constructor(e,t,s,n,i){this._scene=e;const a=e.input,r=[],l=e.canvas.canvas;let o=!0;this._onSceneMouseMove=a.on("mousemove",(()=>{o=!0})),this._onSceneKeyDown=a.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&n.mouseover&&(r[t]=!0,t===a.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=a.on("keyup",(n=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(r[n]=!1,n===a.KEY_SHIFT&&(l.style.cursor=null),t.pivotController.getPivoting()&&t.pivotController.endPivot())})),this._onTick=e.on("tick",(l=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(!n.mouseover)return;const c=t.cameraControl,u=l.deltaTime/1e3;if(!s.planView){const e=c._isKeyDownForAction(c.ROTATE_Y_POS,r),n=c._isKeyDownForAction(c.ROTATE_Y_NEG,r),a=c._isKeyDownForAction(c.ROTATE_X_POS,r),l=c._isKeyDownForAction(c.ROTATE_X_NEG,r),o=u*s.keyboardRotationRate;(e||n||a||l)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?i.rotateDeltaY+=o:n&&(i.rotateDeltaY-=o),a?i.rotateDeltaX+=o:l&&(i.rotateDeltaX-=o),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!r[a.KEY_CTRL]&&!r[a.KEY_ALT]){const e=c._isKeyDownForAction(c.DOLLY_BACKWARDS,r),a=c._isKeyDownForAction(c.DOLLY_FORWARDS,r);if(e||a){const r=u*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),a?i.dollyDelta-=r:e&&(i.dollyDelta+=r),o&&(n.followPointerDirty=!0,o=!1)}}const h=c._isKeyDownForAction(c.PAN_FORWARDS,r),p=c._isKeyDownForAction(c.PAN_BACKWARDS,r),A=c._isKeyDownForAction(c.PAN_LEFT,r),d=c._isKeyDownForAction(c.PAN_RIGHT,r),f=c._isKeyDownForAction(c.PAN_UP,r),I=c._isKeyDownForAction(c.PAN_DOWN,r),y=(r[a.KEY_ALT]?.3:1)*u*s.keyboardPanRate;(h||p||A||d||f||I)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),I?i.panDeltaY+=y:f&&(i.panDeltaY+=-y),d?i.panDeltaX+=-y:A&&(i.panDeltaX+=y),p?i.panDeltaZ+=y:h&&(i.panDeltaZ+=-y))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}const Ph=A.vec3();class Rh{constructor(e,t,s,n,i){this._scene=e;const a=e.camera,r=t.pickController,l=t.pivotController,o=t.panController;let c=1,u=1,h=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(i.dollyDelta)<.001&&(i.dollyDelta=0),Math.abs(i.rotateDeltaX)<.001&&(i.rotateDeltaX=0),Math.abs(i.rotateDeltaY)<.001&&(i.rotateDeltaY=0),0===i.rotateDeltaX&&0===i.rotateDeltaY||(i.dollyDelta=0),s.followPointer&&--c<=0&&(c=1,0!==i.dollyDelta)){if(0===i.rotateDeltaY&&0===i.rotateDeltaX&&s.followPointer&&n.followPointerDirty&&(r.pickCursorPos=n.pointerCanvasPos,r.schedulePickSurface=!0,r.update(),r.pickResult&&r.pickResult.worldPos?h=r.pickResult.worldPos:(u=1,h=null),n.followPointerDirty=!1),h){const t=Math.abs(A.lenVec3(A.subVec3(h,e.camera.eye,Ph)));u=t/s.dollyProximityThreshold}u{n.mouseover=!0}),a.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{n.mouseover=!1,a.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{_h(e,a,n.pointerCanvasPos)}),a.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(_h(e,a,n.pointerCanvasPos),n.mouseover=!0)}),a.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function _h(e,t,s){if(e){const{x:n,y:i}=t.getBoundingClientRect();s[0]=e.clientX-n,s[1]=e.clientY-i}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const Bh=function(e,t){if(e){let s=e.target,n=0,i=0;for(;s.offsetParent;)n+=s.offsetLeft,i+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-n,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class Oh{constructor(e,t,s,n,i){this._scene=e;const a=t.pickController,r=t.pivotController,l=A.vec2(),o=A.vec2(),c=A.vec2(),u=A.vec2(),h=[],p=this._scene.canvas.canvas;let d=0,f=!1;this._onTick=e.on("tick",(()=>{f=!1})),p.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const i=t.touches,o=t.changedTouches;for(n.touchStartTime=Date.now(),1===i.length&&1===o.length&&(Bh(i[0],l),s.followPointer&&(a.pickCursorPos=l,a.schedulePickSurface=!0,a.update(),s.planView||(a.picked&&a.pickedSurface&&a.pickResult&&a.pickResult.worldPos?(r.setPivotPos(a.pickResult.worldPos),!s.firstPerson&&r.startPivot()&&r.showPivot()):(s.smartPivot?r.setCanvasPivotPos(n.pointerCanvasPos):r.setPivotPos(e.camera.look),!s.firstPerson&&r.startPivot()&&r.showPivot()))));h.length{r.getPivoting()&&r.endPivot()}),p.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),f)return;f=!0;const r=e.canvas.boundary,l=r[2],p=r[3],I=t.touches;if(t.touches.length===d){if(1===d){Bh(I[0],o),A.subVec2(o,h[0],u);const t=u[0],a=u[1];if(null!==n.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(a)>s.longTapRadius)&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),s.planView){const n=e.camera;if("perspective"===n.projection){const r=Math.abs(e.camera.eyeLookDist)*Math.tan(n.perspective.fov/2*Math.PI/180);i.panDeltaX+=t*r/p*s.touchPanRate,i.panDeltaY+=a*r/p*s.touchPanRate}else i.panDeltaX+=.5*n.ortho.scale*(t/p)*s.touchPanRate,i.panDeltaY+=.5*n.ortho.scale*(a/p)*s.touchPanRate}else i.rotateDeltaY-=t/l*(1*s.dragRotationRate),i.rotateDeltaX+=a/p*(1.5*s.dragRotationRate)}else if(2===d){const t=I[0],r=I[1];Bh(t,o),Bh(r,c);const l=A.geometricMeanVec2(h[0],h[1]),u=A.geometricMeanVec2(o,c),d=A.vec2();A.subVec2(l,u,d);const f=d[0],y=d[1],m=e.camera,v=A.distVec2([t.pageX,t.pageY],[r.pageX,r.pageY]),w=(A.distVec2(h[0],h[1])-v)*s.touchDollyRate;if(i.dollyDelta=w,Math.abs(w)<1)if("perspective"===m.projection){const t=a.pickResult?a.pickResult.worldPos:e.center,n=Math.abs(A.lenVec3(A.subVec3(t,e.camera.eye,[])))*Math.tan(m.perspective.fov/2*Math.PI/180);i.panDeltaX-=f*n/p*s.touchPanRate,i.panDeltaY-=y*n/p*s.touchPanRate}else i.panDeltaX-=.5*m.ortho.scale*(f/p)*s.touchPanRate,i.panDeltaY-=.5*m.ortho.scale*(y/p)*s.touchPanRate;n.pointerCanvasPos=u}for(let e=0;e{let n;s&&s.worldPos&&(n=s.worldPos);const i=s?s.entity.aabb:e.aabb;if(n){const s=e.camera;A.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:i})}else t.cameraFlight.flyTo({aabb:i})};p.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null);const i=e.touches,a=e.changedTouches;if(l=Date.now(),1===i.length&&1===a.length){u=l,Sh(i[0],c);const a=c[0],r=c[1],o=i[0].pageX,h=i[0].pageY;n.longTouchTimeout=setTimeout((()=>{t.cameraControl.fire("rightClick",{pagePos:[Math.round(o),Math.round(h)],canvasPos:[Math.round(a),Math.round(r)],event:e},!0),n.longTouchTimeout=null}),s.longTapTimeout)}else u=-1;for(;o.length{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),i=e.touches,l=e.changedTouches,p=r.hasSubs("pickedSurface");null!==n.longTouchTimeout&&(clearTimeout(n.longTouchTimeout),n.longTouchTimeout=null),0===i.length&&1===l.length&&u>-1&&t-u<150&&(h>-1&&u-h<325?(Sh(l[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=p,a.update(),a.pickResult?(a.pickResult.touchInput=!0,r.fire("doublePicked",a.pickResult),a.pickedSurface&&r.fire("doublePickedSurface",a.pickResult),s.doublePickFlyTo&&d(a.pickResult)):(r.fire("doublePickedNothing"),s.doublePickFlyTo&&d()),h=-1):A.distVec2(o[0],c)<4&&(Sh(l[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=p,a.update(),a.pickResult?(a.pickResult.touchInput=!0,r.fire("picked",a.pickResult),a.pickedSurface&&r.fire("pickedSurface",a.pickResult)):r.fire("pickedNothing"),h=t),u=-1),o.length=i.length;for(let e=0,t=i.length;e{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:A.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:A.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new dh(this,this._configs),pivotController:new Ah(s,this._configs),panController:new rh(s),cameraFlight:new ye(this,{duration:.5})},this._handlers=[new Ch(this.scene,this._controllers,this._configs,this._states,this._updates),new Oh(this.scene,this._controllers,this._configs,this._states,this._updates),new Ih(this.scene,this._controllers,this._configs,this._states,this._updates),new Eh(this.scene,this._controllers,this._configs,this._states,this._updates),new bh(this.scene,this._controllers,this._configs,this._states,this._updates),new Nh(this.scene,this._controllers,this._configs,this._states,this._updates),new Dh(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cameraUpdater=new Rh(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",v.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;t||(t=this.scene.input.keyDown);for(let e=0,n=s.length;e0?Gh(t):null,r=s&&s.length>0?Gh(s):null,l=e=>{if(!e)return;var t=!0;(r&&r[e.type]||a&&!a[e.type])&&(t=!1),t&&n.push(e.id);const s=e.children;if(s)for(var i=0,o=s.length;i * Copyright (c) 2022 Niklas von Hertzen diff --git a/dist/xeokit-sdk.min.es5.js b/dist/xeokit-sdk.min.es5.js index 2ad31df785..eceabc1924 100644 --- a/dist/xeokit-sdk.min.es5.js +++ b/dist/xeokit-sdk.min.es5.js @@ -1,4 +1,4 @@ -var e,t=l().mark(qT),n=l().mark(JT),r=l().mark(lP);function i(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||A(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var o=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(o&&l){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),b(n),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;b(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:P(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},e}function u(e,t,n,r,i,a,s){try{var o=e[a](s),l=o.value}catch(e){return void n(e)}o.done?t(l):Promise.resolve(l).then(r,i)}function c(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function s(e){u(a,r,i,s,o,"next",e)}function o(e){u(a,r,i,s,o,"throw",e)}s(void 0)}))}}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=A(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}(e,t)||A(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._id=k.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==n.hideOnMouseDown&&(document.addEventListener("mousedown",(function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),n.items&&(this.items=n.items),this._hideOnAction=!1!==n.hideOnAction,this.context=n.context,this.enabled=!1!==n.enabled,this.hide()}return P(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r0,c=t._getNextId(),f=a.getTitle||function(){return a.title||""},p=a.doAction||a.callback||function(){},A=a.getEnabled||function(){return!0},d=a.getShown||function(){return!0},v=new Q(c,f,p,A,d);if(v.parentMenu=i,l.items.push(v),u){var h=e(s);v.subMenu=h,h.parentItem=v}t._itemList.push(v),t._itemMap[v.id]=v},c=0,f=o.length;c'),r.push("
    "),n)for(var i=0,a=n.length;i'+A+" [MORE]"):r.push('
  • '+A+"
  • ")}}r.push("
"),r.push("");var d=r.join("");document.body.insertAdjacentHTML("beforeend",d);var v=document.querySelector("."+e.id);e.menuElement=v,v.style["border-radius"]="4px",v.style.display="none",v.style["z-index"]=3e5,v.style.background="white",v.style.border="1px solid black",v.style["box-shadow"]="0 4px 5px 0 gray",v.oncontextmenu=function(e){e.preventDefault()};var h=this,I=null;if(n)for(var y=0,m=n.length;ywindow.innerWidth?h._showMenu(t.id,a.left-200,a.top-1):h._showMenu(t.id,a.right-5,a.top-1),I=t}}else I&&(h._hideMenu(I.id),I=null)})),i||(r.itemElement.addEventListener("click",(function(e){e.preventDefault(),h._context&&!1!==r.enabled&&(r.doAction&&r.doAction(h._context),t._hideOnAction?h.hide():(h._updateItemsTitles(),h._updateItemsEnabledStatus()))})),r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==r.enabled&&r.doHover&&r.doHover(h._context)})))},T=0,E=w.length;Twindow.innerHeight&&(n=window.innerHeight-r),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=n+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),z=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this.viewer=t,this.scene=this.viewer.scene,this._lensCursorDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._lensCursorDiv,this.viewer.scene.canvas.canvas),this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red",this._lensCursorDiv.style.borderRadius="20px",this._lensCursorDiv.style.width="10px",this._lensCursorDiv.style.height="10px",this._lensCursorDiv.style.margin="-200px -200px",this._lensCursorDiv.style.zIndex="100000",this._lensCursorDiv.style.position="absolute",this._lensCursorDiv.style.pointerEvents="none",this._lensContainer=document.createElement("div"),this._lensContainer.style.border="1px solid black",this._lensContainer.style.background="white",this._lensContainer.style.borderRadius="50%",this._lensContainer.style.width="300px",this._lensContainer.style.height="300px",this._lensContainer.style.marginTop="85px",this._lensContainer.style.marginLeft="25px",this._lensContainer.style.zIndex="15000",this._lensContainer.style.position="absolute",this._lensContainer.style.pointerEvents="none",this._lensContainer.style.visibility="hidden",this._lensCanvas=document.createElement("canvas"),this._lensCanvas.style.borderRadius="50%",this._lensCanvas.style.width="300px",this._lensCanvas.style.height="300px",this._lensCanvas.style.zIndex="15000",this._lensCanvas.style.pointerEvents="none",document.body.appendChild(this._lensContainer),this._lensContainer.appendChild(this._lensCanvas),this._lensCanvasContext=this._lensCanvas.getContext("2d"),this._canvasElement=this.viewer.scene.canvas.canvas,this._centerPos=null,this._cursorPos=null,this._lensPosToggle=!0,this._zoomLevel=r.zoomLevel||2,this._active=!1!==r.active,this._visible=!1,this._snapped=!1,this._onViewerRendering=this.viewer.scene.on("rendering",(function(){n._active&&n._visible&&n.update()}))}return P(e,[{key:"update",value:function(){if(this._active&&this._visible&&this._centerPos){var e=this._lensContainer.getBoundingClientRect(),t=this._canvasElement.getBoundingClientRect(),n=this._centerPos[0]e.left&&this._centerPos[1]e.top;this._lensContainer.style.marginLeft="25px",n&&(this._lensPosToggle?this._lensContainer.style.marginTop="".concat(t.bottom-t.top-this._lensCanvas.height-85,"px"):this._lensContainer.style.marginTop="85px",this._lensPosToggle=!this._lensPosToggle),this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);var r=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,this._centerPos[0]-r/2,this._centerPos[1]-r/2,r,r,0,0,this._lensCanvas.width,this._lensCanvas.height);var i=[(e.left+e.right)/2,(e.top+e.bottom)/2];if(this._cursorPos){var a=this._cursorPos[0]-this._centerPos[0],s=this._cursorPos[1]-this._centerPos[1];this._lensCursorDiv.style.marginLeft="".concat(i[0]+a*this._zoomLevel-10,"px"),this._lensCursorDiv.style.marginTop="".concat(i[1]+s*this._zoomLevel-10,"px")}else this._lensCursorDiv.style.marginLeft="".concat(i[0]-10,"px"),this._lensCursorDiv.style.marginTop="".concat(i[1]-10,"px")}}},{key:"zoomFactor",get:function(){return this._zoomFactor},set:function(e){this._zoomFactor=e,this.update()}},{key:"centerPos",get:function(){return this._centerPos},set:function(e){this._centerPos=e,this.update()}},{key:"cursorPos",get:function(){return this._cursorPos},set:function(e){this._cursorPos=e,this.update()}},{key:"snapped",get:function(){return this._snapped},set:function(e){this._snapped=e,e?(this._lensCursorDiv.style.background="greenyellow",this._lensCursorDiv.style.border="2px solid green"):(this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red")}},{key:"active",get:function(){return this._active},set:function(e){this._active=e,this._lensContainer.style.visibility=e&&this._visible?"visible":"hidden",e&&this._visible||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=e,this._lensContainer.style.visibility=e&&this._active?"visible":"hidden",e&&this._active||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}},{key:"destroy",value:function(){this._destroyed||(this.viewer.scene.off(this._onViewerRendering),this._lensContainer.removeChild(this._lensCanvas),document.body.removeChild(this._lensContainer),this._destroyed=!0)}}]),e}(),K=function(){function e(t,n,r){b(this,e),this.id=r&&r.id?r.id:t,this.viewer=n,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,n.addPlugin(this)}return P(e,[{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){console.log("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"warn",value:function(e){console.warn("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"error",value:function(e){console.error("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.removePlugin(this)}}]),e}(),Y=!0,X=Y?Float64Array:Float32Array,q=new X(16),J=new X(16),Z=new X(4),$={setDoublePrecisionEnabled:function(e){X=(Y=e)?Float64Array:Float32Array},getDoublePrecisionEnabled:function(){return Y},MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId:function(e,t){var n=t.indexOf("#");return n===e.length&&t.startsWith(e)?t.substring(n+1):t},globalizeObjectId:function(e,t){return e+"#"+t},safeInv:function(e){var t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:function(e){return new X(e||2)},vec3:function(e){return new X(e||3)},vec4:function(e){return new X(e||4)},mat3:function(e){return new X(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new X(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},mat4:function(e){return new X(e||16)},mat4ToMat3:function(e,t){},doublesToFloats:function(e,t,n){for(var r=new X(2),i=0,a=e.length;i>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&n]).concat(e[n>>8&255],"-").concat(e[n>>16&15|64]).concat(e[n>>24&255],"-").concat(e[63&r|128]).concat(e[r>>8&255],"-").concat(e[r>>16&255]).concat(e[r>>24&255]).concat(e[255&i]).concat(e[i>>8&255]).concat(e[i>>16&255]).concat(e[i>>24&255])}}(),clamp:function(e,t,n){return Math.max(t,Math.min(n,e))},fmod:function(e,t){if(e1?1:n,Math.acos(n)},vec3FromMat4Scale:function(){var e=new X(3);return function(t,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],n[0]=$.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],n[1]=$.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],n[2]=$.lenVec3(e),n}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var n=0,r=(t=Array.prototype.slice.call(t)).length;n0&&void 0!==arguments[0]?arguments[0]:new X(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},identityMat3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new X(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},isIdentityMat4:function(e){return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]},negateMat4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t},addMat4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n[4]=e[4]+t[4],n[5]=e[5]+t[5],n[6]=e[6]+t[6],n[7]=e[7]+t[7],n[8]=e[8]+t[8],n[9]=e[9]+t[9],n[10]=e[10]+t[10],n[11]=e[11]+t[11],n[12]=e[12]+t[12],n[13]=e[13]+t[13],n[14]=e[14]+t[14],n[15]=e[15]+t[15],n},addMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n[4]=e[4]+t,n[5]=e[5]+t,n[6]=e[6]+t,n[7]=e[7]+t,n[8]=e[8]+t,n[9]=e[9]+t,n[10]=e[10]+t,n[11]=e[11]+t,n[12]=e[12]+t,n[13]=e[13]+t,n[14]=e[14]+t,n[15]=e[15]+t,n},addScalarMat4:function(e,t,n){return $.addMat4Scalar(t,e,n)},subMat4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n[4]=e[4]-t[4],n[5]=e[5]-t[5],n[6]=e[6]-t[6],n[7]=e[7]-t[7],n[8]=e[8]-t[8],n[9]=e[9]-t[9],n[10]=e[10]-t[10],n[11]=e[11]-t[11],n[12]=e[12]-t[12],n[13]=e[13]-t[13],n[14]=e[14]-t[14],n[15]=e[15]-t[15],n},subMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n[4]=e[4]-t,n[5]=e[5]-t,n[6]=e[6]-t,n[7]=e[7]-t,n[8]=e[8]-t,n[9]=e[9]-t,n[10]=e[10]-t,n[11]=e[11]-t,n[12]=e[12]-t,n[13]=e[13]-t,n[14]=e[14]-t,n[15]=e[15]-t,n},subScalarMat4:function(e,t,n){return n||(n=t),n[0]=e-t[0],n[1]=e-t[1],n[2]=e-t[2],n[3]=e-t[3],n[4]=e-t[4],n[5]=e-t[5],n[6]=e-t[6],n[7]=e-t[7],n[8]=e-t[8],n[9]=e-t[9],n[10]=e-t[10],n[11]=e-t[11],n[12]=e-t[12],n[13]=e-t[13],n[14]=e-t[14],n[15]=e-t[15],n},mulMat4:function(e,t,n){n||(n=e);var r=e[0],i=e[1],a=e[2],s=e[3],o=e[4],l=e[5],u=e[6],c=e[7],f=e[8],p=e[9],A=e[10],d=e[11],v=e[12],h=e[13],I=e[14],y=e[15],m=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],L=t[15];return n[0]=m*r+w*o+g*f+T*v,n[1]=m*i+w*l+g*p+T*h,n[2]=m*a+w*u+g*A+T*I,n[3]=m*s+w*c+g*d+T*y,n[4]=E*r+b*o+D*f+P*v,n[5]=E*i+b*l+D*p+P*h,n[6]=E*a+b*u+D*A+P*I,n[7]=E*s+b*c+D*d+P*y,n[8]=R*r+C*o+_*f+B*v,n[9]=R*i+C*l+_*p+B*h,n[10]=R*a+C*u+_*A+B*I,n[11]=R*s+C*c+_*d+B*y,n[12]=O*r+S*o+N*f+L*v,n[13]=O*i+S*l+N*p+L*h,n[14]=O*a+S*u+N*A+L*I,n[15]=O*s+S*c+N*d+L*y,n},mulMat3:function(e,t,n){n||(n=new X(9));var r=e[0],i=e[3],a=e[6],s=e[1],o=e[4],l=e[7],u=e[2],c=e[5],f=e[8],p=t[0],A=t[3],d=t[6],v=t[1],h=t[4],I=t[7],y=t[2],m=t[5],w=t[8];return n[0]=r*p+i*v+a*y,n[3]=r*A+i*h+a*m,n[6]=r*d+i*I+a*w,n[1]=s*p+o*v+l*y,n[4]=s*A+o*h+l*m,n[7]=s*d+o*I+l*w,n[2]=u*p+c*v+f*y,n[5]=u*A+c*h+f*m,n[8]=u*d+c*I+f*w,n},mulMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n[4]=e[4]*t,n[5]=e[5]*t,n[6]=e[6]*t,n[7]=e[7]*t,n[8]=e[8]*t,n[9]=e[9]*t,n[10]=e[10]*t,n[11]=e[11]*t,n[12]=e[12]*t,n[13]=e[13]*t,n[14]=e[14]*t,n[15]=e[15]*t,n},mulMat4v4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=t[0],i=t[1],a=t[2],s=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12]*s,n[1]=e[1]*r+e[5]*i+e[9]*a+e[13]*s,n[2]=e[2]*r+e[6]*i+e[10]*a+e[14]*s,n[3]=e[3]*r+e[7]*i+e[11]*a+e[15]*s,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],a=e[13],s=e[12],o=e[9];if(!t||e===t){var l=e[1],u=e[2],c=e[3],f=e[6],p=e[7],A=e[11];return e[1]=n,e[2]=i,e[3]=s,e[4]=l,e[6]=o,e[7]=a,e[8]=u,e[9]=f,e[11]=r,e[12]=c,e[13]=p,e[14]=A,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=s,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=r,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3:function(e,t){if(t===e){var n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4:function(e){var t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],s=e[5],o=e[6],l=e[7],u=e[8],c=e[9],f=e[10],p=e[11],A=e[12],d=e[13],v=e[14],h=e[15];return A*c*o*i-u*d*o*i-A*s*f*i+a*d*f*i+u*s*v*i-a*c*v*i-A*c*r*l+u*d*r*l+A*n*f*l-t*d*f*l-u*n*v*l+t*c*v*l+A*s*r*p-a*d*r*p-A*n*o*p+t*d*o*p+a*n*v*p-t*s*v*p-u*s*r*h+a*c*r*h+u*n*o*h-t*c*o*h-a*n*f*h+t*s*f*h},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],a=e[3],s=e[4],o=e[5],l=e[6],u=e[7],c=e[8],f=e[9],p=e[10],A=e[11],d=e[12],v=e[13],h=e[14],I=e[15],y=n*o-r*s,m=n*l-i*s,w=n*u-a*s,g=r*l-i*o,T=r*u-a*o,E=i*u-a*l,b=c*v-f*d,D=c*h-p*d,P=c*I-A*d,R=f*h-p*v,C=f*I-A*v,_=p*I-A*h,B=1/(y*_-m*C+w*R+g*P-T*D+E*b);return t[0]=(o*_-l*C+u*R)*B,t[1]=(-r*_+i*C-a*R)*B,t[2]=(v*E-h*T+I*g)*B,t[3]=(-f*E+p*T-A*g)*B,t[4]=(-s*_+l*P-u*D)*B,t[5]=(n*_-i*P+a*D)*B,t[6]=(-d*E+h*w-I*m)*B,t[7]=(c*E-p*w+A*m)*B,t[8]=(s*C-o*P+u*b)*B,t[9]=(-n*C+r*P-a*b)*B,t[10]=(d*T-v*w+I*y)*B,t[11]=(-c*T+f*w-A*y)*B,t[12]=(-s*R+o*D-l*b)*B,t[13]=(n*R-r*D+i*b)*B,t[14]=(-d*g+v*m-h*y)*B,t[15]=(c*g-f*m+p*y)*B,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var n=t||$.identityMat4();return n[12]=e[0],n[13]=e[1],n[14]=e[2],n},translationMat3v:function(e,t){var n=t||$.identityMat3();return n[6]=e[0],n[7]=e[1],n},translationMat4c:(H=new X(3),function(e,t,n,r){return H[0]=e,H[1]=t,H[2]=n,$.translationMat4v(H,r)}),translationMat4s:function(e,t){return $.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return $.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,n,r){var i=r[3];r[0]+=i*e,r[1]+=i*t,r[2]+=i*n;var a=r[7];r[4]+=a*e,r[5]+=a*t,r[6]+=a*n;var s=r[11];r[8]+=s*e,r[9]+=s*t,r[10]+=s*n;var o=r[15];return r[12]+=o*e,r[13]+=o*t,r[14]+=o*n,r},setMat4Translation:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=e[15],n},rotationMat4v:function(e,t,n){var r,i,a,s,o,l,u=$.normalizeVec4([t[0],t[1],t[2],0],[]),c=Math.sin(e),f=Math.cos(e),p=1-f,A=u[0],d=u[1],v=u[2];return r=A*d,i=d*v,a=v*A,s=A*c,o=d*c,l=v*c,(n=n||$.mat4())[0]=p*A*A+f,n[1]=p*r+l,n[2]=p*a-o,n[3]=0,n[4]=p*r-l,n[5]=p*d*d+f,n[6]=p*i+s,n[7]=0,n[8]=p*a+o,n[9]=p*i-s,n[10]=p*v*v+f,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},rotationMat4c:function(e,t,n,r,i){return $.rotationMat4v(e,[t,n,r],i)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.identityMat4();return t[0]=e[0],t[5]=e[1],t[10]=e[2],t},scalingMat3v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new X(3);return function(t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,$.scalingMat4v(e,i)}}(),scaleMat4c:function(e,t,n,r){return r[0]*=e,r[4]*=t,r[8]*=n,r[1]*=e,r[5]*=t,r[9]*=n,r[2]*=e,r[6]*=t,r[10]*=n,r[3]*=e,r[7]*=t,r[11]*=n,r},scaleMat4v:function(e,t){var n=e[0],r=e[1],i=e[2];return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,t},scalingMat4s:function(e){return $.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.mat4(),r=e[0],i=e[1],a=e[2],s=e[3],o=r+r,l=i+i,u=a+a,c=r*o,f=r*l,p=r*u,A=i*l,d=i*u,v=a*u,h=s*o,I=s*l,y=s*u;return n[0]=1-(A+v),n[1]=f+y,n[2]=p-I,n[3]=0,n[4]=f-y,n[5]=1-(c+v),n[6]=d+h,n[7]=0,n[8]=p+I,n[9]=d-h,n[10]=1-(c+A),n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n},mat4ToEuler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=$.clamp,i=e[0],a=e[4],s=e[8],o=e[1],l=e[5],u=e[9],c=e[2],f=e[6],p=e[10];return"XYZ"===t?(n[1]=Math.asin(r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(-u,p),n[2]=Math.atan2(-a,i)):(n[0]=Math.atan2(f,l),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(u,-1,1)),Math.abs(u)<.99999?(n[1]=Math.atan2(s,p),n[2]=Math.atan2(o,l)):(n[1]=Math.atan2(-c,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(f,-1,1)),Math.abs(f)<.99999?(n[1]=Math.atan2(-c,p),n[2]=Math.atan2(-a,l)):(n[1]=0,n[2]=Math.atan2(o,i))):"ZYX"===t?(n[1]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[0]=Math.atan2(f,p),n[2]=Math.atan2(o,i)):(n[0]=0,n[2]=Math.atan2(-a,l))):"YZX"===t?(n[2]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-u,l),n[1]=Math.atan2(-c,i)):(n[0]=0,n[1]=Math.atan2(s,p))):"XZY"===t&&(n[2]=Math.asin(-r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(f,l),n[1]=Math.atan2(s,i)):(n[0]=Math.atan2(-u,p),n[1]=0)),n},composeMat4:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:$.mat4();return $.quaternionToRotationMat4(t,r),$.scaleMat4v(n,r),$.translateMat4v(e,r),r},decomposeMat4:function(){var e=new X(3),t=new X(16);return function(n,r,i,a){e[0]=n[0],e[1]=n[1],e[2]=n[2];var s=$.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var o=$.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var l=$.lenVec3(e);$.determinantMat4(n)<0&&(s=-s),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var u=1/s,c=1/o,f=1/l;return t[0]*=u,t[1]*=u,t[2]*=u,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=f,t[9]*=f,t[10]*=f,$.mat4ToQuaternion(t,i),a[0]=s,a[1]=o,a[2]=l,this}}(),getColMat4:function(e,t){var n=4*t;return[e[n],e[n+1],e[n+2],e[n+3]]},setRowMat4:function(e,t,n){e[t]=n[0],e[t+4]=n[1],e[t+8]=n[2],e[t+12]=n[3]},lookAtMat4v:function(e,t,n,r){r||(r=$.mat4());var i,a,s,o,l,u,c,f,p,A,d=e[0],v=e[1],h=e[2],I=n[0],y=n[1],m=n[2],w=t[0],g=t[1],T=t[2];return d===w&&v===g&&h===T?$.identityMat4():(i=d-w,a=v-g,s=h-T,o=y*(s*=A=1/Math.sqrt(i*i+a*a+s*s))-m*(a*=A),l=m*(i*=A)-I*s,u=I*a-y*i,(A=Math.sqrt(o*o+l*l+u*u))?(o*=A=1/A,l*=A,u*=A):(o=0,l=0,u=0),c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,(A=Math.sqrt(c*c+f*f+p*p))?(c*=A=1/A,f*=A,p*=A):(c=0,f=0,p=0),r[0]=o,r[1]=c,r[2]=i,r[3]=0,r[4]=l,r[5]=f,r[6]=a,r[7]=0,r[8]=u,r[9]=p,r[10]=s,r[11]=0,r[12]=-(o*d+l*v+u*h),r[13]=-(c*d+f*v+p*h),r[14]=-(i*d+a*v+s*h),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,a,s,o,l){return $.lookAtMat4v([e,t,n],[r,i,a],[s,o,l],[])},orthoMat4c:function(e,t,n,r,i,a,s){s||(s=$.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2/l,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=-2/u,s[11]=0,s[12]=-(e+t)/o,s[13]=-(r+n)/l,s[14]=-(a+i)/u,s[15]=1,s},frustumMat4v:function(e,t,n){n||(n=$.mat4());var r=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];$.addVec4(i,r,q),$.subVec4(i,r,J);var a=2*r[2],s=J[0],o=J[1],l=J[2];return n[0]=a/s,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=a/o,n[6]=0,n[7]=0,n[8]=q[0]/s,n[9]=q[1]/o,n[10]=-q[2]/l,n[11]=-1,n[12]=0,n[13]=0,n[14]=-a*i[2]/l,n[15]=0,n},frustumMat4:function(e,t,n,r,i,a,s){s||(s=$.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2*i/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2*i/l,s[6]=0,s[7]=0,s[8]=(t+e)/o,s[9]=(r+n)/l,s[10]=-(a+i)/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i*2/u,s[15]=0,s},perspectiveMat4:function(e,t,n,r,i){var a=[],s=[];return a[2]=n,s[2]=r,s[1]=a[2]*Math.tan(e/2),a[1]=-s[1],s[0]=s[1]*t,a[0]=-s[0],$.frustumMat4v(a,s,i)},compareMat4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]},transformPoint3:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec3(),r=t[0],i=t[1],a=t[2];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12],n[1]=e[1]*r+e[5]*i+e[9]*a+e[13],n[2]=e[2]*r+e[6]*i+e[10]*a+e[14],n},transformPoint4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4();return n[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],n[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],n[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],n[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],n},transformPoints3:function(e,t,n){for(var r,i,a,s,o,l=n||[],u=t.length,c=e[0],f=e[1],p=e[2],A=e[3],d=e[4],v=e[5],h=e[6],I=e[7],y=e[8],m=e[9],w=e[10],g=e[11],T=e[12],E=e[13],b=e[14],D=e[15],P=0;P2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2];e[3];var f=e[4],p=e[5],A=e[6];e[7];var d=e[8],v=e[9],h=e[10];e[11];var I=e[12],y=e[13],m=e[14];for(e[15],n=0;n2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n3&&void 0!==arguments[3]?arguments[3]:e,i=Math.cos(n),a=Math.sin(n),s=e[0]-t[0],o=e[1]-t[1];return r[0]=s*i-o*a+t[0],r[1]=s*a+o*i+t[1],e},rotateVec3X:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Y:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Z:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},projectVec4:function(e,t){var n=1/e[3];return(t=t||$.vec2())[0]=e[0]*n,t[1]=e[1]*n,t},unprojectVec3:(x=new X(16),M=new X(16),F=new X(16),function(e,t,n,r){return this.transformVec3(this.mulMat4(this.inverseMat4(t,x),this.inverseMat4(n,M),F),e,r)}),lerpVec3:function(e,t,n,r,i,a){var s=a||$.vec3(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s},lerpMat4:function(e,t,n,r,i,a){var s=a||$.mat4(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s[3]=r[3]+o*(i[3]-r[3]),s[4]=r[4]+o*(i[4]-r[4]),s[5]=r[5]+o*(i[5]-r[5]),s[6]=r[6]+o*(i[6]-r[6]),s[7]=r[7]+o*(i[7]-r[7]),s[8]=r[8]+o*(i[8]-r[8]),s[9]=r[9]+o*(i[9]-r[9]),s[10]=r[10]+o*(i[10]-r[10]),s[11]=r[11]+o*(i[11]-r[11]),s[12]=r[12]+o*(i[12]-r[12]),s[13]=r[13]+o*(i[13]-r[13]),s[14]=r[14]+o*(i[14]-r[14]),s[15]=r[15]+o*(i[15]-r[15]),s},flatten:function(e){var t,n,r,i,a,s=[];for(t=0,n=e.length;t0&&void 0!==arguments[0]?arguments[0]:$.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=e[0]*$.DEGTORAD/2,i=e[1]*$.DEGTORAD/2,a=e[2]*$.DEGTORAD/2,s=Math.cos(r),o=Math.cos(i),l=Math.cos(a),u=Math.sin(r),c=Math.sin(i),f=Math.sin(a);return"XYZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"YXZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"ZXY"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"ZYX"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"YZX"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l-u*c*f):"XZY"===t&&(n[0]=u*o*l-s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l+u*c*f),n},mat4ToQuaternion:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),r=e[0],i=e[4],a=e[8],s=e[1],o=e[5],l=e[9],u=e[2],c=e[6],f=e[10],p=r+o+f;return p>0?(t=.5/Math.sqrt(p+1),n[3]=.25/t,n[0]=(c-l)*t,n[1]=(a-u)*t,n[2]=(s-i)*t):r>o&&r>f?(t=2*Math.sqrt(1+r-o-f),n[3]=(c-l)/t,n[0]=.25*t,n[1]=(i+s)/t,n[2]=(a+u)/t):o>f?(t=2*Math.sqrt(1+o-r-f),n[3]=(a-u)/t,n[0]=(i+s)/t,n[1]=.25*t,n[2]=(l+c)/t):(t=2*Math.sqrt(1+f-r-o),n[3]=(s-i)/t,n[0]=(a+u)/t,n[1]=(l+c)/t,n[2]=.25*t),n},vec3PairToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=Math.sqrt($.dotVec3(e,e)*$.dotVec3(t,t)),i=r+$.dotVec3(e,t);return i<1e-8*r?(i=0,Math.abs(e[0])>Math.abs(e[2])?(n[0]=-e[1],n[1]=e[0],n[2]=0):(n[0]=0,n[1]=-e[2],n[2]=e[1])):$.cross3Vec3(e,t,n),n[3]=i,$.normalizeQuaternion(n)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),n=e[3]/2,r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},quaternionToEuler:function(){var e=new X(16);return function(t,n,r){return r=r||$.vec3(),$.quaternionToRotationMat4(t,e),$.mat4ToEuler(e,n,r),r}}(),mulQuaternions:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=e[0],i=e[1],a=e[2],s=e[3],o=t[0],l=t[1],u=t[2],c=t[3];return n[0]=s*o+r*c+i*u-a*l,n[1]=s*l+i*c+a*o-r*u,n[2]=s*u+a*c+r*l-i*o,n[3]=s*c-r*o-i*l-a*u,n},vec3ApplyQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec3(),r=t[0],i=t[1],a=t[2],s=e[0],o=e[1],l=e[2],u=e[3],c=u*r+o*a-l*i,f=u*i+l*r-s*a,p=u*a+s*i-o*r,A=-s*r-o*i-l*a;return n[0]=c*u+A*-s+f*-l-p*-o,n[1]=f*u+A*-o+p*-s-c*-l,n[2]=p*u+A*-l+c*-o-f*-s,n},quaternionToMat4:function(e,t){t=$.identityMat4(t);var n=e[0],r=e[1],i=e[2],a=e[3],s=2*n,o=2*r,l=2*i,u=s*a,c=o*a,f=l*a,p=s*n,A=o*n,d=l*n,v=o*r,h=l*r,I=l*i;return t[0]=1-(v+I),t[1]=A+f,t[2]=d-c,t[4]=A-f,t[5]=1-(p+I),t[6]=h+u,t[8]=d+c,t[9]=h-u,t[10]=1-(p+v),t},quaternionToRotationMat4:function(e,t){var n=e[0],r=e[1],i=e[2],a=e[3],s=n+n,o=r+r,l=i+i,u=n*s,c=n*o,f=n*l,p=r*o,A=r*l,d=i*l,v=a*s,h=a*o,I=a*l;return t[0]=1-(p+d),t[4]=c-I,t[8]=f+h,t[1]=c+I,t[5]=1-(u+d),t[9]=A-v,t[2]=f-h,t[6]=A+v,t[10]=1-(u+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=$.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n,t[3]=e[3]/n,t},conjugateQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},inverseQuaternion:function(e,t){return $.normalizeQuaternion($.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),n=(e=$.normalizeQuaternion(e,Z))[3],r=2*Math.acos(n),i=Math.sqrt(1-n*n);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=r,t},AABB3:function(e){return new X(e||6)},AABB2:function(e){return new X(e||4)},OBB3:function(e){return new X(e||32)},OBB2:function(e){return new X(e||16)},Sphere3:function(e,t,n,r){return new X([e,t,n,r])},transformOBB3:function(e,t){var n,r,i,a,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;no?s:o,a[1]+=l>u?l:u,a[2]+=c>f?c:f,Math.abs($.lenVec3(a))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var n=t||$.vec3();return n[0]=(e[0]+e[3])/2,n[1]=(e[1]+e[4])/2,n[2]=(e[2]+e[5])/2,n},getAABB2Center:function(e,t){var n=t||$.vec2();return n[0]=(e[2]+e[0])/2,n[1]=(e[3]+e[1])/2,n},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:$.AABB3();return e[0]=$.MAX_DOUBLE,e[1]=$.MAX_DOUBLE,e[2]=$.MAX_DOUBLE,e[3]=$.MIN_DOUBLE,e[4]=$.MIN_DOUBLE,e[5]=$.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.OBB3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t},positions3ToAABB3:function(){var e=new X(3);return function(t,n,r){n=n||$.AABB3();for(var i,a,s,o=$.MAX_DOUBLE,l=$.MAX_DOUBLE,u=$.MAX_DOUBLE,c=$.MIN_DOUBLE,f=$.MIN_DOUBLE,p=$.MIN_DOUBLE,A=0,d=t.length;Ac&&(c=i),a>f&&(f=a),s>p&&(p=s);return n[0]=o,n[1]=l,n[2]=u,n[3]=c,n[4]=f,n[5]=p,n}}(),OBB3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB3(),a=$.MAX_DOUBLE,s=$.MAX_DOUBLE,o=$.MAX_DOUBLE,l=$.MIN_DOUBLE,u=$.MIN_DOUBLE,c=$.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB3(),a=$.MAX_DOUBLE,s=$.MAX_DOUBLE,o=$.MAX_DOUBLE,l=$.MIN_DOUBLE,u=$.MIN_DOUBLE,c=$.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToSphere3:function(){var e=new X(3);return function(t,n){n=n||$.vec4();var r,i=0,a=0,s=0,o=t.length;for(r=0;ru&&(u=l);return n[3]=u,n}}(),positions3ToSphere3:function(){var e=new X(3),t=new X(3);return function(n,r){r=r||$.vec4();var i,a=0,s=0,o=0,l=n.length,u=0;for(i=0;iu&&(u=c);return r[3]=u,r}}(),OBB3ToSphere3:function(){var e=new X(3),t=new X(3);return function(n,r){r=r||$.vec4();var i,a=0,s=0,o=0,l=n.length,u=l/4;for(i=0;if&&(f=c);return r[3]=f,r}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},getPositionsCenter:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec3(),n=0,r=0,i=0,a=0,s=e.length;at[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]n&&(e[0]=n),e[1]>r&&(e[1]=r),e[2]>i&&(e[2]=i),e[3]0&&void 0!==arguments[0]?arguments[0]:$.AABB2();return e[0]=$.MAX_DOUBLE,e[1]=$.MAX_DOUBLE,e[2]=$.MIN_DOUBLE,e[3]=$.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(r=e[0]*n[0],i=e[0]*n[3]):(r=e[0]*n[3],i=e[0]*n[0]),e[1]>0?(r+=e[1]*n[1],i+=e[1]*n[4]):(r+=e[1]*n[4],i+=e[1]*n[1]),e[2]>0?(r+=e[2]*n[2],i+=e[2]*n[5]):(r+=e[2]*n[5],i+=e[2]*n[2]),r<=-t&&i<=-t?-1:r>=-t&&i>=-t?1:0},OBB3ToAABB2:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB2(),a=$.MAX_DOUBLE,s=$.MAX_DOUBLE,o=$.MIN_DOUBLE,l=$.MIN_DOUBLE,u=0,c=e.length;uo&&(o=t),n>l&&(l=n);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i},expandAABB2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]3&&void 0!==arguments[3]?arguments[3]:e,i=.5*(e[0]+1),a=.5*(e[1]+1),s=.5*(e[2]+1),o=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(o*n),r[2]=Math.floor(s*t),r[3]=n-Math.floor(a*n),r},tangentQuadraticBezier:function(e,t,n,r){return 2*(1-e)*(n-t)+2*e*(r-n)},tangentQuadraticBezier3:function(e,t,n,r,i){return-3*t*(1-e)*(1-e)+3*n*(1-e)*(1-e)-6*e*n*(1-e)+6*e*r*(1-e)-3*e*e*r+3*e*e*i},tangentSpline:function(e){return 6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e)},catmullRomInterpolate:function(e,t,n,r,i){var a=.5*(n-e),s=.5*(r-t),o=i*i;return(2*t-2*n+a+s)*(i*o)+(-3*t+3*n-2*a-s)*o+a*i+t},b2p0:function(e,t){var n=1-e;return n*n*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,n,r){return this.b2p0(e,t)+this.b2p1(e,n)+this.b2p2(e,r)},b3p0:function(e,t){var n=1-e;return n*n*n*t},b3p1:function(e,t){var n=1-e;return 3*n*n*e*t},b3p2:function(e,t){return 3*(1-e)*e*e*t},b3p3:function(e,t){return e*e*e*t},b3:function(e,t,n,r,i){return this.b3p0(e,t)+this.b3p1(e,n)+this.b3p2(e,r)+this.b3p3(e,i)},triangleNormal:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:$.vec3(),i=t[0]-e[0],a=t[1]-e[1],s=t[2]-e[2],o=n[0]-e[0],l=n[1]-e[1],u=n[2]-e[2],c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,A=Math.sqrt(c*c+f*f+p*p);return 0===A?(r[0]=0,r[1]=0,r[2]=0):(r[0]=c/A,r[1]=f/A,r[2]=p/A),r},rayTriangleIntersect:function(){var e=new X(3),t=new X(3),n=new X(3),r=new X(3),i=new X(3);return function(a,s,o,l,u,c){c=c||$.vec3();var f=$.subVec3(l,o,e),p=$.subVec3(u,o,t),A=$.cross3Vec3(s,p,n),d=$.dotVec3(f,A);if(d<1e-6)return null;var v=$.subVec3(a,o,r),h=$.dotVec3(v,A);if(h<0||h>d)return null;var I=$.cross3Vec3(v,f,i),y=$.dotVec3(s,I);if(y<0||h+y>d)return null;var m=$.dotVec3(p,I)/d;return c[0]=a[0]+m*s[0],c[1]=a[1]+m*s[1],c[2]=a[2]+m*s[2],c}}(),rayPlaneIntersect:function(){var e=new X(3),t=new X(3),n=new X(3),r=new X(3);return function(i,a,s,o,l,u){u=u||$.vec3(),a=$.normalizeVec3(a,e);var c=$.subVec3(o,s,t),f=$.subVec3(l,s,n),p=$.cross3Vec3(c,f,r);$.normalizeVec3(p,p);var A=-$.dotVec3(s,p),d=-($.dotVec3(i,p)+A)/$.dotVec3(a,p);return u[0]=i[0]+d*a[0],u[1]=i[1]+d*a[1],u[2]=i[2]+d*a[2],u}}(),cartesianToBarycentric:function(){var e=new X(3),t=new X(3),n=new X(3);return function(r,i,a,s,o){var l=$.subVec3(s,i,e),u=$.subVec3(a,i,t),c=$.subVec3(r,i,n),f=$.dotVec3(l,l),p=$.dotVec3(l,u),A=$.dotVec3(l,c),d=$.dotVec3(u,u),v=$.dotVec3(u,c),h=f*d-p*p;if(0===h)return null;var I=1/h,y=(d*A-p*v)*I,m=(f*v-p*A)*I;return o[0]=1-y-m,o[1]=m,o[2]=y,o}}(),barycentricInsideTriangle:function(e){var t=e[1],n=e[2];return n>=0&&t>=0&&n+t<1},barycentricToCartesian:function(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:$.vec3(),a=e[0],s=e[1],o=e[2];return i[0]=t[0]*a+n[0]*s+r[0]*o,i[1]=t[1]*a+n[1]*s+r[1]*o,i[2]=t[2]*a+n[2]*s+r[2]*o,i},mergeVertices:function(e,t,n,r){var i,a,s,o,l,u,c={},f=[],p=[],A=t?[]:null,d=n?[]:null,v=[],h=Math.pow(10,4),I=0;for(l=0,u=e.length;l>24&255,s=f>>16&255,a=f>>8&255,i=255&f,r=3*t[d],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+1],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+2],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,f++;return{positions:u,colors:c}},faceToVertexNormals:function(e,t){var n,r,i,a,s,o,l,u,c,f,p,A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},d=A.smoothNormalsAngleThreshold||20,v={},h=[],I={},y=4,m=Math.pow(10,y);for(l=0,c=e.length;ll[3]&&(l[3]=i[p]),i[p+1]l[4]&&(l[4]=i[p+1]),i[p+2]l[5]&&(l[5]=i[p+2])}if(n.length<20||a>10)return u.triangles=n,u.leaf=!0,u;e[0]=l[3]-l[0],e[1]=l[4]-l[1],e[2]=l[5]-l[2];var A=0;e[1]>e[A]&&(A=1),e[2]>e[A]&&(A=2),u.splitDim=A;var d=(l[A]+l[A+3])/2,v=new Array(n.length),h=0,I=new Array(n.length),y=0;for(s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t},octDecodeVec2s:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t}};$.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=$.vec3(),c=$.vec3(),f=$.vec3(),p=$.vec3(),A=$.vec3(),d=$.vec3(),v=$.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var ee=function(){function e(){b(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return P(e,[{key:"length",get:function(){return this._length}},{key:"shift",value:function(){if(this._index>=this._headLength){var e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}var t=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,t}},{key:"push",value:function(e){return this._length++,this._tail.push(e),this}},{key:"unshift",value:function(e){return this._head[--this._index]=e,this._length++,this}}]),e}(),te={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var ne=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],n=e[0].charCodeAt(0),r=n+e[1],i=n;i0&&void 0!==arguments[0]?arguments[0]:-1,r=(new Date).getTime(),i=0;ue.length>0&&(n<0||r0&&ae>0){var n=1e3/ae;Ae+=n,fe.push(n),fe.length>=30&&(Ae-=fe.shift()),te.frame.fps=Math.round(Ae/fe.length)}!function(e){var t=de.runTasks(e+10),n=de.getNumTasks();te.frame.tasksRun=t,te.frame.tasksScheduled=n,te.frame.tasksBudget=10}(t),function(e){for(var t in ce.time=e,de.scenes)if(de.scenes.hasOwnProperty(t)){var n=de.scenes[t];ce.sceneId=t,ce.startTime=n.startTime,ce.deltaTime=null!=ce.prevTime?ce.time-ce.prevTime:0,n.fire("tick",ce,!0)}ce.prevTime=e}(t),function(){var e,t,n,r,i,a=de.scenes,s=!1;for(i in a)a.hasOwnProperty(i)&&(e=a[i],(t=oe[i])||(t=oe[i]={}),n=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==n&&(t.ticksPerOcclusionTest=n,t.renderCountdown=n),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=n),r=e.ticksPerRender,t.ticksPerRender!==r&&(t.ticksPerRender=r,t.renderCountdown=r),0==--t.renderCountdown&&(e.render(s),t.renderCountdown=r))}(),pe=t,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(e):requestAnimationFrame(e)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(ve):requestAnimationFrame(ve);var he=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=n.viewer;else{if("Scene"===t.type)this.scene=t;else{if(!(t instanceof e))throw"Invalid param: owner must be a Component";this.scene=t.scene}this._owner=t}this._dontClear=!!n.dontClear,this._renderer=this.scene._renderer,this.meta=n.meta||{},this.id=n.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,t&&t._own(this)}return P(e,[{key:"type",get:function(){return"Component"}},{key:"isComponent",get:function(){return!0}},{key:"glRedraw",value:function(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}},{key:"glResort",value:function(){this._renderer&&this._renderer.needStateSort()}},{key:"owner",get:function(){return this._owner}},{key:"isType",value:function(e){return this.type===e}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}},{key:"_message",value:function(e){return" ["+this.type+" "+se.inQuotes(this.id)+"]: "+e}},{key:"warn",value:function(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}},{key:"error",value:function(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}},{key:"_attach",value:function(e){var t=e.name;if(t){var n=e.component,r=e.sceneDefault,i=e.sceneSingleton,a=e.type,s=e.on,o=!1!==e.recompiles;if(n&&(se.isNumeric(n)||se.isString(n))){var l=n;if(!(n=this.scene.components[l]))return void this.error("Component not found: "+se.inQuotes(l))}if(!n)if(!0===i){var u=this.scene.types[a];for(var c in u)if(u.hasOwnProperty){n=u[c];break}if(!n)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===r&&!(n=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(n){if(n.scene.id!==this.scene.id)return void this.error("Not in same scene: "+n.type+" "+se.inQuotes(n.id));if(a&&!n.isType(a))return void this.error("Expected a "+a+" type or subtype: "+n.type+" "+se.inQuotes(n.id))}this._attachments||(this._attachments={});var f,p,A,d=this._attached[t];if(d){if(n&&d.id===n.id)return;var v=this._attachments[d.id];for(p=0,A=(f=v.subs).length;p3&&void 0!==arguments[3]?arguments[3]:1e3,i=$.getPositionsCenter(e,Ie),a=Math.round(i[0]/r)*r,s=Math.round(i[1]/r)*r,o=Math.round(i[2]/r)*r;n[0]=a,n[1]=s,n[2]=o;var l=0!==n[0]||0!==n[1]||0!==n[2];if(l)for(var u=0,c=e.length;u0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,n=this.meshes[0]._colorize[3],r=255;if(t){if(e<0?e=0:e>1&&(e=1),n===(r=Math.floor(255*e)))return}else if(n===(r=255))return;for(var i=0,a=this.meshes.length;i1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._color=r.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=r.thickness||1,this._thicknessClickable=r.thicknessClickable||6;var i=this._wire,a=i.style;a.border="solid "+this._thickness+"px "+this._color,a.position="absolute",a["z-index"]=void 0===r.zIndex?"2000001":r.zIndex,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._wireClickable,o=s.style;o.border="solid "+this._thicknessClickable+"px "+this._color,o.position="absolute",o["z-index"]=void 0===r.zIndex?"2000002":r.zIndex+1,o.width="0px",o.height="0px",o.visibility="visible",o.top="0px",o.left="0px",o["-webkit-transform-origin"]="0 0",o["-moz-transform-origin"]="0 0",o["-ms-transform-origin"]="0 0",o["-o-transform-origin"]="0 0",o["transform-origin"]="0 0",o["-webkit-transform"]="rotate(0deg)",o["-moz-transform"]="rotate(0deg)",o["-ms-transform"]="rotate(0deg)",o["-o-transform"]="rotate(0deg)",o.transform="rotate(0deg)",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}return P(e,[{key:"_visible",get:function(){return"visible"===this._wire.style.visibility}},{key:"_update",value:function(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,n=this._wire.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)";var r=this._wireClickable.style;r.width=Math.round(e)+"px",r.left=Math.round(this._x1)+"px",r.top=Math.round(this._y1)+"px",r["-webkit-transform"]="rotate("+t+"deg)",r["-moz-transform"]="rotate("+t+"deg)",r["-ms-transform"]="rotate("+t+"deg)",r["-o-transform"]="rotate("+t+"deg)",r.transform="rotate("+t+"deg)"}},{key:"setStartAndEnd",value:function(e,t,n,r){this._x1=e,this._y1=t,this._x2=n,this._y2=r,this._update()}},{key:"setColor",value:function(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}},{key:"setOpacity",value:function(e){this._wire.style.opacity=e}},{key:"setVisible",value:function(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}},{key:"setClickable",value:function(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}},{key:"destroy",value:function(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}]),e}(),Ge=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var i=this._dot,a=i.style;a["border-radius"]="25px",a.border="solid 2px white",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"40000005":r.zIndex,a.width="8px",a.height="8px",a.visibility=!1!==r.visible?"visible":"hidden",a.top="0px",a.left="0px",a["box-shadow"]="0 2px 5px 0 #182A3D;",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._dotClickable,o=s.style;o["border-radius"]="35px",o.border="solid 10px white",o.position="absolute",o["z-index"]=void 0===r.zIndex?"40000007":r.zIndex+1,o.width="8px",o.height="8px",o.visibility="visible",o.top="0px",o.left="0px",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.borderColor)}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._dot.style;n.left=Math.round(e)-4+"px",n.top=Math.round(t)-4+"px";var r=this._dotClickable.style;r.left=Math.round(e)-9+"px",r.top=Math.round(t)-9+"px"}},{key:"setFillColor",value:function(e){this._dot.style.background=e||"lightgreen"}},{key:"setBorderColor",value:function(e){this._dot.style.border="solid 2px"+(e||"black")}},{key:"setOpacity",value:function(e){this._dot.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}},{key:"setClickable",value:function(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}},{key:"destroy",value:function(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}]),e}(),ke=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-label-highlighted",this._prefix=r.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var i=this._label,a=i.style;a["border-radius"]="5px",a.color="white",a.padding="4px",a.border="solid 1px",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"5000005":r.zIndex,a.width="auto",a.height="auto",a.visibility="visible",a.top="0px",a.left="0px",a["pointer-events"]="all",a.opacity=1,r.onContextMenu,i.innerText="",t.appendChild(i),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.fillColor),this.setText(r.text),r.onMouseOver&&i.addEventListener("mouseover",(function(e){r.onMouseOver(e,n),e.preventDefault()})),r.onMouseLeave&&i.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n),e.preventDefault()})),r.onMouseWheel&&i.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&i.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()}))}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._label.style;n.left=Math.round(e)-20+"px",n.top=Math.round(t)-12+"px"}},{key:"setPosOnWire",value:function(e,t,n,r){var i=e+.5*(n-e),a=t+.5*(r-t),s=this._label.style;s.left=Math.round(i)-20+"px",s.top=Math.round(a)-12+"px"}},{key:"setPosBetweenWires",value:function(e,t,n,r,i,a){var s=(e+n+i)/3,o=(t+r+a)/3,l=this._label.style;l.left=Math.round(s)-20+"px",l.top=Math.round(o)-12+"px"}},{key:"setText",value:function(e){this._label.innerHTML=this._prefix+(e||"")}},{key:"setFillColor",value:function(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}},{key:"setBorderColor",value:function(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}},{key:"setOpacity",value:function(e){this._label.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}},{key:"setClickable",value:function(e){this._label.style["pointer-events"]=e?"all":"none"}},{key:"destroy",value:function(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}]),e}(),je=$.vec3(),Ve=$.vec3(),Qe=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._color=i.color||e.defaultColor;var a=r.plugin.viewer.scene;r._originMarker=new He(a,i.origin),r._cornerMarker=new He(a,i.corner),r._targetMarker=new He(a,i.target),r._originWorld=$.vec3(),r._cornerWorld=$.vec3(),r._targetWorld=$.vec3(),r._wp=new Float64Array(12),r._vp=new Float64Array(12),r._pp=new Float64Array(12),r._cp=new Int16Array(6);var s=i.onMouseOver?function(e){i.onMouseOver(e,g(r))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,g(r))}:null,l=i.onContextMenu?function(e){i.onContextMenu(e,g(r))}:null,u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new Ge(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._cornerDot=new Ge(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetDot=new Ge(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._originWire=new Ue(r._container,{color:r._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetWire=new Ue(r._container,{color:r._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._angleLabel=new ke(r._container,{fillColor:r._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._visible=!1,r._originVisible=!1,r._cornerVisible=!1,r._targetVisible=!1,r._originWireVisible=!1,r._targetWireVisible=!1,r._angleVisible=!1,r._labelsVisible=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._cornerMarker.on("worldPos",(function(e){r._cornerWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.cornerVisible=i.cornerVisible,r.targetVisible=i.targetVisible,r.originWireVisible=i.originWireVisible,r.targetWireVisible=i.targetWireVisible,r.angleVisible=i.angleVisible,r.labelsVisible=i.labelsVisible,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&($.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){var t=-.3,n=this._originMarker.viewPos[2],r=this._cornerMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(n>t||r>t||i>t)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);$.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var a=this._pp,s=this._cp,o=e.canvas.canvas.getBoundingClientRect(),l=this._container.getBoundingClientRect(),u=o.top-l.top,c=o.left-l.left,f=e.canvas.boundary,p=f[2],A=f[3],d=0,v=0,h=a.length;v0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return P(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var n=this._messages[this._locale];if(!n)return null;var r=ze(e,n);return r?t?Ke(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=ze(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=Ke(i,[t]),n&&(i=Ke(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new G),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function ze(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,a=n.length;r&&i1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var Ye=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).t=i.t,r}return P(n,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),a=this.getPoint(r),s=$.subVec3(a,i,[]);return $.normalizeVec3(s,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,n,r=[],i=this.getPoint(0),a=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),a+=$.lenVec3($.subVec3(t,i,[])),r.push(a),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,a=r.length;n=t||e*r[a-1];for(var s,o=0,l=a-1;o<=l;)if((s=r[i=Math.floor(o+(l-o)/2)]-n)<0)o=i+1;else{if(!(s>0)){l=i;break}l=i-1}if(r[i=l]===n)return i/(a-1);var u=r[i];return(i+(n-u)/(r[i+1]-u))/(a-1)}}]),n}(),Xe=function(e){I(n,Ye);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return P(n,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var n=(t.length-1)*e,r=Math.floor(n),i=n-r,a=t[0===r?r:r-1],s=t[r],o=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=$.vec3();return u[0]=$.catmullRomInterpolate(a[0],s[0],o[0],l[0],i),u[1]=$.catmullRomInterpolate(a[1],s[1],o[1],l[1],i),u[2]=$.catmullRomInterpolate(a[2],s[2],o[2],l[2],i),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),n}(),qe=$.vec3(),Je=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new Xe(g(r)),r._lookCurve=new Xe(g(r)),r._upCurve=new Xe(g(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return P(n,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n1?1:e,t.eye=this._eyeCurve.getPoint(e,qe),t.look=this._lookCurve.getPoint(e,qe),t.up=this._upCurve.getPoint(e,qe)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=$.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,a=this._frames.length;i1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._look1=$.vec3(),r._eye1=$.vec3(),r._up1=$.vec3(),r._look2=$.vec3(),r._eye2=$.vec3(),r._up2=$.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return P(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=n;var r,i,a,s,o,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,a=e.look,s=e.up;else if(e.eye)i=e.eye;else if(e.look)a=e.look;else{var c=e;if((se.isNumeric(c)||se.isString(c))&&(o=c,!(c=this.scene.components[o])))return this.error("Component not found: "+se.inQuotes(o)),void(t&&(n?t.call(n):t()));u||(r=c.aabb||this.scene.aabb)}var f=e.poi;if(r){if(r[3]=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?($.subVec3(i.eye,i.look,nt),i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,et),i.look=$.subVec3(et,nt,$e)):this._flyingLook&&(i.look=$.lerpVec3(r,0,1,this._look1,this._look2,$e),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,tt)):this._flyingEyeLookUp&&(i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,et),i.look=$.lerpVec3(r,0,1,this._look1,this._look2,$e),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,tt)),this._projection2){var a="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=$.lerpMat4(a,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();de.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),v(T(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),it=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new rt(g(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,g(r)),r}return P(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),a=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==a)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*a,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*a*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=n.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();it.STOPPED=0,it.SCRUBBING=1,it.PLAYING=2,it.PLAYING_TO=3;var at=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),r=t.call(this,e,i),te.memory.meshes++,r}return P(n,[{key:"type",get:function(){return"Geometry"}},{key:"isGeometry",get:function(){return!0}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),te.memory.meshes--}}]),n}(),st=new G({}),ot=function(){function e(t){for(var n in b(this,e),this.id=st.addItem({}),t)t.hasOwnProperty(n)&&(this[n]=t[n])}return P(e,[{key:"destroy",value:function(){st.removeItem(this.id)}}]),e}(),lt=function(){function e(t,n,r,i,a,s,o,l,u){switch(b(this,e),this._gl=t,this.type=n,this.allocated=!1,r.constructor){case Uint8Array:this.itemType=t.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=t.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=t.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=t.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=t.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=t.INT,this.itemByteSize=4;break;default:this.itemType=t.FLOAT,this.itemByteSize=4}this.usage=s,this.length=0,this.dataLength=i,this.numItems=0,this.itemSize=a,this.normalized=!!o,this.stride=l||0,this.offset=u||0,this._allocate(r)}return P(e,[{key:"_allocate",value:function(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}},{key:"setData",value:function(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}},{key:"bind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}},{key:"unbind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,null)}},{key:"destroy",value:function(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}]),e}(),ut=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=$.vec3(),c=$.vec3(),f=$.vec3(),p=$.vec3(),A=$.vec3(),d=$.vec3(),v=$.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var ct=function(){var e=$.mat4(),t=$.mat4();return function(n,r){r=r||$.mat4();var i=n[0],a=n[1],s=n[2],o=n[3]-i,l=n[4]-a,u=n[5]-s,c=65535;return $.identityMat4(e),$.translationMat4v(n,e),$.identityMat4(t),$.scalingMat4v([o/c,l/c,u/c],t),$.mulMat4(e,t,r),r}}(),ft=function(){var e=$.mat4(),t=$.mat4();return function(n,r,i){var a,s=new Uint16Array(n.length),o=new Float32Array([i[0]!==r[0]?65535/(i[0]-r[0]):0,i[1]!==r[1]?65535/(i[1]-r[1]):0,i[2]!==r[2]?65535/(i[2]-r[2]):0]);for(a=0;a=0?1:-1),o=(1-Math.abs(i))*(a>=0?1:-1);i=s,a=o}return new Int8Array([Math[n](127.5*i+(i<0?-1:0)),Math[r](127.5*a+(a<0?-1:0))])}function dt(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}function vt(e,t,n){return e[t]*n[0]+e[t+1]*n[1]+e[t+2]*n[2]}var ht={getPositionsBounds:function(e){var t,n,r=new Float32Array(3),i=new Float32Array(3);for(t=0;t<3;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:e;return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n[3]=e[3]*t[0]+t[12],n[4]=e[4]*t[5]+t[13],n[5]=e[5]*t[10]+t[14],n},getUVBounds:function(e){var t,n,r=new Float32Array(2),i=new Float32Array(2);for(t=0;t<2;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;ri&&(n=t,i=r),(r=vt(e,s,dt(t=At(e,s,"floor","ceil"))))>i&&(n=t,i=r),(r=vt(e,s,dt(t=At(e,s,"ceil","ceil"))))>i&&(n=t,i=r),a[s]=n[0],a[s+1]=n[1];return a},decompressNormals:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t},decompressNormal:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t}},It=te.memory,yt=$.AABB3(),mt=function(e){I(n,at);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._state=new ot({compressGeometry:!!i.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._edgeIndicesBuf=null,r._pickTrianglePositionsBuf=null,r._pickTriangleColorsBuf=null,r._aabbDirty=!0,r._boundingSphere=!0,r._aabb=null,r._aabbDirty=!0,r._obb=null,r._obbDirty=!0;var a=r._state,s=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":a.primitive=s.POINTS,a.primitiveName=i.primitive;break;case"lines":a.primitive=s.LINES,a.primitiveName=i.primitive;break;case"line-loop":a.primitive=s.LINE_LOOP,a.primitiveName=i.primitive;break;case"line-strip":a.primitive=s.LINE_STRIP,a.primitiveName=i.primitive;break;case"triangles":a.primitive=s.TRIANGLES,a.primitiveName=i.primitive;break;case"triangle-strip":a.primitive=s.TRIANGLE_STRIP,a.primitiveName=i.primitive;break;case"triangle-fan":a.primitive=s.TRIANGLE_FAN,a.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),a.primitive=s.TRIANGLES,a.primitiveName=i.primitive}if(i.positions)if(r._state.compressGeometry){var o=ht.getPositionsBounds(i.positions),l=ht.compressPositions(i.positions,o.min,o.max);a.positions=l.quantized,a.positionsDecodeMatrix=l.decodeMatrix}else a.positions=i.positions.constructor===Float32Array?i.positions:new Float32Array(i.positions);if(i.colors&&(a.colors=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors)),i.uv)if(r._state.compressGeometry){var u=ht.getUVBounds(i.uv),c=ht.compressUVs(i.uv,u.min,u.max);a.uv=c.quantized,a.uvDecodeMatrix=c.decodeMatrix}else a.uv=i.uv.constructor===Float32Array?i.uv:new Float32Array(i.uv);return i.normals&&(r._state.compressGeometry?a.normals=ht.compressNormals(i.normals):a.normals=i.normals.constructor===Float32Array?i.normals:new Float32Array(i.normals)),i.indices&&(a.indices=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3)),r._buildHash(),It.meshes++,r._buildVBOs(),r}return P(n,[{key:"type",get:function(){return"ReadableGeometry"}},{key:"isReadableGeometry",get:function(){return!0}},{key:"_buildVBOs",value:function(){var e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),It.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new lt(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),It.positions+=e.positionsBuf.numItems),e.normals){var n=e.compressGeometry;e.normalsBuf=new lt(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,n),It.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new lt(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),It.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new lt(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),It.uvs+=e.uvBuf.numItems)}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}},{key:"_getPickTrianglePositions",value:function(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}},{key:"_getPickTriangleColors",value:function(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}},{key:"_buildEdgeIndices",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=ut(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,n,n.length,1,t.STATIC_DRAW),It.indices+=this._edgeIndicesBuf.numItems}}},{key:"_buildPickTriangleVBOs",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=$.buildPickTriangles(e.positions,e.indices,e.compressGeometry),r=n.positions,i=n.colors;this._pickTrianglePositionsBuf=new lt(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new lt(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),It.positions+=this._pickTrianglePositionsBuf.numItems,It.colors+=this._pickTriangleColorsBuf.numItems}}},{key:"_buildPickVertexVBOs",value:function(){}},{key:"_webglContextLost",value:function(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}},{key:"_webglContextRestored",value:function(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"compressGeometry",get:function(){return this._state.compressGeometry}},{key:"positions",get:function(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),ht.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null},set:function(e){var t=this._state,n=t.positions;if(n)if(n.length===e.length){if(this._state.compressGeometry){var r=ht.getPositionsBounds(e),i=ht.compressPositions(e,r.min,r.max);e=i.quantized,t.positionsDecodeMatrix=i.decodeMatrix}n.set(e),t.positionsBuf&&t.positionsBuf.setData(n),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}},{key:"normals",get:function(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){var e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),ht.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry normals - quantized geometry is immutable");else{var t=this._state,n=t.normals;n?n.length===e.length?(n.set(e),t.normalsBuf&&t.normalsBuf.setData(n),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}}},{key:"uv",get:function(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),ht.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry UVs - quantized geometry is immutable");else{var t=this._state,n=t.uv;n?n.length===e.length?(n.set(e),t.uvBuf&&t.uvBuf.setData(n),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}}},{key:"colors",get:function(){return this._state.colors},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry colors - quantized geometry is immutable");else{var t=this._state,n=t.colors;n?n.length===e.length?(n.set(e),t.colorsBuf&&t.colorsBuf.setData(n),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}}},{key:"indices",get:function(){return this._state.indices}},{key:"aabb",get:function(){return this._aabbDirty&&(this._aabb||(this._aabb=$.AABB3()),$.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}},{key:"obb",get:function(){return this._obbDirty&&(this._obb||(this._obb=$.OBB3()),$.positions3ToAABB3(this._state.positions,yt,this._state.positionsDecodeMatrix),$.AABB3ToOBB3(yt,this._obb),this._obbDirty=!1),this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_setAABBDirty",value:function(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),It.meshes--}}]),n}(),wt=te.memory,gt=$.AABB3(),Tt=function(e){I(n,at);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._state=new ot({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._aabb=null,r._obb=$.OBB3();var a,s=r._state,o=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":s.primitive=o.POINTS,s.primitiveName=i.primitive;break;case"lines":s.primitive=o.LINES,s.primitiveName=i.primitive;break;case"line-loop":s.primitive=o.LINE_LOOP,s.primitiveName=i.primitive;break;case"line-strip":s.primitive=o.LINE_STRIP,s.primitiveName=i.primitive;break;case"triangles":s.primitive=o.TRIANGLES,s.primitiveName=i.primitive;break;case"triangle-strip":s.primitive=o.TRIANGLE_STRIP,s.primitiveName=i.primitive;break;case"triangle-fan":s.primitive=o.TRIANGLE_FAN,s.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=o.TRIANGLES,s.primitiveName=i.primitive}if(!i.positions)return r.error("Config expected: positions"),w(r);if(!i.indices)return r.error("Config expected: indices"),w(r);var l=i.positionsDecodeMatrix;if(l);else{var u=ht.getPositionsBounds(i.positions),c=ht.compressPositions(i.positions,u.min,u.max);a=c.quantized,s.positionsDecodeMatrix=c.decodeMatrix,s.positionsBuf=new lt(o,o.ARRAY_BUFFER,a,a.length,3,o.STATIC_DRAW),wt.positions+=s.positionsBuf.numItems,$.positions3ToAABB3(i.positions,r._aabb),$.positions3ToAABB3(a,gt,s.positionsDecodeMatrix),$.AABB3ToOBB3(gt,r._obb)}if(i.colors){var f=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors);s.colorsBuf=new lt(o,o.ARRAY_BUFFER,f,f.length,4,o.STATIC_DRAW),wt.colors+=s.colorsBuf.numItems}if(i.uv){var p=ht.getUVBounds(i.uv),A=ht.compressUVs(i.uv,p.min,p.max),d=A.quantized;s.uvDecodeMatrix=A.decodeMatrix,s.uvBuf=new lt(o,o.ARRAY_BUFFER,d,d.length,2,o.STATIC_DRAW),wt.uvs+=s.uvBuf.numItems}if(i.normals){var v=ht.compressNormals(i.normals),h=s.compressGeometry;s.normalsBuf=new lt(o,o.ARRAY_BUFFER,v,v.length,3,o.STATIC_DRAW,h),wt.normals+=s.normalsBuf.numItems}var I=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices);s.indicesBuf=new lt(o,o.ELEMENT_ARRAY_BUFFER,I,I.length,1,o.STATIC_DRAW),wt.indices+=s.indicesBuf.numItems;var y=ut(a,I,s.positionsDecodeMatrix,r._edgeThreshold);return r._edgeIndicesBuf=new lt(o,o.ELEMENT_ARRAY_BUFFER,y,y.length,1,o.STATIC_DRAW),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3),r._buildHash(),wt.meshes++,r}return P(n,[{key:"type",get:function(){return"VBOGeometry"}},{key:"isVBOGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"aabb",get:function(){return this._aabb}},{key:"obb",get:function(){return this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),wt.meshes--}}]),n}(),Et={};function bt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("load3DSGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,se.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,r());var a=Et.parse.from3DS(e).edit.objects[0].mesh,s=a.vertices,o=a.uvt,l=a.indices;i.processes--,n(se.apply(t,{primitive:"triangles",positions:s,normals:null,uv:o,indices:l}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,r()}))}))}function Dt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,se.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,r());for(var a=Et.parse.fromOBJ(e),s=Et.edit.unwrap(a.i_verts,a.c_verts,3),o=Et.edit.unwrap(a.i_norms,a.c_norms,3),l=Et.edit.unwrap(a.i_uvt,a.c_uvt,2),u=new Int32Array(a.i_verts.length),c=0;c0?o:null,autoNormals:0===o.length,uv:l,indices:u}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,r()}))}))}function Pt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,a=i?i[0]:0,s=i?i[1]:0,o=i?i[2]:0,l=-t+a,u=-n+s,c=-r+o,f=t+a,p=n+s,A=r+o;return se.apply(e,{positions:[f,p,A,l,p,A,l,u,A,f,u,A,f,p,A,f,u,A,f,u,c,f,p,c,f,p,A,f,p,c,l,p,c,l,p,A,l,p,A,l,p,c,l,u,c,l,u,A,l,u,c,f,u,c,f,u,A,l,u,A,f,u,c,l,u,c,l,p,c,f,p,c],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function Rt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,a=i?i[0]:0,s=i?i[1]:0,o=i?i[2]:0,l=-t+a,u=-n+s,c=-r+o,f=t+a,p=n+s,A=r+o;return se.apply(e,{primitive:"lines",positions:[l,u,c,l,u,A,l,p,c,l,p,A,f,u,c,f,u,A,f,p,c,f,p,A],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function Ct(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);var n=e.radiusBottom||1;n<0&&(console.error("negative radiusBottom not allowed - will invert"),n*=-1);var r=e.height||1;r<0&&(console.error("negative height not allowed - will invert"),r*=-1);var i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);var a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);var s,o,l,u,c,f,p,A,d,v,h,I=!!e.openEnded,y=e.center,m=y?y[0]:0,w=y?y[1]:0,g=y?y[2]:0,T=r/2,E=r/a,b=2*Math.PI/i,D=1/i,P=(t-n)/a,R=[],C=[],_=[],B=[],O=(90-180*Math.atan(r/(n-t))/Math.PI)/90;for(s=0;s<=a;s++)for(c=t-s*P,f=T-s*E,o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),C.push(c*l),C.push(O),C.push(c*u),_.push(o*D),_.push(1*s/a),R.push(c*l+m),R.push(f+w),R.push(c*u+g);for(s=0;s0){for(d=R.length/3,C.push(0),C.push(1),C.push(0),_.push(.5),_.push(.5),R.push(0+m),R.push(T+w),R.push(0+g),o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),v=.5*Math.sin(o*b)+.5,h=.5*Math.cos(o*b)+.5,C.push(t*l),C.push(1),C.push(t*u),_.push(v),_.push(h),R.push(t*l+m),R.push(T+w),R.push(t*u+g);for(o=0;o0){for(d=R.length/3,C.push(0),C.push(-1),C.push(0),_.push(.5),_.push(.5),R.push(0+m),R.push(0-T+w),R.push(0+g),o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),v=.5*Math.sin(o*b)+.5,h=.5*Math.cos(o*b)+.5,C.push(n*l),C.push(-1),C.push(n*u),_.push(v),_.push(h),R.push(n*l+m),R.push(0-T+w),R.push(n*u+g);for(o=0;o0&&void 0!==arguments[0]?arguments[0]:{},t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);var n=e.divisions||1;n<0&&(console.error("negative divisions not allowed - will invert"),n*=-1),n<1&&(n=1);for(var r=(t=t||10)/(n=n||10),i=t/2,a=[],s=[],o=0,l=0,u=-i;l<=n;l++,u+=r)a.push(-i),a.push(0),a.push(u),a.push(i),a.push(0),a.push(u),a.push(u),a.push(0),a.push(-i),a.push(u),a.push(0),a.push(i),s.push(o++),s.push(o++),s.push(o++),s.push(o++);return se.apply(e,{primitive:"lines",positions:a,indices:s})}function Bt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);var r=e.xSegments||1;r<0&&(console.error("negative xSegments not allowed - will invert"),r*=-1),r<1&&(r=1);var i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);var a,s,o,l,u,c,f,p=e.center,A=p?p[0]:0,d=p?p[1]:0,v=p?p[2]:0,h=t/2,I=n/2,y=Math.floor(r)||1,m=Math.floor(i)||1,w=y+1,g=m+1,T=t/y,E=n/m,b=new Float32Array(w*g*3),D=new Float32Array(w*g*3),P=new Float32Array(w*g*2),R=0,C=0;for(a=0;a65535?Uint32Array:Uint16Array)(y*m*6);for(a=0;a0&&void 0!==arguments[0]?arguments[0]:{},t=e.lod||1,n=e.center?e.center[0]:0,r=e.center?e.center[1]:0,i=e.center?e.center[2]:0,a=e.radius||1;a<0&&(console.error("negative radius not allowed - will invert"),a*=-1);var s=e.heightSegments||18;s<0&&(console.error("negative heightSegments not allowed - will invert"),s*=-1),(s=Math.floor(t*s))<18&&(s=18);var o=e.widthSegments||18;o<0&&(console.error("negative widthSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var l,u,c,f,p,A,d,v,h,I,y,m,w,g,T=[],E=[],b=[],D=[];for(l=0;l<=s;l++)for(c=l*Math.PI/s,f=Math.sin(c),p=Math.cos(c),u=0;u<=o;u++)A=2*u*Math.PI/o,d=Math.sin(A),v=Math.cos(A)*f,h=p,I=d*f,y=1-u/o,m=l/s,E.push(v),E.push(h),E.push(I),b.push(y),b.push(m),T.push(n+a*v),T.push(r+a*h),T.push(i+a*I);for(l=0;l0&&void 0!==arguments[0]?arguments[0]:{},t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;var n=e.tube||.3;n<0&&(console.error("negative tube not allowed - will invert"),n*=-1);var r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<4&&(r=4);var i=e.tubeSegments||24;i<0&&(console.error("negative tubeSegments not allowed - will invert"),i*=-1),i<4&&(i=4);var a=e.arc||2*Math.PI;a<0&&(console.warn("negative arc not allowed - will invert"),a*=-1),a>360&&(a=360);var s,o,l,u,c,f,p,A,d,v,h,I,y=e.center,m=y?y[0]:0,w=y?y[1]:0,g=y?y[2]:0,T=[],E=[],b=[],D=[];for(A=0;A<=i;A++)for(p=0;p<=r;p++)s=p/r*a,o=.785398+A/i*Math.PI*2,m=t*Math.cos(s),w=t*Math.sin(s),l=(t+n*Math.cos(o))*Math.cos(s),u=(t+n*Math.cos(o))*Math.sin(s),c=n*Math.sin(o),T.push(l+m),T.push(u+w),T.push(c+g),b.push(1-p/r),b.push(A/i),f=$.normalizeVec3($.subVec3([l,u,c],[m,w,g],[]),[]),E.push(f[0]),E.push(f[1]),E.push(f[2]);for(A=1;A<=i;A++)for(p=1;p<=r;p++)d=(r+1)*A+p-1,v=(r+1)*(A-1)+p-1,h=(r+1)*(A-1)+p,I=(r+1)*A+p,D.push(d),D.push(v),D.push(h),D.push(h),D.push(I),D.push(d);return se.apply(e,{positions:T,normals:E,uv:b,indices:D})}Et.load=function(e,t){var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=function(e){t(e.target.response)},n.send()},Et.save=function(e,t){var n="data:application/octet-stream;base64,"+btoa(Et.parse._buffToStr(e));window.location.href=n},Et.clone=function(e){return JSON.parse(JSON.stringify(e))},Et.bin={},Et.bin.f=new Float32Array(1),Et.bin.fb=new Uint8Array(Et.bin.f.buffer),Et.bin.rf=function(e,t){for(var n=Et.bin.f,r=Et.bin.fb,i=0;i<4;i++)r[i]=e[t+i];return n[0]},Et.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Et.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Et.bin.rASCII0=function(e,t){for(var n="";0!=e[t];)n+=String.fromCharCode(e[t++]);return n},Et.bin.wf=function(e,t,n){new Float32Array(e.buffer,t,1)[0]=n},Et.bin.wsl=function(e,t,n){e[t]=n,e[t+1]=n>>8},Et.bin.wil=function(e,t,n){e[t]=n,e[t+1]=n>>8,e[t+2]=n>>16,e[t+3]},Et.parse={},Et.parse._buffToStr=function(e){for(var t=new Uint8Array(e),n="",r=0;ri&&(i=l),ua&&(a=u),cs&&(s=c)}return{min:{x:t,y:n,z:r},max:{x:i,y:a,z:s}}};var Nt={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function Lt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.origin||[0,0,0],n=t[0],r=t[1],i=t[2],a=e.size||1,s=[],o=[],l=e.text;se.isNumeric(l)&&(l=""+l);for(var u,c,f,p,A,d,v,h,I,y=(l||"").split("\n"),m=0,w=0,g=.04,T=0;T1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e,i))._parentNode=null,r._children=[],r._aabb=null,r._aabbDirty=!0,r.scene._aabbDirty=!0,r._numTriangles=0,r._scale=$.vec3(),r._quaternion=$.identityQuaternion(),r._rotation=$.vec3(),r._position=$.vec3(),r._offset=$.vec3(),r._localMatrix=$.identityMat4(),r._worldMatrix=$.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(g(r)),r.origin=i.origin,r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.children)for(var a=i.children,s=0,o=a.length;s0,l=!!i.compressGeometry,u=[];u.push("#version 300 es"),u.push("// Lambertian drawing vertex shader"),u.push("in vec3 position;"),u.push("uniform mat4 modelMatrix;"),u.push("uniform mat4 viewMatrix;"),u.push("uniform mat4 projMatrix;"),u.push("uniform vec4 colorize;"),u.push("uniform vec3 offset;"),l&&u.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(u.push("uniform float logDepthBufFC;"),u.push("out float vFragDepth;"),u.push("bool isPerspectiveMatrix(mat4 m) {"),u.push(" return (m[2][3] == - 1.0);"),u.push("}"),u.push("out float isPerspective;"));o&&u.push("out vec4 vWorldPosition;");if(u.push("uniform vec4 lightAmbient;"),u.push("uniform vec4 materialColor;"),u.push("uniform vec3 materialEmissive;"),i.normalsBuf){u.push("in vec3 normal;"),u.push("uniform mat4 modelNormalMatrix;"),u.push("uniform mat4 viewNormalMatrix;");for(var c=0,f=r.lights.length;c= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),u.push(" }"),u.push(" return normalize(v);"),u.push("}"))}u.push("out vec4 vColor;"),"points"===i.primitiveName&&u.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(u.push("void billboard(inout mat4 mat) {"),u.push(" mat[0][0] = 1.0;"),u.push(" mat[0][1] = 0.0;"),u.push(" mat[0][2] = 0.0;"),"spherical"===a&&(u.push(" mat[1][0] = 0.0;"),u.push(" mat[1][1] = 1.0;"),u.push(" mat[1][2] = 0.0;")),u.push(" mat[2][0] = 0.0;"),u.push(" mat[2][1] = 0.0;"),u.push(" mat[2][2] =1.0;"),u.push("}"));u.push("void main(void) {"),u.push("vec4 localPosition = vec4(position, 1.0); "),u.push("vec4 worldPosition;"),l&&u.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(l?u.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):u.push("vec4 localNormal = vec4(normal, 0.0); "),u.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),u.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));u.push("mat4 viewMatrix2 = viewMatrix;"),u.push("mat4 modelMatrix2 = modelMatrix;"),s&&u.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(u.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),u.push("billboard(modelMatrix2);"),u.push("billboard(viewMatrix2);"),u.push("billboard(modelViewMatrix);"),i.normalsBuf&&(u.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),u.push("billboard(modelNormalMatrix2);"),u.push("billboard(viewNormalMatrix2);"),u.push("billboard(modelViewNormalMatrix);")),u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&u.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(u.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),u.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),u.push("float lambertian = 1.0;"),i.normalsBuf)for(var A=0,d=r.lights.length;A0,a=t.gammaOutput,s=[];s.push("#version 300 es"),s.push("// Lambertian drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"));if(i){s.push("in vec4 vWorldPosition;"),s.push("uniform bool clippable;");for(var o=0,l=n.sectionPlanes.length;o 0.0) { discard; }"),s.push("}")}"points"===r.primitiveName&&(s.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),s.push("float r = dot(cxy, cxy);"),s.push("if (r > 1.0) {"),s.push(" discard;"),s.push("}"));t.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?s.push("outColor = linearToGamma(vColor, gammaFactor);"):s.push("outColor = vColor;");return s.push("}"),s}(e)):(this.vertex=function(e){var t=e.scene;e._material;var n,r=e._state,i=t._sectionPlanesState,a=e._geometry._state,s=t._lightsState,o=r.billboard,l=r.background,u=r.stationary,c=function(e){if(!e._geometry._state.uvBuf)return!1;var t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),f=ur(e),p=i.sectionPlanes.length>0,A=lr(e),d=!!a.compressGeometry,v=[];v.push("#version 300 es"),v.push("// Drawing vertex shader"),v.push("in vec3 position;"),d&&v.push("uniform mat4 positionsDecodeMatrix;");v.push("uniform mat4 modelMatrix;"),v.push("uniform mat4 viewMatrix;"),v.push("uniform mat4 projMatrix;"),v.push("out vec3 vViewPosition;"),v.push("uniform vec3 offset;"),p&&v.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(v.push("uniform float logDepthBufFC;"),v.push("out float vFragDepth;"),v.push("bool isPerspectiveMatrix(mat4 m) {"),v.push(" return (m[2][3] == - 1.0);"),v.push("}"),v.push("out float isPerspective;"));s.lightMaps.length>0&&v.push("out vec3 vWorldNormal;");if(f){v.push("in vec3 normal;"),v.push("uniform mat4 modelNormalMatrix;"),v.push("uniform mat4 viewNormalMatrix;"),v.push("out vec3 vViewNormal;");for(var h=0,I=s.lights.length;h= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),v.push(" }"),v.push(" return normalize(v);"),v.push("}"))}c&&(v.push("in vec2 uv;"),v.push("out vec2 vUV;"),d&&v.push("uniform mat3 uvDecodeMatrix;"));a.colors&&(v.push("in vec4 color;"),v.push("out vec4 vColor;"));"points"===a.primitiveName&&v.push("uniform float pointSize;");"spherical"!==o&&"cylindrical"!==o||(v.push("void billboard(inout mat4 mat) {"),v.push(" mat[0][0] = 1.0;"),v.push(" mat[0][1] = 0.0;"),v.push(" mat[0][2] = 0.0;"),"spherical"===o&&(v.push(" mat[1][0] = 0.0;"),v.push(" mat[1][1] = 1.0;"),v.push(" mat[1][2] = 0.0;")),v.push(" mat[2][0] = 0.0;"),v.push(" mat[2][1] = 0.0;"),v.push(" mat[2][2] =1.0;"),v.push("}"));if(A){v.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(var y=0,m=s.lights.length;y0&&v.push("vWorldNormal = worldNormal;"),v.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),v.push("vec3 tmpVec3;"),v.push("float lightDist;");for(var w=0,g=s.lights.length;w0,l=ur(e),u=r.uvBuf,c="PhongMaterial"===s.type,f="MetallicMaterial"===s.type,p="SpecularMaterial"===s.type,A=lr(e);t.gammaInput;var d=t.gammaOutput,v=[];v.push("#version 300 es"),v.push("// Drawing fragment shader"),v.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),v.push("precision highp float;"),v.push("precision highp int;"),v.push("#else"),v.push("precision mediump float;"),v.push("precision mediump int;"),v.push("#endif"),t.logarithmicDepthBufferEnabled&&(v.push("in float isPerspective;"),v.push("uniform float logDepthBufFC;"),v.push("in float vFragDepth;"));A&&(v.push("float unpackDepth (vec4 color) {"),v.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),v.push(" return dot(color, bitShift);"),v.push("}"));v.push("uniform float gammaFactor;"),v.push("vec4 linearToLinear( in vec4 value ) {"),v.push(" return value;"),v.push("}"),v.push("vec4 sRGBToLinear( in vec4 value ) {"),v.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),v.push("}"),v.push("vec4 gammaToLinear( in vec4 value) {"),v.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),v.push("}"),d&&(v.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),v.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),v.push("}"));if(o){v.push("in vec4 vWorldPosition;"),v.push("uniform bool clippable;");for(var h=0;h0&&(v.push("uniform samplerCube lightMap;"),v.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&v.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("uniform mat4 viewMatrix;"),v.push("#define PI 3.14159265359"),v.push("#define RECIPROCAL_PI 0.31830988618"),v.push("#define RECIPROCAL_PI2 0.15915494"),v.push("#define EPSILON 1e-6"),v.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),v.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),v.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),v.push("}"),v.push("struct IncidentLight {"),v.push(" vec3 color;"),v.push(" vec3 direction;"),v.push("};"),v.push("struct ReflectedLight {"),v.push(" vec3 diffuse;"),v.push(" vec3 specular;"),v.push("};"),v.push("struct Geometry {"),v.push(" vec3 position;"),v.push(" vec3 viewNormal;"),v.push(" vec3 worldNormal;"),v.push(" vec3 viewEyeDir;"),v.push("};"),v.push("struct Material {"),v.push(" vec3 diffuseColor;"),v.push(" float specularRoughness;"),v.push(" vec3 specularColor;"),v.push(" float shine;"),v.push("};"),c&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(v.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(v.push(" vec3 irradiance = "+or[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),v.push(" irradiance *= PI;"),v.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(v.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),v.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),v.push(" radiance *= PI;"),v.push(" reflectedLight.specular += radiance;")),v.push("}")),v.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),v.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),v.push(" vec3 irradiance = dotNL * directLight.color * PI;"),v.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),v.push("}")),(f||p)&&(v.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),v.push(" float r = ggxRoughness + 0.0001;"),v.push(" return (2.0 / (r * r) - 2.0);"),v.push("}"),v.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),v.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),v.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),v.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),v.push("}"),a.reflectionMaps.length>0&&(v.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),v.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),v.push(" vec3 envMapColor = "+or[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),v.push(" return envMapColor;"),v.push("}")),v.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),v.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),v.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),v.push("}"),v.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),v.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),v.push(" return 1.0 / ( gl * gv );"),v.push("}"),v.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),v.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),v.push(" return 0.5 / max( gv + gl, EPSILON );"),v.push("}"),v.push("float D_GGX(const in float alpha, const in float dotNH) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),v.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),v.push("}"),v.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),v.push(" float alpha = ( roughness * roughness );"),v.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),v.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),v.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),v.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),v.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),v.push(" vec3 F = F_Schlick( specularColor, dotLH );"),v.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),v.push(" float D = D_GGX( alpha, dotNH );"),v.push(" return F * (G * D);"),v.push("}"),v.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),v.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),v.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),v.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),v.push(" vec4 r = roughness * c0 + c1;"),v.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),v.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),v.push(" return specularColor * AB.x + AB.y;"),v.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(v.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(v.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),v.push(" irradiance *= PI;"),v.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(v.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),v.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),v.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),v.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),v.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),v.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),v.push("}")),v.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),v.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),v.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),v.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),v.push("}")));v.push("in vec3 vViewPosition;"),r.colors&&v.push("in vec4 vColor;");u&&(l&&n._normalMap||n._ambientMap||n._baseColorMap||n._diffuseMap||n._emissiveMap||n._metallicMap||n._roughnessMap||n._metallicRoughnessMap||n._specularMap||n._glossinessMap||n._specularGlossinessMap||n._occlusionMap||n._alphaMap)&&v.push("in vec2 vUV;");l&&(a.lightMaps.length>0&&v.push("in vec3 vWorldNormal;"),v.push("in vec3 vViewNormal;"));s.ambient&&v.push("uniform vec3 materialAmbient;");s.baseColor&&v.push("uniform vec3 materialBaseColor;");void 0!==s.alpha&&null!==s.alpha&&v.push("uniform vec4 materialAlphaModeCutoff;");s.emissive&&v.push("uniform vec3 materialEmissive;");s.diffuse&&v.push("uniform vec3 materialDiffuse;");void 0!==s.glossiness&&null!==s.glossiness&&v.push("uniform float materialGlossiness;");void 0!==s.shininess&&null!==s.shininess&&v.push("uniform float materialShininess;");s.specular&&v.push("uniform vec3 materialSpecular;");void 0!==s.metallic&&null!==s.metallic&&v.push("uniform float materialMetallic;");void 0!==s.roughness&&null!==s.roughness&&v.push("uniform float materialRoughness;");void 0!==s.specularF0&&null!==s.specularF0&&v.push("uniform float materialSpecularF0;");u&&n._ambientMap&&(v.push("uniform sampler2D ambientMap;"),n._ambientMap._state.matrix&&v.push("uniform mat4 ambientMapMatrix;"));u&&n._baseColorMap&&(v.push("uniform sampler2D baseColorMap;"),n._baseColorMap._state.matrix&&v.push("uniform mat4 baseColorMapMatrix;"));u&&n._diffuseMap&&(v.push("uniform sampler2D diffuseMap;"),n._diffuseMap._state.matrix&&v.push("uniform mat4 diffuseMapMatrix;"));u&&n._emissiveMap&&(v.push("uniform sampler2D emissiveMap;"),n._emissiveMap._state.matrix&&v.push("uniform mat4 emissiveMapMatrix;"));l&&u&&n._metallicMap&&(v.push("uniform sampler2D metallicMap;"),n._metallicMap._state.matrix&&v.push("uniform mat4 metallicMapMatrix;"));l&&u&&n._roughnessMap&&(v.push("uniform sampler2D roughnessMap;"),n._roughnessMap._state.matrix&&v.push("uniform mat4 roughnessMapMatrix;"));l&&u&&n._metallicRoughnessMap&&(v.push("uniform sampler2D metallicRoughnessMap;"),n._metallicRoughnessMap._state.matrix&&v.push("uniform mat4 metallicRoughnessMapMatrix;"));l&&n._normalMap&&(v.push("uniform sampler2D normalMap;"),n._normalMap._state.matrix&&v.push("uniform mat4 normalMapMatrix;"),v.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),v.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),v.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),v.push(" vec2 st0 = dFdx( uv.st );"),v.push(" vec2 st1 = dFdy( uv.st );"),v.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),v.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),v.push(" vec3 N = normalize( surf_norm );"),v.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),v.push(" mat3 tsn = mat3( S, T, N );"),v.push(" return normalize( tsn * mapN );"),v.push("}"));u&&n._occlusionMap&&(v.push("uniform sampler2D occlusionMap;"),n._occlusionMap._state.matrix&&v.push("uniform mat4 occlusionMapMatrix;"));u&&n._alphaMap&&(v.push("uniform sampler2D alphaMap;"),n._alphaMap._state.matrix&&v.push("uniform mat4 alphaMapMatrix;"));l&&u&&n._specularMap&&(v.push("uniform sampler2D specularMap;"),n._specularMap._state.matrix&&v.push("uniform mat4 specularMapMatrix;"));l&&u&&n._glossinessMap&&(v.push("uniform sampler2D glossinessMap;"),n._glossinessMap._state.matrix&&v.push("uniform mat4 glossinessMapMatrix;"));l&&u&&n._specularGlossinessMap&&(v.push("uniform sampler2D materialSpecularGlossinessMap;"),n._specularGlossinessMap._state.matrix&&v.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));l&&(n._diffuseFresnel||n._specularFresnel||n._alphaFresnel||n._emissiveFresnel||n._reflectivityFresnel)&&(v.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),v.push(" float fr = abs(dot(eyeDir, normal));"),v.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),v.push(" return pow(finalFr, power);"),v.push("}"),n._diffuseFresnel&&(v.push("uniform float diffuseFresnelCenterBias;"),v.push("uniform float diffuseFresnelEdgeBias;"),v.push("uniform float diffuseFresnelPower;"),v.push("uniform vec3 diffuseFresnelCenterColor;"),v.push("uniform vec3 diffuseFresnelEdgeColor;")),n._specularFresnel&&(v.push("uniform float specularFresnelCenterBias;"),v.push("uniform float specularFresnelEdgeBias;"),v.push("uniform float specularFresnelPower;"),v.push("uniform vec3 specularFresnelCenterColor;"),v.push("uniform vec3 specularFresnelEdgeColor;")),n._alphaFresnel&&(v.push("uniform float alphaFresnelCenterBias;"),v.push("uniform float alphaFresnelEdgeBias;"),v.push("uniform float alphaFresnelPower;"),v.push("uniform vec3 alphaFresnelCenterColor;"),v.push("uniform vec3 alphaFresnelEdgeColor;")),n._reflectivityFresnel&&(v.push("uniform float materialSpecularF0FresnelCenterBias;"),v.push("uniform float materialSpecularF0FresnelEdgeBias;"),v.push("uniform float materialSpecularF0FresnelPower;"),v.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),v.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),n._emissiveFresnel&&(v.push("uniform float emissiveFresnelCenterBias;"),v.push("uniform float emissiveFresnelEdgeBias;"),v.push("uniform float emissiveFresnelPower;"),v.push("uniform vec3 emissiveFresnelCenterColor;"),v.push("uniform vec3 emissiveFresnelEdgeColor;")));if(v.push("uniform vec4 lightAmbient;"),l)for(var I=0,y=a.lights.length;I 0.0) { discard; }"),v.push("}")}"points"===r.primitiveName&&(v.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),v.push("float r = dot(cxy, cxy);"),v.push("if (r > 1.0) {"),v.push(" discard;"),v.push("}"));v.push("float occlusion = 1.0;"),s.ambient?v.push("vec3 ambientColor = materialAmbient;"):v.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");s.diffuse?v.push("vec3 diffuseColor = materialDiffuse;"):s.baseColor?v.push("vec3 diffuseColor = materialBaseColor;"):v.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");r.colors&&v.push("diffuseColor *= vColor.rgb;");s.emissive?v.push("vec3 emissiveColor = materialEmissive;"):v.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");s.specular?v.push("vec3 specular = materialSpecular;"):v.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==s.alpha?v.push("float alpha = materialAlphaModeCutoff[0];"):v.push("float alpha = 1.0;");r.colors&&v.push("alpha *= vColor.a;");void 0!==s.glossiness?v.push("float glossiness = materialGlossiness;"):v.push("float glossiness = 1.0;");void 0!==s.metallic?v.push("float metallic = materialMetallic;"):v.push("float metallic = 1.0;");void 0!==s.roughness?v.push("float roughness = materialRoughness;"):v.push("float roughness = 1.0;");void 0!==s.specularF0?v.push("float specularF0 = materialSpecularF0;"):v.push("float specularF0 = 1.0;");u&&(l&&n._normalMap||n._ambientMap||n._baseColorMap||n._diffuseMap||n._occlusionMap||n._emissiveMap||n._metallicMap||n._roughnessMap||n._metallicRoughnessMap||n._specularMap||n._glossinessMap||n._specularGlossinessMap||n._alphaMap)&&(v.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),v.push("vec2 textureCoord;"));u&&n._ambientMap&&(n._ambientMap._state.matrix?v.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),v.push("ambientTexel = "+or[n._ambientMap._state.encoding]+"(ambientTexel);"),v.push("ambientColor *= ambientTexel.rgb;"));u&&n._diffuseMap&&(n._diffuseMap._state.matrix?v.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),v.push("diffuseTexel = "+or[n._diffuseMap._state.encoding]+"(diffuseTexel);"),v.push("diffuseColor *= diffuseTexel.rgb;"),v.push("alpha *= diffuseTexel.a;"));u&&n._baseColorMap&&(n._baseColorMap._state.matrix?v.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),v.push("baseColorTexel = "+or[n._baseColorMap._state.encoding]+"(baseColorTexel);"),v.push("diffuseColor *= baseColorTexel.rgb;"),v.push("alpha *= baseColorTexel.a;"));u&&n._emissiveMap&&(n._emissiveMap._state.matrix?v.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),v.push("emissiveTexel = "+or[n._emissiveMap._state.encoding]+"(emissiveTexel);"),v.push("emissiveColor = emissiveTexel.rgb;"));u&&n._alphaMap&&(n._alphaMap._state.matrix?v.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("alpha *= texture(alphaMap, textureCoord).r;"));u&&n._occlusionMap&&(n._occlusionMap._state.matrix?v.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(l&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){u&&n._normalMap?(n._normalMap._state.matrix?v.push("textureCoord = (normalMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):v.push("vec3 viewNormal = normalize(vViewNormal);"),u&&n._specularMap&&(n._specularMap._state.matrix?v.push("textureCoord = (specularMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("specular *= texture(specularMap, textureCoord).rgb;")),u&&n._glossinessMap&&(n._glossinessMap._state.matrix?v.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("glossiness *= texture(glossinessMap, textureCoord).r;")),u&&n._specularGlossinessMap&&(n._specularGlossinessMap._state.matrix?v.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),v.push("specular *= specGlossRGB.rgb;"),v.push("glossiness *= specGlossRGB.a;")),u&&n._metallicMap&&(n._metallicMap._state.matrix?v.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("metallic *= texture(metallicMap, textureCoord).r;")),u&&n._roughnessMap&&(n._roughnessMap._state.matrix?v.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("roughness *= texture(roughnessMap, textureCoord).r;")),u&&n._metallicRoughnessMap&&(n._metallicRoughnessMap._state.matrix?v.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),v.push("metallic *= metalRoughRGB.b;"),v.push("roughness *= metalRoughRGB.g;")),v.push("vec3 viewEyeDir = normalize(-vViewPosition);"),n._diffuseFresnel&&(v.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),v.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),n._specularFresnel&&(v.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),v.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),n._alphaFresnel&&(v.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),v.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),n._emissiveFresnel&&(v.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),v.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),v.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),v.push(" discard;"),v.push("}"),v.push("IncidentLight light;"),v.push("Material material;"),v.push("Geometry geometry;"),v.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),v.push("vec3 viewLightDir;"),c&&(v.push("material.diffuseColor = diffuseColor;"),v.push("material.specularColor = specular;"),v.push("material.shine = materialShininess;")),p&&(v.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),v.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),v.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),v.push("material.specularColor = specular;")),f&&(v.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),v.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),v.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),v.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),v.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&v.push("geometry.worldNormal = normalize(vWorldNormal);"),v.push("geometry.viewNormal = viewNormal;"),v.push("geometry.viewEyeDir = viewEyeDir;"),c&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||f)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("computePBRLightMapping(geometry, material, reflectedLight);"),v.push("float shadow = 1.0;"),v.push("float shadowAcneRemover = 0.007;"),v.push("vec3 fragmentDepth;"),v.push("float texelSize = 1.0 / 1024.0;"),v.push("float amountInLight = 0.0;"),v.push("vec3 shadowCoord;"),v.push("vec4 rgbaDepth;"),v.push("float depth;");for(var T=0,E=a.lights.length;T0&&"/"===t.charAt(n+1)&&(t=t.substring(0,n)),r.push(t);return r.join("\n")}function vr(e){console.error(e.join("\n"))}var hr=function(){function e(t,n){b(this,e),this.id=Ar.addItem({}),this.source=n,this.init(t)}return P(e,[{key:"init",value:function(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new cr(e,e.VERTEX_SHADER,dr(this.source.vertex)),this._fragmentShader=new cr(e,e.FRAGMENT_SHADER,dr(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void vr(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void vr(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void vr(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void vr(this.errors);var t,n,r,i,a;if(this.compiled=!0,this.handle=e.createProgram(),this.handle){if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void vr(this.errors);var s=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(n=0;n0?Ir.FS_MAX_FLOAT_PRECISION="highp":mr.getShaderPrecisionFormat(mr.FRAGMENT_SHADER,mr.MEDIUM_FLOAT).precision>0?Ir.FS_MAX_FLOAT_PRECISION="mediump":Ir.FS_MAX_FLOAT_PRECISION="lowp":Ir.FS_MAX_FLOAT_PRECISION="mediump",Ir.DEPTH_BUFFER_BITS=mr.getParameter(mr.DEPTH_BITS),Ir.MAX_TEXTURE_SIZE=mr.getParameter(mr.MAX_TEXTURE_SIZE),Ir.MAX_CUBE_MAP_SIZE=mr.getParameter(mr.MAX_CUBE_MAP_TEXTURE_SIZE),Ir.MAX_RENDERBUFFER_SIZE=mr.getParameter(mr.MAX_RENDERBUFFER_SIZE),Ir.MAX_TEXTURE_UNITS=mr.getParameter(mr.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Ir.MAX_TEXTURE_IMAGE_UNITS=mr.getParameter(mr.MAX_TEXTURE_IMAGE_UNITS),Ir.MAX_VERTEX_ATTRIBS=mr.getParameter(mr.MAX_VERTEX_ATTRIBS),Ir.MAX_VERTEX_UNIFORM_VECTORS=mr.getParameter(mr.MAX_VERTEX_UNIFORM_VECTORS),Ir.MAX_FRAGMENT_UNIFORM_VECTORS=mr.getParameter(mr.MAX_FRAGMENT_UNIFORM_VECTORS),Ir.MAX_VARYING_VECTORS=mr.getParameter(mr.MAX_VARYING_VECTORS),mr.getSupportedExtensions().forEach((function(e){Ir.SUPPORTED_EXTENSIONS[e]=!0})))}var wr=$.vec3(),gr=new G({}),Tr=function(e,t){this.id=gr.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new sr(t),this._allocate(t)},Er={};Tr.get=function(e){var t=e.scene,n=[t.canvas.canvas.id,(t.gammaInput?"gi;":";")+(t.gammaOutput?"go":""),t._lightsState.getHash(),t._sectionPlanesState.getHash(),e._geometry._state.hash,e._material._state.hash,e._state.drawHash].join(";"),r=Er[n];if(!r){if((r=new Tr(n,e)).errors)return console.log(r.errors.join("\n")),null;Er[n]=r,te.memory.programs++}return r._useCount++,r},Tr.prototype.put=function(){0==--this._useCount&&(gr.removeItem(this.id),this._program&&this._program.destroy(),delete Er[this._hash],te.memory.programs--)},Tr.prototype.webglContextRestored=function(){this._program=null},Tr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=Ir.MAX_TEXTURE_UNITS,r=t.scene,i=t._material,a=r.canvas.gl,s=this._program,o=t._state,l=t._material._state,u=t._geometry._state,c=r.camera,f=t.origin,p=o.background;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,p&&a.depthFunc(a.LEQUAL),this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,f?e.getRTCViewMatrix(o.originHash,f):c.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,c.viewNormalMatrix),o.clippable){var A=r._sectionPlanesState.sectionPlanes.length;if(A>0)for(var d=r._sectionPlanesState.sectionPlanes,v=t.renderFlags,h=0;h0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(c=0,f=a.sectionPlanes.length;c0&&a.lightMaps[0].texture&&this._uLightMap&&(o.bindTexture(this._uLightMap,a.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++),a.reflectionMaps.length>0&&a.reflectionMaps[0].texture&&this._uReflectionMap&&(o.bindTexture(this._uReflectionMap,a.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++),this._uGammaFactor&&i.uniform1f(this._uGammaFactor,r.gammaFactor),this._baseTextureUnit=e.textureUnit};var br=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._lightsState,r=function(e){var t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,s=e._state.billboard,o=e._state.stationary,l=[];l.push("#version 300 es"),l.push("// EmphasisFillShaderSource vertex shader"),l.push("in vec3 position;"),l.push("uniform mat4 modelMatrix;"),l.push("uniform mat4 viewMatrix;"),l.push("uniform mat4 projMatrix;"),l.push("uniform vec4 colorize;"),l.push("uniform vec3 offset;"),a&&l.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;"));i&&l.push("out vec4 vWorldPosition;");if(l.push("uniform vec4 lightAmbient;"),l.push("uniform vec4 fillColor;"),r){l.push("in vec3 normal;"),l.push("uniform mat4 modelNormalMatrix;"),l.push("uniform mat4 viewNormalMatrix;");for(var u=0,c=n.lights.length;u= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"))}l.push("out vec4 vColor;"),("spherical"===s||"cylindrical"===s)&&(l.push("void billboard(inout mat4 mat) {"),l.push(" mat[0][0] = 1.0;"),l.push(" mat[0][1] = 0.0;"),l.push(" mat[0][2] = 0.0;"),"spherical"===s&&(l.push(" mat[1][0] = 0.0;"),l.push(" mat[1][1] = 1.0;"),l.push(" mat[1][2] = 0.0;")),l.push(" mat[2][0] = 0.0;"),l.push(" mat[2][1] = 0.0;"),l.push(" mat[2][2] =1.0;"),l.push("}"));l.push("void main(void) {"),l.push("vec4 localPosition = vec4(position, 1.0); "),l.push("vec4 worldPosition;"),a&&l.push("localPosition = positionsDecodeMatrix * localPosition;");r&&(a?l.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):l.push("vec4 localNormal = vec4(normal, 0.0); "),l.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),l.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));l.push("mat4 viewMatrix2 = viewMatrix;"),l.push("mat4 modelMatrix2 = modelMatrix;"),o&&l.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===s||"cylindrical"===s?(l.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),l.push("billboard(modelMatrix2);"),l.push("billboard(viewMatrix2);"),l.push("billboard(modelViewMatrix);"),r&&(l.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),l.push("billboard(modelNormalMatrix2);"),l.push("billboard(viewNormalMatrix2);"),l.push("billboard(modelViewNormalMatrix);")),l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r&&l.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),r)for(var p=0,A=n.lights.length;p0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));r&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(var s=0,o=n.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");r?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(t)}));var Dr=new G({}),Pr=$.vec3(),Rr=function(e,t){this.id=Dr.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new br(t),this._allocate(t)},Cr={};Rr.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Cr[t];return n||(n=new Rr(t,e),Cr[t]=n,te.memory.programs++),n._useCount++,n},Rr.prototype.put=function(){0==--this._useCount&&(Dr.removeItem(this.id),this._program&&this._program.destroy(),delete Cr[this._hash],te.memory.programs--)},Rr.prototype.webglContextRestored=function(){this._program=null},Rr.prototype.drawMesh=function(e,t,n){this._program||this._allocate(t);var r=this._scene,i=r.camera,a=r.canvas.gl,s=0===n?t._xrayMaterial._state:1===n?t._highlightMaterial._state:t._selectedMaterial._state,o=t._state,l=t._geometry._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(o.originHash,u):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),o.clippable){var c=r._sectionPlanesState.sectionPlanes.length;if(c>0)for(var f=r._sectionPlanesState.sectionPlanes,p=t.renderFlags,A=0;A0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Edges drawing vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform vec4 edgeColor;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));n&&s.push("out vec4 vWorldPosition;");s.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"),s.push("billboard(modelViewMatrix);"),s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s.push("vColor = edgeColor;"),n&&s.push("vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=e.scene._sectionPlanesState,r=e.scene.gammaOutput,i=n.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));r&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(var s=0,o=n.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");r?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(t)}));var Br=new G({}),Or=$.vec3(),Sr=function(e,t){this.id=Br.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new _r(t),this._allocate(t)},Nr={};Sr.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Nr[t];return n||(n=new Sr(t,e),Nr[t]=n,te.memory.programs++),n._useCount++,n},Sr.prototype.put=function(){0==--this._useCount&&(Br.removeItem(this.id),this._program&&this._program.destroy(),delete Nr[this._hash],te.memory.programs--)},Sr.prototype.webglContextRestored=function(){this._program=null},Sr.prototype.drawMesh=function(e,t,n){this._program||this._allocate(t);var r,i,a=this._scene,s=a.camera,o=a.canvas.gl,l=t._state,u=t._geometry,c=u._state,f=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),o.uniformMatrix4fv(this._uViewMatrix,!1,f?e.getRTCViewMatrix(l.originHash,f):s.viewMatrix),l.clippable){var p=a._sectionPlanesState.sectionPlanes.length;if(p>0)for(var A=a._sectionPlanesState.sectionPlanes,d=t.renderFlags,v=0;v0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Mesh picking vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("out vec4 vViewPosition;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");n&&s.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"));s.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),n&&s.push(" vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(t)}));var xr=$.vec3(),Mr=function(e,t){this._hash=e,this._shaderSource=new Lr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Fr={};Mr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),n=Fr[t];if(!n){if((n=new Mr(t,e)).errors)return console.log(n.errors.join("\n")),null;Fr[t]=n,te.memory.programs++}return n._useCount++,n},Mr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Fr[this._hash],te.memory.programs--)},Mr.prototype.webglContextRestored=function(){this._program=null},Mr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._state,a=t._material._state,s=t._geometry._state,o=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){var l=n._sectionPlanesState.sectionPlanes.length;if(l>0)for(var u=n._sectionPlanesState.sectionPlanes,c=t.renderFlags,f=0;f>24&255,m=I>>16&255,w=I>>8&255,g=255&I;r.uniform4f(this._uPickColor,g/255,w/255,m/255,y/255),s.indicesBuf?(r.drawElements(s.primitive,s.indicesBuf.numItems,s.indicesBuf.itemType,0),e.drawElements++):s.positions&&r.drawArrays(r.TRIANGLES,0,s.positions.numItems)},Mr.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new hr(n,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uPositionsDecodeMatrix=r.getLocation("positionsDecodeMatrix"),this._uModelMatrix=r.getLocation("modelMatrix"),this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i0,r=!!e._geometry._state.compressGeometry;e._state.billboard,e._state.stationary;var i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),n&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("out vec4 vColor;"),r&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),r&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),n&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = clipPos;"),i.push("}"),i}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(t)}));var Ur=$.vec3(),Gr=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Hr(t),this._allocate(t)},kr={};Gr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=kr[t];if(!n){if((n=new Gr(t,e)).errors)return console.log(n.errors.join("\n")),null;kr[t]=n,te.memory.programs++}return n._useCount++,n},Gr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete kr[this._hash],te.memory.programs--)},Gr.prototype.webglContextRestored=function(){this._program=null},Gr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._state,a=t._material._state,s=t._geometry,o=t._geometry._state,l=t.origin,u=a.backfaces,c=a.frontface,f=n.camera.project,p=s._getPickTrianglePositions(),A=s._getPickTriangleColors();if(this._program.bind(),e.useProgram++,n.logarithmicDepthBufferEnabled){var d=2/(Math.log(f.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,d)}if(r.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){var v=n._sectionPlanesState.sectionPlanes.length;if(v>0)for(var h=n._sectionPlanesState.sectionPlanes,I=t.renderFlags,y=0;y0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Mesh occlusion vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");n&&s.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"),s.push("billboard(modelViewMatrix);"),s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&s.push(" vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(t)}));var Vr=$.vec3(),Qr=function(e,t){this._hash=e,this._shaderSource=new jr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Wr={};Qr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";"),n=Wr[t];if(!n){if((n=new Qr(t,e)).errors)return console.log(n.errors.join("\n")),null;Wr[t]=n,te.memory.programs++}return n._useCount++,n},Qr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Wr[this._hash],te.memory.programs--)},Qr.prototype.webglContextRestored=function(){this._program=null},Qr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._material._state,a=t._state,s=t._geometry._state,o=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){var l=i.backfaces;e.backfaces!==l&&(l?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),e.backfaces=l);var u=i.frontface;e.frontface!==u&&(u?r.frontFace(r.CCW):r.frontFace(r.CW),e.frontface=u),this._lastMaterialId=i.id}var c=n.camera;if(r.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCViewMatrix(a.originHash,o):c.viewMatrix),a.clippable){var f=n._sectionPlanesState.sectionPlanes.length;if(f>0)for(var p=n._sectionPlanesState.sectionPlanes,A=t.renderFlags,d=0;d0,n=!!e._geometry._state.compressGeometry,r=[];r.push("// Mesh shadow vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 shadowViewMatrix;"),r.push("uniform mat4 shadowProjMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t&&r.push("out vec4 vWorldPosition;");r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("worldPosition = modelMatrix * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&r.push("vWorldPosition = worldPosition;");return r.push(" gl_Position = shadowProjMatrix * viewPosition;"),r.push("}"),r}(t),this.fragment=function(e){var t=e.scene;t.canvas.gl;var n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(t)}));var Kr=function(e,t){this._hash=e,this._shaderSource=new zr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Yr={};Kr.get=function(e){var t=e.scene,n=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),r=Yr[n];if(!r){if((r=new Kr(n,e)).errors)return console.log(r.errors.join("\n")),null;Yr[n]=r,te.memory.programs++}return r._useCount++,r},Kr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Yr[this._hash],te.memory.programs--)},Kr.prototype.webglContextRestored=function(){this._program=null},Kr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene.canvas.gl,r=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.id!==this._lastMaterialId){var a=r.backfaces;e.backfaces!==a&&(a?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=a);var s=r.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),e.lineWidth!==r.lineWidth&&(n.lineWidth(r.lineWidth),e.lineWidth=r.lineWidth),this._uPointSize&&n.uniform1i(this._uPointSize,r.pointSize),this._lastMaterialId=r.id}if(n.uniformMatrix4fv(this._uModelMatrix,n.FALSE,t.worldMatrix),i.combineGeometry){var o=t.vertexBufs;o.id!==this._lastVertexBufsId&&(o.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(o.positionsBuf,o.compressGeometry?n.UNSIGNED_SHORT:n.FLOAT),e.bindArray++),this._lastVertexBufsId=o.id)}this._uClippable&&n.uniform1i(this._uClippable,t._state.clippable),n.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&n.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?n.UNSIGNED_SHORT:n.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(n.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(n.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(n.drawArrays(n.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},Kr.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new hr(n,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uPositionsDecodeMatrix=r.getLocation("positionsDecodeMatrix"),this._uModelMatrix=r.getLocation("modelMatrix"),this._uShadowViewMatrix=r.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=r.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i0)for(var i,a,s,o=0,l=this._uSectionPlanes.length;o1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).originalSystemId=i.originalSystemId||r.id,r.renderFlags=new Xr,r._state=new ot({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==i.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!i.stationary,background:!!i.background,billboard:r._checkBillboard(i.billboard),layer:null,colorize:null,pickID:r.scene._renderer.getPickID(g(r)),drawHash:"",pickHash:"",offset:$.vec3(),origin:null,originHash:null}),r._drawRenderer=null,r._shadowRenderer=null,r._emphasisFillRenderer=null,r._emphasisEdgesRenderer=null,r._pickMeshRenderer=null,r._pickTriangleRenderer=null,r._occlusionRenderer=null,r._geometry=i.geometry?r._checkComponent2(["ReadableGeometry","VBOGeometry"],i.geometry):r.scene.geometry,r._material=i.material?r._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],i.material):r.scene.material,r._xrayMaterial=i.xrayMaterial?r._checkComponent("EmphasisMaterial",i.xrayMaterial):r.scene.xrayMaterial,r._highlightMaterial=i.highlightMaterial?r._checkComponent("EmphasisMaterial",i.highlightMaterial):r.scene.highlightMaterial,r._selectedMaterial=i.selectedMaterial?r._checkComponent("EmphasisMaterial",i.selectedMaterial):r.scene.selectedMaterial,r._edgeMaterial=i.edgeMaterial?r._checkComponent("EdgeMaterial",i.edgeMaterial):r.scene.edgeMaterial,r._parentNode=null,r._aabb=null,r._aabbDirty=!0,r._numTriangles=r._geometry?r._geometry.numTriangles:0,r.scene._aabbDirty=!0,r._scale=$.vec3(),r._quaternion=$.identityQuaternion(),r._rotation=$.vec3(),r._position=$.vec3(),r._worldMatrix=$.identityMat4(),r._worldNormalMatrix=$.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,r._worldNormalMatrixDirty=!0;var a=i.origin||i.rtcCenter;if(a&&(r._state.origin=$.vec3(a),r._state.originHash=a.join()),i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(g(r)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.layer=i.layer,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.parentId){var s=r.scene.components[i.parentId];s?s.isNode?s.addChild(g(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'"),r._parentNode=s}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(g(r)),r._parentNode=i.parent);return r.compile(),r}return P(n,[{key:"type",get:function(){return"Mesh"}},{key:"isMesh",get:function(){return!0}},{key:"parent",get:function(){return this._parentNode}},{key:"geometry",get:function(){return this._geometry}},{key:"material",get:function(){return this._material}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=$.identityMat4()),$.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix},set:function(e){this.__localMatrix||(this.__localMatrix=$.identityMat4()),this.__localMatrix.set(e||ai),$.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._state.origin},set:function(e){e?(this._state.origin||(this._state.origin=$.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._state.visible},set:function(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}},{key:"xrayed",get:function(){return this._state.xrayed},set:function(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}},{key:"highlighted",get:function(){return this._state.highlighted},set:function(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}},{key:"selected",get:function(){return this._state.selected},set:function(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}},{key:"culled",get:function(){return this._state.culled},set:function(e){this._state.culled=!!e,this.glRedraw()}},{key:"clippable",get:function(){return this._state.clippable},set:function(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}},{key:"collidable",get:function(){return this._state.collidable},set:function(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"pickable",get:function(){return this._state.pickable},set:function(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._state.receivesShadow},set:function(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}},{key:"saoEnabled",get:function(){return!1}},{key:"colorize",get:function(){return this._state.colorize},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);var n=!!e;this.scene._objectColorizeUpdated(this,n),this.glRedraw()}},{key:"opacity",get:function(){return this._state.colorize[3]},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1);var n=null!=e;t[3]=n?e:1,this.scene._objectOpacityUpdated(this,n),this.glRedraw()}},{key:"transparent",get:function(){return 2===this._material.alphaMode||this._state.colorize[3]<1}},{key:"layer",get:function(){return this._state.layer},set:function(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}},{key:"stationary",get:function(){return this._state.stationary}},{key:"billboard",get:function(){return this._state.billboard}},{key:"offset",get:function(){return this._state.offset},set:function(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!0}},{key:"xrayMaterial",get:function(){return this._xrayMaterial}},{key:"highlightMaterial",get:function(){return this._highlightMaterial}},{key:"selectedMaterial",get:function(){return this._selectedMaterial}},{key:"edgeMaterial",get:function(){return this._edgeMaterial}},{key:"_checkBillboard",value:function(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}},{key:"compile",value:function(){var e=this._makeDrawHash();this._state.drawHash!==e&&(this._state.drawHash=e,this._putDrawRenderers(),this._drawRenderer=Tr.get(this),this._emphasisFillRenderer=Rr.get(this),this._emphasisEdgesRenderer=Sr.get(this));var t=this._makePickHash();if(this._state.pickHash!==t&&(this._state.pickHash=t,this._putPickRenderers(),this._pickMeshRenderer=Mr.get(this)),this._state.occluder){var n=this._makeOcclusionHash();this._state.occlusionHash!==n&&(this._state.occlusionHash=n,this._putOcclusionRenderer(),this._occlusionRenderer=Qr.get(this))}}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)$.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t0)for(var n=0;n-1){var x=B.geometry._state,M=B.scene,F=M.camera,H=M.canvas;if("triangles"===x.primitiveName){N.primitive="triangle";var U,G,k,j=L,V=x.indices,Q=x.positions;if(V){var W=V[j+0],z=V[j+1],K=V[j+2];a[0]=W,a[1]=z,a[2]=K,N.indices=a,U=3*W,G=3*z,k=3*K}else k=(G=(U=3*j)+3)+3;if(n[0]=Q[U+0],n[1]=Q[U+1],n[2]=Q[U+2],r[0]=Q[G+0],r[1]=Q[G+1],r[2]=Q[G+2],i[0]=Q[k+0],i[1]=Q[k+1],i[2]=Q[k+2],x.compressGeometry){var Y=x.positionsDecodeMatrix;Y&&(ht.decompressPosition(n,Y,n),ht.decompressPosition(r,Y,r),ht.decompressPosition(i,Y,i))}N.canvasPos?$.canvasPosToLocalRay(H.canvas,B.origin?ye(O,B.origin):O,S,B.worldMatrix,N.canvasPos,e,t):N.origin&&N.direction&&$.worldRayToLocalRay(B.worldMatrix,N.origin,N.direction,e,t),$.normalizeVec3(t),$.rayPlaneIntersect(e,t,n,r,i,s),N.localPos=s,N.position=s,h[0]=s[0],h[1]=s[1],h[2]=s[2],h[3]=1,$.transformVec4(B.worldMatrix,h,I),o[0]=I[0],o[1]=I[1],o[2]=I[2],N.canvasPos&&B.origin&&(o[0]+=B.origin[0],o[1]+=B.origin[1],o[2]+=B.origin[2]),N.worldPos=o,$.transformVec4(F.matrix,I,y),l[0]=y[0],l[1]=y[1],l[2]=y[2],N.viewPos=l,$.cartesianToBarycentric(s,n,r,i,u),N.bary=u;var X=x.normals;if(X){if(x.compressGeometry){var q=3*W,J=3*z,Z=3*K;ht.decompressNormal(X.subarray(q,q+2),c),ht.decompressNormal(X.subarray(J,J+2),f),ht.decompressNormal(X.subarray(Z,Z+2),p)}else c[0]=X[U],c[1]=X[U+1],c[2]=X[U+2],f[0]=X[G],f[1]=X[G+1],f[2]=X[G+2],p[0]=X[k],p[1]=X[k+1],p[2]=X[k+2];var ee=$.addVec3($.addVec3($.mulVec3Scalar(c,u[0],m),$.mulVec3Scalar(f,u[1],w),g),$.mulVec3Scalar(p,u[2],T),E);N.worldNormal=$.normalizeVec3($.transformVec3(B.worldNormalMatrix,ee,b))}var te=x.uv;if(te){if(A[0]=te[2*W],A[1]=te[2*W+1],d[0]=te[2*z],d[1]=te[2*z+1],v[0]=te[2*K],v[1]=te[2*K+1],x.compressGeometry){var ne=x.uvDecodeMatrix;ne&&(ht.decompressUV(A,ne,A),ht.decompressUV(d,ne,d),ht.decompressUV(v,ne,v))}N.uv=$.addVec3($.addVec3($.mulVec2Scalar(A,u[0],D),$.mulVec2Scalar(d,u[1],P),R),$.mulVec2Scalar(v,u[2],C),_)}}}}}(),li=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),r=t.call(this,e,i),te.memory.materials++,r}return P(n,[{key:"type",get:function(){return"Material"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),te.memory.materials--}}]),n}(),ui={opaque:0,mask:1,blend:2},ci=["opaque","mask","blend"],fi=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"PhongMaterial",ambient:$.vec3([1,1,1]),diffuse:$.vec3([1,1,1]),specular:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.ambient=i.ambient,r.diffuse=i.diffuse,r.specular=i.specular,r.emissive=i.emissive,r.alpha=i.alpha,r.shininess=i.shininess,r.reflectivity=i.reflectivity,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,i.ambientMap&&(r._ambientMap=r._checkComponent("Texture",i.ambientMap)),i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.reflectivityMap&&(r._reflectivityMap=r._checkComponent("Texture",i.reflectivityMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.diffuseFresnel&&(r._diffuseFresnel=r._checkComponent("Fresnel",i.diffuseFresnel)),i.specularFresnel&&(r._specularFresnel=r._checkComponent("Fresnel",i.specularFresnel)),i.emissiveFresnel&&(r._emissiveFresnel=r._checkComponent("Fresnel",i.emissiveFresnel)),i.alphaFresnel&&(r._alphaFresnel=r._checkComponent("Fresnel",i.alphaFresnel)),i.reflectivityFresnel&&(r._reflectivityFresnel=r._checkComponent("Fresnel",i.reflectivityFresnel)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"PhongMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"shininess",get:function(){return this._state.shininess},set:function(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"reflectivity",get:function(){return this._state.reflectivity},set:function(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}},{key:"normalMap",get:function(){return this._normalMap}},{key:"ambientMap",get:function(){return this._ambientMap}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specularMap",get:function(){return this._specularMap}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"reflectivityMap",get:function(){return this._reflectivityMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"diffuseFresnel",get:function(){return this._diffuseFresnel}},{key:"specularFresnel",get:function(){return this._specularFresnel}},{key:"emissiveFresnel",get:function(){return this._emissiveFresnel}},{key:"alphaFresnel",get:function(){return this._alphaFresnel}},{key:"reflectivityFresnel",get:function(){return this._reflectivityFresnel}},{key:"alphaMode",get:function(){return ci[this._state.alphaMode]},set:function(e){var t=ui[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function pi(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var n;switch(t){case"WEBGL_depth_texture":n=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=e.getExtension(t)}return e._cachedExtensions[t]=n,n}function Ai(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===r){var a=pi(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===a)return null;if(33776===i)return a.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(n=pi(e,"WEBGL_compressed_texture_s3tc")))return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){var s=pi(e,"WEBGL_compressed_texture_pvrtc");if(null===s)return null;if(35840===i)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){var o=pi(e,"WEBGL_compressed_texture_etc1");return null!==o?o.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){var l=pi(e,"WEBGL_compressed_texture_etc");if(null===l)return null;if(37492===i)return 3001===r?l.COMPRESSED_SRGB8_ETC2:l.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===r?l.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:l.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){var u=pi(e,"WEBGL_compressed_texture_astc");if(null===u)return null;if(37808===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:u.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:u.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:u.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:u.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:u.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:u.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:u.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:u.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:u.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:u.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:u.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:u.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:u.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:u.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){var c=pi(e,"EXT_texture_compression_bptc");if(null===c)return null;if(36492===i)return 3001===r?c.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:c.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}var di=new Uint8Array([0,0,0,1]),vi=function(){function e(t){var n=t.gl,r=t.target,i=t.format,a=t.type,s=t.wrapS,o=t.wrapT,l=t.wrapR,u=t.encoding,c=t.preloadColor,f=t.premultiplyAlpha,p=t.flipY;b(this,e),this.gl=n,this.target=r||n.TEXTURE_2D,this.format=i||1023,this.type=a||1009,this.internalFormat=null,this.premultiplyAlpha=!!f,this.flipY=!!p,this.unpackAlignment=4,this.wrapS=s||1e3,this.wrapT=o||1e3,this.wrapR=l||1e3,this.encoding=u||3001,this.texture=n.createTexture(),c&&this.setPreloadColor(c),this.allocated=!0}return P(e,[{key:"setPreloadColor",value:function(e){e?(di[0]=Math.floor(255*e[0]),di[1]=Math.floor(255*e[1]),di[2]=Math.floor(255*e[2]),di[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(di[0]=0,di[1]=0,di[2]=0,di[3]=255);var t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP)for(var n=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],r=0,i=n.length;r1&&void 0!==arguments[1]?arguments[1]:{},n=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);var r=!1;n.bindTexture(this.target,this.texture);var i=n.getParameter(n.UNPACK_FLIP_Y_WEBGL);n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,this.flipY);var a=n.getParameter(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL);n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);var s=n.getParameter(n.UNPACK_ALIGNMENT);n.pixelStorei(n.UNPACK_ALIGNMENT,this.unpackAlignment);var o=n.getParameter(n.UNPACK_COLORSPACE_CONVERSION_WEBGL);n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,n.NONE);var l=Ai(n,this.minFilter);n.texParameteri(this.target,n.TEXTURE_MIN_FILTER,l),l!==n.NEAREST_MIPMAP_NEAREST&&l!==n.LINEAR_MIPMAP_NEAREST&&l!==n.NEAREST_MIPMAP_LINEAR&&l!==n.LINEAR_MIPMAP_LINEAR||(r=!0);var u=Ai(n,this.magFilter);u&&n.texParameteri(this.target,n.TEXTURE_MAG_FILTER,u);var c=Ai(n,this.wrapS);c&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,c);var f=Ai(n,this.wrapT);f&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,f);var p=Ai(n,this.format,this.encoding),A=Ai(n,this.type),d=hi(n,this.internalFormat,p,A,this.encoding,!1);if(this.target===n.TEXTURE_CUBE_MAP){if(se.isArray(e))for(var v=e,h=[n.TEXTURE_CUBE_MAP_POSITIVE_X,n.TEXTURE_CUBE_MAP_NEGATIVE_X,n.TEXTURE_CUBE_MAP_POSITIVE_Y,n.TEXTURE_CUBE_MAP_NEGATIVE_Y,n.TEXTURE_CUBE_MAP_POSITIVE_Z,n.TEXTURE_CUBE_MAP_NEGATIVE_Z],I=0,y=h.length;I1;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);var o=Ai(i,this.wrapS);o&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,o);var l=Ai(i,this.wrapT);if(l&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,l),this.type===i.TEXTURE_3D||this.type===i.TEXTURE_2D_ARRAY){var u=Ai(i,this.wrapR);u&&i.texParameteri(this.target,i.TEXTURE_WRAP_R,u),i.texParameteri(this.type,i.TEXTURE_WRAP_R,u)}s?(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Ii(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ii(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Ai(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ai(i,this.magFilter)));var c=Ai(i,this.format,this.encoding),f=Ai(i,this.type),p=hi(i,this.internalFormat,c,f,this.encoding,!1);i.texStorage2D(i.TEXTURE_2D,a,p,t[0].width,t[0].height);for(var A=0,d=t.length;A5&&void 0!==arguments[5]&&arguments[5];if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}var s=n;return n===e.RED&&(r===e.FLOAT&&(s=e.R32F),r===e.HALF_FLOAT&&(s=e.R16F),r===e.UNSIGNED_BYTE&&(s=e.R8)),n===e.RG&&(r===e.FLOAT&&(s=e.RG32F),r===e.HALF_FLOAT&&(s=e.RG16F),r===e.UNSIGNED_BYTE&&(s=e.RG8)),n===e.RGBA&&(r===e.FLOAT&&(s=e.RGBA32F),r===e.HALF_FLOAT&&(s=e.RGBA16F),r===e.UNSIGNED_BYTE&&(s=3001===i&&!1===a?e.SRGB8_ALPHA8:e.RGBA8),r===e.UNSIGNED_SHORT_4_4_4_4&&(s=e.RGBA4),r===e.UNSIGNED_SHORT_5_5_5_1&&(s=e.RGB5_A1)),s!==e.R16F&&s!==e.R32F&&s!==e.RG16F&&s!==e.RG32F&&s!==e.RGBA16F&&s!==e.RGBA32F||pi(e,"EXT_color_buffer_float"),s}function Ii(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function yi(e){if(!mi(e.width)||!mi(e.height)){var t=document.createElement("canvas");t.width=wi(e.width),t.height=wi(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function mi(e){return 0==(e&e-1)}function wi(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var gi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({texture:new vi({gl:r.scene.canvas.gl}),matrix:$.identityMat4(),hasMatrix:i.translate&&(0!==i.translate[0]||0!==i.translate[1])||!!i.rotate||i.scale&&(0!==i.scale[0]||0!==i.scale[1]),minFilter:r._checkMinFilter(i.minFilter),magFilter:r._checkMagFilter(i.magFilter),wrapS:r._checkWrapS(i.wrapS),wrapT:r._checkWrapT(i.wrapT),flipY:r._checkFlipY(i.flipY),encoding:r._checkEncoding(i.encoding)}),r._src=null,r._image=null,r._translate=$.vec2([0,0]),r._scale=$.vec2([1,1]),r._rotate=$.vec2([0,0]),r._matrixDirty=!1,r.translate=i.translate,r.scale=i.scale,r.rotate=i.rotate,i.src?r.src=i.src:i.image&&(r.image=i.image),te.memory.textures++,r}return P(n,[{key:"type",get:function(){return"Texture"}},{key:"_checkMinFilter",value:function(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}},{key:"_checkMagFilter",value:function(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}},{key:"_checkWrapS",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkWrapT",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this._state.texture=new vi({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}},{key:"_update",value:function(){var e,t,n=this._state;this._matrixDirty&&(0===this._translate[0]&&0===this._translate[1]||(e=$.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(t=$.scalingMat4v([this._scale[0],this._scale[1],1]),e=e?$.mulMat4(e,t):t),0!==this._rotate&&(t=$.rotationMat4v(.0174532925*this._rotate,[0,0,1]),e=e?$.mulMat4(e,t):t),e&&(n.matrix=e),this._matrixDirty=!1);this.glRedraw()}},{key:"image",get:function(){return this._image},set:function(e){this._image=yi(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}},{key:"src",get:function(){return this._src},set:function(e){this.scene.loading++,this.scene.canvas.spinner.processes++;var t=this,n=new Image;n.onload=function(){n=yi(n),t._state.texture.setImage(n,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},n.src=e,this._src=e,this._image=null}},{key:"translate",get:function(){return this._translate},set:function(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}},{key:"rotate",get:function(){return this._rotate},set:function(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}},{key:"minFilter",get:function(){return this._state.minFilter}},{key:"magFilter",get:function(){return this._state.magFilter}},{key:"wrapS",get:function(){return this._state.wrapS}},{key:"wrapT",get:function(){return this._state.wrapT}},{key:"flipY",get:function(){return this._state.flipY}},{key:"encoding",get:function(){return this._state.encoding}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),te.memory.textures--}}]),n}(),Ti=$.vec3(),Ei=$.vec3();$.vec3();var bi=$.vec3([0,-1,0]),Di=$.vec4([0,0,0,1]),Pi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new gi(g(r)),r._plane=new si(g(r),{geometry:new mt(g(r),Bt({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new fi(g(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new si(g(r),{geometry:new mt(g(r),_t({size:1,divisions:10})),material:new fi(g(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new Qt(g(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),me(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,n=[-this._dir[0],-this._dir[1],-this._dir[2]];$.subVec3(t,this.position,Ti);var r=-$.dotVec3(n,Ti);$.normalizeVec3(n),$.mulVec3Scalar(n,r,Ei),$.vec3PairToQuaternion(bi,e,Di),this._node.quaternion=Di}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),Ri=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"LambertMaterial",ambient:$.vec3([1,1,1]),color:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),r.ambient=i.ambient,r.color=i.color,r.emissive=i.emissive,r.alpha=i.alpha,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r.backfaces=i.backfaces,r.frontface=i.frontface,r}return P(n,[{key:"type",get:function(){return"LambertMaterial"}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){var t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ci={opaque:0,mask:1,blend:2},_i=["opaque","mask","blend"],Bi=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"MetallicMaterial",baseColor:$.vec4([1,1,1]),emissive:$.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.baseColor=i.baseColor,r.metallic=i.metallic,r.roughness=i.roughness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.baseColorMap&&(r._baseColorMap=r._checkComponent("Texture",i.baseColorMap)),i.metallicMap&&(r._metallicMap=r._checkComponent("Texture",i.metallicMap)),i.roughnessMap&&(r._roughnessMap=r._checkComponent("Texture",i.roughnessMap)),i.metallicRoughnessMap&&(r._metallicRoughnessMap=r._checkComponent("Texture",i.metallicRoughnessMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"MetallicMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"baseColor",get:function(){return this._state.baseColor},set:function(e){var t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"baseColorMap",get:function(){return this._baseColorMap}},{key:"metallic",get:function(){return this._state.metallic},set:function(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}},{key:"metallicMap",get:function(){return this._attached.metallicMap}},{key:"roughness",get:function(){return this._state.roughness},set:function(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}},{key:"roughnessMap",get:function(){return this._attached.roughnessMap}},{key:"metallicRoughnessMap",get:function(){return this._attached.metallicRoughnessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._attached.emissiveMap}},{key:"occlusionMap",get:function(){return this._attached.occlusionMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._attached.alphaMap}},{key:"normalMap",get:function(){return this._attached.normalMap}},{key:"alphaMode",get:function(){return _i[this._state.alphaMode]},set:function(e){var t=Ci[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Oi={opaque:0,mask:1,blend:2},Si=["opaque","mask","blend"],Ni=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"SpecularMaterial",diffuse:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),specular:$.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.diffuse=i.diffuse,r.specular=i.specular,r.glossiness=i.glossiness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.glossinessMap&&(r._glossinessMap=r._checkComponent("Texture",i.glossinessMap)),i.specularGlossinessMap&&(r._specularGlossinessMap=r._checkComponent("Texture",i.specularGlossinessMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"SpecularMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specularMap",get:function(){return this._specularMap}},{key:"specularGlossinessMap",get:function(){return this._specularGlossinessMap}},{key:"glossiness",get:function(){return this._state.glossiness},set:function(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}},{key:"glossinessMap",get:function(){return this._glossinessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"normalMap",get:function(){return this._normalMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"alphaMode",get:function(){return Si[this._state.alphaMode]},set:function(e){var t=Oi[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Li={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}},xi=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),r._preset="default",i.preset?(r.preset=i.preset,void 0!==i.fill&&(r.fill=i.fill),i.fillColor&&(r.fillColor=i.fillColor),void 0!==i.fillAlpha&&(r.fillAlpha=i.fillAlpha),void 0!==i.edges&&(r.edges=i.edges),i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth),void 0!==i.backfaces&&(r.backfaces=i.backfaces),void 0!==i.glowThrough&&(r.glowThrough=i.glowThrough)):(r.fill=i.fill,r.fillColor=i.fillColor,r.fillAlpha=i.fillAlpha,r.edges=i.edges,r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth,r.backfaces=i.backfaces,r.glowThrough=i.glowThrough),r}return P(n,[{key:"type",get:function(){return"EmphasisMaterial"}},{key:"presets",get:function(){return Li}},{key:"fill",get:function(){return this._state.fill},set:function(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}},{key:"fillColor",get:function(){return this._state.fillColor},set:function(e){var t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}},{key:"fillAlpha",get:function(){return this._state.fillAlpha},set:function(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"glowThrough",get:function(){return this._state.glowThrough},set:function(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Li[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Li).join(", "))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Mi={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}},Fi=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),r._preset="default",i.preset?(r.preset=i.preset,i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth)):(r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth),r.edges=!1!==i.edges,r}return P(n,[{key:"type",get:function(){return"EdgeMaterial"}},{key:"presets",get:function(){return Mi}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Mi[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Mi).join(", "))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Hi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({edgeColor:$.vec3([0,0,0]),centerColor:$.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),r.edgeColor=i.edgeColor,r.centerColor=i.centerColor,r.edgeBias=i.edgeBias,r.centerBias=i.centerBias,r.power=i.power,r}return P(n,[{key:"type",get:function(){return"Fresnel"}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}},{key:"centerColor",get:function(){return this._state.centerColor},set:function(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}},{key:"edgeBias",get:function(){return this._state.edgeBias},set:function(e){this._state.edgeBias=e||0,this.glRedraw()}},{key:"centerBias",get:function(){return this._state.centerBias},set:function(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}},{key:"power",get:function(){return this._state.power},set:function(e){this._state.power=null!=e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ui=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._type=i.type||(i.src?i.src.split(".").pop():null)||"jpg",r._pos=$.vec3(i.pos||[0,0,0]),r._up=$.vec3(i.up||[0,1,0]),r._normal=$.vec3(i.normal||[0,0,1]),r._height=i.height||1,r._origin=$.vec3(),r._rtcPos=$.vec3(),r._imageSize=$.vec2(),r._texture=new gi(g(r)),r._image=new Image,"jpg"!==r._type&&"png"!==r._type&&(r.error('Unsupported type - defaulting to "jpg"'),r._type="jpg"),r._node=new Qt(g(r),{matrix:$.inverseMat4($.lookAtMat4v(r._pos,$.subVec3(r._pos,r._normal,$.mat4()),r._up,$.mat4())),children:[r._bitmapMesh=new si(g(r),{scale:[1,1,1],rotation:[-90,0,0],collidable:i.collidable,pickable:i.pickable,opacity:i.opacity,clippable:i.clippable,geometry:new mt(g(r),Bt({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new fi(g(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0})})]}),i.image?r.image=i.image:i.src?r.src=i.src:i.imageData&&(r.imageData=i.imageData),r.scene._bitmapCreated(g(r)),r}return P(n,[{key:"visible",get:function(){return this._bitmapMesh.visible},set:function(e){this._bitmapMesh.visible=e}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}},{key:"src",get:function(){return this._image.src},set:function(e){var t=this;if(e)switch(this._image.onload=function(){t._texture.image=t._image,t._imageSize[0]=t._image.width,t._imageSize[1]=t._image.height,t._updateBitmapMeshScale()},this._image.src=e,e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}},{key:"imageData",get:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")},set:function(e){var t=this;this._image.onload=function(){t._texture.image=image,t._imageSize[0]=image.width,t._imageSize[1]=image.height,t._updateBitmapMeshScale()},this._image.src=e}},{key:"type",get:function(){return this._type},set:function(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}},{key:"pos",get:function(){return this._pos}},{key:"normal",get:function(){return this._normal}},{key:"up",get:function(){return this._up}},{key:"height",get:function(){return this._height},set:function(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}},{key:"collidable",get:function(){return this._bitmapMesh.collidable},set:function(e){this._bitmapMesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._bitmapMesh.clippable},set:function(e){this._bitmapMesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._bitmapMesh.pickable},set:function(e){this._bitmapMesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._bitmapMesh.opacity},set:function(e){this._bitmapMesh.opacity=e}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._bitmapDestroyed(this)}},{key:"_updateBitmapMeshScale",value:function(){var e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}]),n}(),Gi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e,i))._positions=i.positions||[],r._origin=$.vec3(i.origin||[0,0,0]),i.indices)r._indices=i.indices;else{r._indices=[];for(var a=0,s=r._positions.length/3-1;a1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n,[{key:"type",get:function(){return"Light"}},{key:"isLight",get:function(){return!0}}]),n}(),ji=function(e){I(n,ki);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state={type:"ambient",color:$.vec3([.7,.7,.7]),intensity:1},r.color=i.color,r.intensity=i.intensity,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"AmbientLight"}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lightDestroyed(this)}}]),n}(),Vi=function(){function e(t,n,r){b(this,e),r=r||{},this.gl=n,this.allocated=!1,this.canvas=t,this.buffer=null,this.bound=!1,this.size=r.size,this._hasDepthTexture=!!r.depthTexture}return P(e,[{key:"setSize",value:function(e){this.size=e}},{key:"webglContextRestored",value:function(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}},{key:"bind",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(this._touch(e),!this.bound){var t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"_touch",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=this.gl;if(this.size?(e=this.size[0],t=this.size[1]):(e=r.drawingBufferWidth,t=r.drawingBufferHeight),this.buffer){if(this.buffer.width===e&&this.buffer.height===t)return;r.deleteTexture(this.buffer.texture),r.deleteFramebuffer(this.buffer.framebuf),r.deleteRenderbuffer(this.buffer.renderbuf)}var i,a=r.createTexture();r.bindTexture(r.TEXTURE_2D,a),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),n?r.texStorage2D(r.TEXTURE_2D,1,n,e,t):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),this._hasDepthTexture&&(i=r.createTexture(),r.bindTexture(r.TEXTURE_2D,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.DEPTH_COMPONENT32F,e,t,0,r.DEPTH_COMPONENT,r.FLOAT,null));var s=r.createRenderbuffer();r.bindRenderbuffer(r.RENDERBUFFER,s),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT32F,e,t);var o=r.createFramebuffer();if(r.bindFramebuffer(r.FRAMEBUFFER,o),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,a,0),this._hasDepthTexture?r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,i,0):r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,s),r.bindTexture(r.TEXTURE_2D,null),r.bindRenderbuffer(r.RENDERBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,o),!r.isFramebuffer(o))throw"Invalid framebuffer";r.bindFramebuffer(r.FRAMEBUFFER,null);var l=r.checkFramebufferStatus(r.FRAMEBUFFER);switch(l){case r.FRAMEBUFFER_COMPLETE:break;case r.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case r.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+l}this.buffer={framebuf:o,renderbuf:s,texture:a,depthTexture:i,width:e,height:t},this.bound=!1}},{key:"clear",value:function(){if(!this.bound)throw"Render buffer not bound";var e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}},{key:"read",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,s=e,o=(this.buffer.height||this.gl.drawingBufferHeight)-t,l=new i(a),u=this.gl;return u.readPixels(s,o,1,1,n||u.RGBA,r||u.UNSIGNED_BYTE,l,0),l}},{key:"readArray",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Uint8Array,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:4,i=new n(this.buffer.width*this.buffer.height*r),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}},{key:"readImageAsCanvas",value:function(){var e=this.gl,t=this._getImageDataCache(),n=t.pixelData,r=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,n);for(var s=this.buffer.width,o=this.buffer.height,l=o/2|0,u=4*s,c=new Uint8Array(4*s),f=0;f0&&void 0!==arguments[0]?arguments[0]:Uint8Array,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,n=this.buffer.width,r=this.buffer.height,i=this._imageDataCache;if(i&&(i.width===n&&i.height===r||(this._imageDataCache=null,i=null)),!i){var a=document.createElement("canvas"),s=a.getContext("2d");a.width=n,a.height=r,i={pixelData:new e(n*r*t),canvas:a,context:s,imageData:s.createImageData(n,r),width:n,height:r},this._imageDataCache=i}return i.context.resetTransform(),i}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"getTexture",value:function(){var e=this;return this._texture||(this._texture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.texture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.texture),!0)},unbind:function(t){e.buffer&&e.buffer.texture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"hasDepthTexture",value:function(){return this._hasDepthTexture}},{key:"getDepthTexture",value:function(){if(!this._hasDepthTexture)return null;var e=this;return this._depthTexture||(this._dethTexture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.depthTexture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.depthTexture),!0)},unbind:function(t){e.buffer&&e.buffer.depthTexture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"destroy",value:function(){if(this.allocated){var e=this.gl;e.deleteTexture(this.buffer.texture),e.deleteTexture(this.buffer.depthTexture),e.deleteFramebuffer(this.buffer.framebuf),e.deleteRenderbuffer(this.buffer.renderbuf),this.allocated=!1,this.buffer=null,this.bound=!1}this._imageDataCache=null,this._texture=null,this._depthTexture=null}}]),e}(),Qi=function(e){I(n,ki);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var a=r.scene.camera,s=r.scene.canvas;return r._onCameraViewMatrix=a.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=a.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=s.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new ot({type:"dir",dir:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(r._shadowViewMatrixDirty){r._shadowViewMatrix||(r._shadowViewMatrix=$.identityMat4());var e=r.scene.camera,t=r._state.dir,n=e.look,i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]];$.lookAtMat4v(i,n,[0,1,0],r._shadowViewMatrix),r._shadowViewMatrixDirty=!1}return r._shadowViewMatrix},getShadowProjMatrix:function(){return r._shadowProjMatrixDirty&&(r._shadowProjMatrix||(r._shadowProjMatrix=$.identityMat4()),$.orthoMat4c(-40,40,-40,40,-40,80,r._shadowProjMatrix),r._shadowProjMatrixDirty=!1),r._shadowProjMatrix},getShadowRenderBuf:function(){return r._shadowRenderBuf||(r._shadowRenderBuf=new Vi(r.scene.canvas.canvas,r.scene.canvas.gl,{size:[1024,1024]})),r._shadowRenderBuf}}),r.dir=i.dir,r.color=i.color,r.intensity=i.intensity,r.castsShadow=i.castsShadow,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"DirLight"}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}(),Wi=function(e){I(n,ki);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=g(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new ot({type:"point",pos:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(a._shadowViewMatrixDirty){a._shadowViewMatrix||(a._shadowViewMatrix=$.identityMat4());var e=a._state.pos,t=s.look,n=s.up;$.lookAtMat4v(e,t,n,a._shadowViewMatrix),a._shadowViewMatrixDirty=!1}return a._shadowViewMatrix},getShadowProjMatrix:function(){if(a._shadowProjMatrixDirty){a._shadowProjMatrix||(a._shadowProjMatrix=$.identityMat4());var e=a.scene.canvas.canvas;$.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,a._shadowProjMatrix),a._shadowProjMatrixDirty=!1}return a._shadowProjMatrix},getShadowRenderBuf:function(){return a._shadowRenderBuf||(a._shadowRenderBuf=new Vi(a.scene.canvas.canvas,a.scene.canvas.gl,{size:[1024,1024]})),a._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function zi(e){return 0==(e&e-1)}function Ki(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Yi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new ot({texture:new vi({gl:a,target:a.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),te.memory.textures++,r}return P(n,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,a=function(a){var s=new Image;s.onload=function(){var e=s,o=a;return function(){if(!r&&(e=function(e){if(!zi(e.width)||!zi(e.height)){var t=document.createElement("canvas");t.width=Ki(e.width),t.height=Ki(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(e),t._images[o]=e,6===++i)){var a=t._state.texture;a||(a=new vi({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=a),a.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}}(),s.onerror=function(){r=!0},s.src=e[a]},s=0;s1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),qi=function(e){I(n,Yi);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightMapCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),Ji=function(e){I(n,He);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new gi(g(r),{src:i.src}),r._geometry=new mt(g(r),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),r._mesh=new si(g(r),{geometry:r._geometry,material:new fi(g(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,v(T(n.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),Zi=$.vec3(),$i=$.vec3(),ea=$.mat4(),ta=function(){function e(){b(this,e),this.normal=$.vec3(),this.offset=0,this.testVertex=$.vec3()}return P(e,[{key:"set",value:function(e,t,n,r){var i=1/Math.sqrt(e*e+t*t+n*n);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=n*i,this.offset=r*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}]),e}(),na=P((function e(){b(this,e),this.planes=[new ta,new ta,new ta,new ta,new ta,new ta]}));function ra(e,t,n){var r=$.mulMat4(n,t,ea),i=r[0],a=r[1],s=r[2],o=r[3],l=r[4],u=r[5],c=r[6],f=r[7],p=r[8],A=r[9],d=r[10],v=r[11],h=r[12],I=r[13],y=r[14],m=r[15];e.planes[0].set(o-i,f-l,v-p,m-h),e.planes[1].set(o+i,f+l,v+p,m+h),e.planes[2].set(o-a,f-u,v-A,m-I),e.planes[3].set(o+a,f+u,v+A,m+I),e.planes[4].set(o-s,f-c,v-d,m-y),e.planes[5].set(o+s,f+c,v+d,m+y)}function ia(e,t){var n=na.INSIDE,r=Zi,i=$i;r[0]=t[0],r[1]=t[1],r[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];for(var a=[r,i],s=0;s<6;++s){var o=e.planes[s];if(o.normal[0]*a[o.testVertex[0]][0]+o.normal[1]*a[o.testVertex[1]][1]+o.normal[2]*a[o.testVertex[2]][2]+o.offset<0)return na.OUTSIDE;o.normal[0]*a[1-o.testVertex[0]][0]+o.normal[1]*a[1-o.testVertex[1]][1]+o.normal[2]*a[1-o.testVertex[2]][2]+o.offset<0&&(n=na.INTERSECT)}return n}na.INSIDE=0,na.INTERSECT=1,na.OUTSIDE=2;var aa=function(){function e(t){b(this,e),this._eye=$.vec3(),this._look=$.vec3(),this._up=$.vec3(),this._projection={},t&&this.saveCamera(t)}return P(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),sa=$.vec3(),oa=function(){function e(t){if(b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var n=t.metaScene.scene;this.saveObjects(n,t)}}return P(e,[{key:"saveObjects",value:function(e,t,n){this.numObjects=0,this._mask=n?se.apply(n,{}):null;for(var r=!n||n.visible,i=!n||n.edges,a=!n||n.xrayed,s=!n||n.highlighted,o=!n||n.selected,l=!n||n.clippable,u=!n||n.pickable,c=!n||n.colorize,f=!n||n.opacity,p=t.metaObjects,A=e.objects,d=0,v=p.length;d1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||$.vec3([0,0,0]))}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=$.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=$.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),n}(),fa=function(e){I(n,Ye);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return P(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,n=e*this.length,r=this._getCurveLengths(),i=0;i=n){var a=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=$.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=$.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),n}(),Aa=function(){function e(t,n,r,i){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;b(this,e),this.model=t,this.object=null,this.parent=null,this.id=n,this._aabb=null,this.layer=a,this.portionId=s,this._color=[r[0],r[1],r[2],i],this._colorize=[r[0],r[1],r[2],i],this._colorizing=!1,this._transparent=i<255,this.numTriangles=0,this.origin=null}return P(e,[{key:"_finalize",value:function(e){this.layer.initFlags(this.portionId,e,this._transparent)}},{key:"_finalize2",value:function(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}},{key:"_setVisible",value:function(e){this.layer.setVisible(this.portionId,e,this._transparent)}},{key:"_setColor",value:function(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}},{key:"_setColorize",value:function(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}},{key:"_setOpacity",value:function(e,t){var n=e<255,r=this._transparent!==n;this._color[3]=e,this._colorize[3]=e,this._transparent=n,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),r&&this.layer.setTransparent(this.portionId,t,n)}},{key:"_setOffset",value:function(e){this.layer.setOffset(this.portionId,e)}},{key:"_setHighlighted",value:function(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}},{key:"_setXRayed",value:function(e){this.layer.setXRayed(this.portionId,e,this._transparent)}},{key:"_setSelected",value:function(e){this.layer.setSelected(this.portionId,e,this._transparent)}},{key:"_setEdges",value:function(e){this.layer.setEdges(this.portionId,e,this._transparent)}},{key:"_setClippable",value:function(e){this.layer.setClippable(this.portionId,e,this._transparent)}},{key:"_setCollidable",value:function(e){this.layer.setCollidable(this.portionId,e)}},{key:"_setPickable",value:function(e){this.layer.setPickable(this.portionId,e,this._transparent)}},{key:"_setCulled",value:function(e){this.layer.setCulled(this.portionId,e,this._transparent)}},{key:"canPickTriangle",value:function(){return!1}},{key:"drawPickTriangles",value:function(e,t){}},{key:"pickTriangleSurface",value:function(e){}},{key:"precisionRayPickSurface",value:function(e,t,n,r){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,n,r)}},{key:"canPickWorldPos",value:function(){return!0}},{key:"drawPickDepths",value:function(e){this.model.drawPickDepths(e)}},{key:"drawPickNormals",value:function(e){this.model.drawPickNormals(e)}},{key:"delegatePickedEntity",value:function(){return this.parent}},{key:"getEachVertex",value:function(e){this.layer.getEachVertex(this.portionId,e)}},{key:"aabb",get:function(){return this._aabb},set:function(e){this._aabb=e}},{key:"_destroy",value:function(){this.model.scene._renderer.putPickID(this.pickId)}}]),e}(),da=new(function(){function e(){b(this,e),this._uint8Arrays={},this._float32Arrays={}}return P(e,[{key:"_clear",value:function(){this._uint8Arrays={},this._float32Arrays={}}},{key:"getUInt8Array",value:function(e){var t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}},{key:"getFloat32Array",value:function(e){var t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}}]),e}()),va=0;function ha(){return va++,da}var Ia={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},ya=new Float32Array([1,1,1,1]),ma=new Float32Array([0,0,0,1]),wa=$.vec4(),ga=$.vec3();$.vec3();var Ta=$.vec3(),Ea=$.mat4(),ba=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.instancing,a=void 0!==i&&i,s=r.edges,o=void 0!==s&&s;b(this,e),this._scene=t,this._withSAO=n,this._instancing=a,this._edges=o,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}return P(e,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){return[""]}},{key:"_buildFragmentShader",value:function(){return[""]}},{key:"_addMatricesUniformBlockLines",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}},{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"setSectionPlanesStateUniforms",value:function(e){var t=this._scene,n=t.canvas.gl,r=e.model,i=e.layerIndex,a=t._sectionPlanesState.sectionPlanes.length;if(a>0)for(var s=t._sectionPlanesState.sectionPlanes,o=i*a,l=r.renderFlags,u=0;u0&&(this._uReflectionMap="reflectionMap"),n.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.sectionPlanes.length;o3&&void 0!==arguments[3]?arguments[3]:{},i=r.colorUniform,a=void 0!==i&&i,s=r.incrementDrawState,o=void 0!==s&&s,l=Ir.MAX_TEXTURE_IMAGE_UNITS,u=this._scene,c=u.canvas.gl,f=t._state,p=t.model,A=f.textureSet,d=f.origin,v=f.positionsDecodeMatrix,h=u._lightsState,I=u.pointsMaterial,y=p.scene.camera,m=y.viewNormalMatrix,w=y.project,g=e.pickViewMatrix||y.viewMatrix,T=p.position,E=p.rotationMatrix,b=p.rotationMatrixConjugate,D=p.worldNormalMatrix;if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),this._vaoCache.has(t)?c.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(f));var P=0,R=16;this._matricesUniformBlockBufferData.set(b,0);var C=0!==d[0]||0!==d[1]||0!==d[2],_=0!==T[0]||0!==T[1]||0!==T[2];if(C||_){var B=ga;if(C){var O=$.transformPoint3(E,d,Ta);B[0]=O[0],B[1]=O[1],B[2]=O[2]}else B[0]=0,B[1]=0,B[2]=0;B[0]+=T[0],B[1]+=T[1],B[2]+=T[2],this._matricesUniformBlockBufferData.set(ye(g,B,Ea),P+=R)}else this._matricesUniformBlockBufferData.set(g,P+=R);if(this._matricesUniformBlockBufferData.set(e.pickProjMatrix||w.matrix,P+=R),this._matricesUniformBlockBufferData.set(v,P+=R),this._matricesUniformBlockBufferData.set(D,P+=R),this._matricesUniformBlockBufferData.set(m,P+=R),c.bindBuffer(c.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),c.bufferData(c.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,c.DYNAMIC_DRAW),c.bindBufferBase(c.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer),c.uniform1i(this._uRenderPass,n),this.setSectionPlanesStateUniforms(t),u.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var S=2/(Math.log(e.pickZFar+1)/Math.LN2);c.uniform1f(this._uLogDepthBufFC,S)}this._uZFar&&c.uniform1f(this._uZFar,u.camera.project.far)}if(this._uPickInvisible&&c.uniform1i(this._uPickInvisible,e.pickInvisible),this._uPickZNear&&c.uniform1f(this._uPickZNear,e.pickZNear),this._uPickZFar&&c.uniform1f(this._uPickZFar,e.pickZFar),this._uPositionsDecodeMatrix&&c.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,f.positionsDecodeMatrix),this._uUVDecodeMatrix&&c.uniformMatrix3fv(this._uUVDecodeMatrix,!1,f.uvDecodeMatrix),this._uIntensityRange&&I.filterIntensity&&c.uniform2f(this._uIntensityRange,I.minIntensity,I.maxIntensity),this._uPointSize&&c.uniform1f(this._uPointSize,I.pointSize),this._uNearPlaneHeight){var N="ortho"===u.camera.projection?1:c.drawingBufferHeight/(2*Math.tan(.5*u.camera.perspective.fov*Math.PI/180));c.uniform1f(this._uNearPlaneHeight,N)}if(A){var L=A.colorTexture,x=A.metallicRoughnessTexture,M=A.emissiveTexture,F=A.normalsTexture,H=A.occlusionTexture;this._uColorMap&&L&&(this._program.bindTexture(this._uColorMap,L.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uMetallicRoughMap&&x&&(this._program.bindTexture(this._uMetallicRoughMap,x.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uEmissiveMap&&M&&(this._program.bindTexture(this._uEmissiveMap,M.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uNormalMap&&F&&(this._program.bindTexture(this._uNormalMap,F.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uAOMap&&H&&(this._program.bindTexture(this._uAOMap,H.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l)}if(h.reflectionMaps.length>0&&h.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,h.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),h.lightMaps.length>0&&h.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,h.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),this._withSAO){var U=u.sao,G=U.possible;if(G){var k=c.drawingBufferWidth,j=c.drawingBufferHeight;wa[0]=k,wa[1]=j,wa[2]=U.blendCutoff,wa[3]=U.blendFactor,c.uniform4fv(this._uSAOParams,wa),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++}}if(a){var V=this._edges?"edgeColor":"fillColor",Q=this._edges?"edgeAlpha":"fillAlpha";if(n===Ia["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var W=u.xrayMaterial._state,z=W[V],K=W[Q];c.uniform4f(this._uColor,z[0],z[1],z[2],K)}else if(n===Ia["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var Y=u.highlightMaterial._state,X=Y[V],q=Y[Q];c.uniform4f(this._uColor,X[0],X[1],X[2],q)}else if(n===Ia["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var J=u.selectedMaterial._state,Z=J[V],ee=J[Q];c.uniform4f(this._uColor,Z[0],Z[1],Z[2],ee)}else c.uniform4fv(this._uColor,this._edges?ma:ya)}this._draw({state:f,frameCtx:e,incrementDrawState:o}),c.bindVertexArray(null)}}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null,te.memory.programs--}}]),e}(),Da=function(e){I(n,ba);var t=m(n);function n(e,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=i.instancing,s=void 0!==a&&a,o=i.edges,l=void 0!==o&&o;return b(this,n),t.call(this,e,r,{instancing:s,edges:l})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;if(this._edges)t.drawElements(t.LINES,n.edgeIndicesBuf.numItems,n.edgeIndicesBuf.itemType,0);else{var a=r.pickElementsCount||n.indicesBuf.numItems,s=r.pickElementsOffset?r.pickElementsOffset*n.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,a,n.indicesBuf.itemType,s),i&&r.drawElements++}}}]),n}(),Pa=function(e){I(n,Da);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!1,edges:!0})}return P(n)}(),Ra=function(e){I(n,ba);var t=m(n);function n(e,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=i.edges,s=void 0!==a&&a;return b(this,n),t.call(this,e,r,{instancing:!0,edges:s})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;this._edges?t.drawElementsInstanced(t.LINES,n.edgeIndicesBuf.numItems,n.edgeIndicesBuf.itemType,0,n.numInstances):(t.drawElementsInstanced(t.TRIANGLES,n.indicesBuf.numItems,n.indicesBuf.itemType,0,n.numInstances),i&&r.drawElements++)}}]),n}(),Ca=function(e){I(n,Ra);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0,edges:!0})}return P(n)}(),_a=function(e){I(n,ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawArrays(t.POINTS,0,n.positionsBuf.numItems),i&&r.drawArrays++}}]),n}(),Ba=function(e){I(n,ba);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawArraysInstanced(t.POINTS,0,n.positionsBuf.numItems,n.numInstances),i&&r.drawArrays++}}]),n}(),Oa=function(e){I(n,ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawElements(t.LINES,n.indicesBuf.numItems,n.indicesBuf.itemType,0),i&&r.drawElements++}}]),n}(),Sa=function(e){I(n,ba);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawElementsInstanced(t.LINES,n.indicesBuf.numItems,n.indicesBuf.itemType,0,n.numInstances),i&&r.drawElements++}}]),n}(),Na=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t=this._scene,n=t._sectionPlanesState,r=t._lightsState,i=n.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),t.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),t.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(var s=0,o=r.lights.length;s= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),i&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),t.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(var l=0,u=r.lights.length;l0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),n}(),La=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching flat-shading draw vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._lightsState,n=e._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),r){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var a=0,s=n.sectionPlanes.length;a> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var c=0,f=n.sectionPlanes.length;c 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var p=0,A=t.lights.length;p0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}]),n}(),Ma=function(e){I(n,Pa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("uniform int renderPass;"),n.push("uniform vec4 color;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Fa=function(e){I(n,Pa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ha=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry picking vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vPickColor; "),r.push("}"),r}}]),n}(),Ua=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Ga=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vWorldNormal;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec3 worldNormal = octDecode(normal.xy); "),n.push(" vWorldNormal = worldNormal;"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}}]),n}(),ka=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}]),n}(),ja=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec2 vHighPrecisionZW;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching depth fragment shader"),r.push("precision highp float;"),r.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),r.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),r.push("}"),r}}]),n}(),Va=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n,!0),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),Qa=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry shadow vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),n.push(" int colorFlag = int(flags) & 0xF;"),n.push(" bool visible = (colorFlag > 0);"),n.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push(" if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry shadow fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = encodeFloat( gl_FragCoord.z); "),n.push("}"),n}}]),n}(),Wa=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=e._lightsState,r=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),n.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),r&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),r&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),n.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._sectionPlanesState,r=e._lightsState,i=n.sectionPlanes.length>0,a=n.clippingCaps,s=[];s.push("#version 300 es"),s.push("// Triangles batching quality draw fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform sampler2D uColorMap;"),s.push("uniform sampler2D uMetallicRoughMap;"),s.push("uniform sampler2D uEmissiveMap;"),s.push("uniform sampler2D uNormalMap;"),s.push("uniform sampler2D uAOMap;"),s.push("in vec4 vViewPosition;"),s.push("in vec3 vViewNormal;"),s.push("in vec4 vColor;"),s.push("in vec2 vUV;"),s.push("in vec2 vMetallicRoughness;"),r.lightMaps.length>0&&s.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(s,!0),r.reflectionMaps.length>0&&s.push("uniform samplerCube reflectionMap;"),r.lightMaps.length>0&&s.push("uniform samplerCube lightMap;"),s.push("uniform vec4 lightAmbient;");for(var o=0,l=r.lights.length;o0&&(s.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),s.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),s.push(" return envMapColor;"),s.push("}")),s.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),s.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),s.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),s.push("}"),s.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" return 1.0 / ( gl * gv );"),s.push("}"),s.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" return 0.5 / max( gv + gl, EPSILON );"),s.push("}"),s.push("float D_GGX(const in float alpha, const in float dotNH) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),s.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float alpha = ( roughness * roughness );"),s.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),s.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),s.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),s.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),s.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),s.push(" vec3 F = F_Schlick( specularColor, dotLH );"),s.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),s.push(" float D = D_GGX( alpha, dotNH );"),s.push(" return F * (G * D);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),s.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),s.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),s.push(" vec4 r = roughness * c0 + c1;"),s.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),s.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),s.push(" return specularColor * AB.x + AB.y;"),s.push("}"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&(s.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.lightMaps.length>0&&(s.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),s.push(" irradiance *= PI;"),s.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),r.reflectionMaps.length>0&&(s.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),s.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),s.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),s.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),s.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),s.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),s.push("}")),s.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),s.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),s.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),s.push("}"),s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var p=0,A=n.sectionPlanes.length;p (0.002 * vClipPosition.w)) {"),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" return;"),s.push("}")):(s.push(" if (dist > 0.0) { "),s.push(" discard;"),s.push(" }")),s.push("}")}s.push("IncidentLight light;"),s.push("Material material;"),s.push("Geometry geometry;"),s.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),s.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),s.push("float opacity = float(vColor.a) / 255.0;"),s.push("vec3 baseColor = rgb;"),s.push("float specularF0 = 1.0;"),s.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),s.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),s.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),s.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),s.push("baseColor *= colorTexel.rgb;"),s.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),s.push("metallic *= metalRoughTexel.b;"),s.push("roughness *= metalRoughTexel.g;"),s.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),s.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),s.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),s.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),s.push("geometry.position = vViewPosition.xyz;"),s.push("geometry.viewNormal = -normalize(viewNormal);"),s.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),r.lightMaps.length>0&&s.push("geometry.worldNormal = normalize(vWorldNormal);"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&s.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var d=0,v=r.lights.length;d0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick flat normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("out vec4 vWorldPosition;"),t&&n.push("out float vFlags;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),t&&n.push(" vFlags = flags;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick flat normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}}]),n}(),Ka=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching color texture vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._lightsState,r=e._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(var s=0,o=r.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(var f=0,p=r.sectionPlanes.length;f 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var A=0,d=n.lights.length;A0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]})),Ja=$.mat4(),Za=$.mat4();function $a(e,t,n){for(var r=e.length,i=new Uint16Array(r),a=t[0],s=t[1],o=t[2],l=t[3]-a,u=t[4]-s,c=t[5]-o,f=65525,p=f/l,A=f/u,d=f/c,v=function(e){return e>=0?e:0},h=0;h=0?1:-1),s=(1-Math.abs(r))*(i>=0?1:-1),r=a,i=s}return new Int8Array([Math[t](127.5*r+(r<0?-1:0)),Math[n](127.5*i+(i<0?-1:0))])}function ns(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}var rs=$.vec3(),is=$.vec3(),as=$.vec3(),ss=$.vec3(),os=$.mat4(),ls=function(e){I(n,ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin,u=r.position,c=r.rotationMatrix,f=r.rotationMatrixConjugate,p=t.aabb,A=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?s.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(o));var d,v,h=rs;if(h[0]=$.safeInv(p[3]-p[0])*$.MAX_INT,h[1]=$.safeInv(p[4]-p[1])*$.MAX_INT,h[2]=$.safeInv(p[5]-p[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(h[0]),e.snapPickCoordinateScale[1]=$.safeInv(h[1]),e.snapPickCoordinateScale[2]=$.safeInv(h[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var I=is;if(l){var y=as;$.transformPoint3(c,l,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=u[0],I[1]+=u[1],I[2]+=u[2],d=ye(A,I,os),(v=ss)[0]=a.eye[0]-I[0],v[1]=a.eye[1]-I[1],v[2]=a.eye[2]-I[2],e.snapPickOrigin[0]=I[0],e.snapPickOrigin[1]=I[1],e.snapPickOrigin[2]=I[2]}else d=A,v=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),s.uniform3fv(this._uCoordinateScaler,h),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(f,0),this._matricesUniformBlockBufferData.set(d,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(o.positionsDecodeMatrix,m+=16),s.bindBuffer(s.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),s.bufferData(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,s.DYNAMIC_DRAW),s.bindBufferBase(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var w=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,w),this.setSectionPlanesStateUniforms(t),o.indicesBuf.bind(),s.drawElements(s.TRIANGLES,o.indicesBuf.numItems,o.indicesBuf.itemType,0),o.indicesBuf.unbind()}}},{key:"_allocate",value:function(){v(T(n.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),n}(),us=$.vec3(),cs=$.vec3(),fs=$.vec3(),ps=$.vec3(),As=$.mat4(),ds=function(e){I(n,ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin,u=r.position,c=r.rotationMatrix,f=r.rotationMatrixConjugate,p=t.aabb,A=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?s.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(o));var d,v,h=us;if(h[0]=$.safeInv(p[3]-p[0])*$.MAX_INT,h[1]=$.safeInv(p[4]-p[1])*$.MAX_INT,h[2]=$.safeInv(p[5]-p[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(h[0]),e.snapPickCoordinateScale[1]=$.safeInv(h[1]),e.snapPickCoordinateScale[2]=$.safeInv(h[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var I=cs;if(l){var y=fs;$.transformPoint3(c,l,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=u[0],I[1]+=u[1],I[2]+=u[2],d=ye(A,I,As),(v=ps)[0]=a.eye[0]-I[0],v[1]=a.eye[1]-I[1],v[2]=a.eye[2]-I[2],e.snapPickOrigin[0]=I[0],e.snapPickOrigin[1]=I[1],e.snapPickOrigin[2]=I[2]}else d=A,v=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),s.uniform3fv(this._uCoordinateScaler,h),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(f,0),this._matricesUniformBlockBufferData.set(d,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(o.positionsDecodeMatrix,m+=16),s.bindBuffer(s.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),s.bufferData(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,s.DYNAMIC_DRAW),s.bindBufferBase(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var w=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,w),this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(o.edgeIndicesBuf.bind(),s.drawElements(s.LINES,o.edgeIndicesBuf.numItems,o.edgeIndicesBuf.itemType,0),o.edgeIndicesBuf.unbind()):s.drawArrays(s.POINTS,0,o.positionsBuf.numItems)}}},{key:"_allocate",value:function(){v(T(n.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0;e.pointsMaterial._state;var n=[];return n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("gl_PointSize = 1.0;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),n}(),vs=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new ls(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new ds(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),hs={};var Is=$.mat4(),ys=$.mat4(),ms=$.vec4([0,0,0,1]),ws=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]),$.OBB3();var gs=$.vec3(),Ts=$.vec3(),Es=$.vec3(),bs=$.vec3(),Ds=$.vec3(),Ps=$.vec3(),Rs=$.vec3(),Cs=function(){function e(t){var n,r,i;b(this,e),console.info("Creating TrianglesBatchingLayer"),this.model=t.model,this.sortId="TrianglesBatchingLayer"+(t.solid?"-solid":"-surface")+(t.autoNormals?"-autonormals":"-normals")+(t.textureSet&&t.textureSet.colorTexture?"-colorTexture":"")+(t.textureSet&&t.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=t.layerIndex,this._batchingRenderers=(n=t.model.scene,r=n.id,(i=Xa[r])||(i=new Ya(n),Xa[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Xa[r],i._destroy()}))),i),this._snapBatchingRenderers=function(e){var t=e.id,n=hs[t];return n||(n=new vs(e),hs[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete hs[t],n._destroy()}))),n}(t.model.scene),this._buffer=new qa(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new ot({origin:$.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:t.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,t.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=$.mat4(t.positionsDecodeMatrix)),t.uvDecodeMatrix?(this._state.uvDecodeMatrix=$.mat3(t.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,t.origin&&this._state.origin.set(t.origin),this.aabb=$.collapseAABB3(),this.solid=!!t.solid}return P(e,[{key:"canCreatePortion",value:function(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(var M=0,F=a.length;M0){var H=Is;h?$.inverseMat4($.transposeMat4(h,ys),H):$.identityMat4(H,H),function(e,t,n,r,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}var s,o,l,u,c,f=new Float32Array([0,0,0,0]),p=new Float32Array([0,0,0,0]);for(c=0;cu&&(o=s,u=l),(l=a(p,ns(s=ts(p,"floor","ceil"))))>u&&(o=s,u=l),(l=a(p,ns(s=ts(p,"ceil","ceil"))))>u&&(o=s,u=l),r[i+c+0]=o[0],r[i+c+1]=o[1],r[i+c+2]=0}(H,i,i.length,w.normals,w.normals.length)}if(l)for(var U=0,G=l.length;U0)for(var J=0,Z=s.length;J0)for(var ee=0,te=o.length;ee0){var r=this._state.positionsDecodeMatrix?new Uint16Array(n.positions):$a(n.positions,this._modelAABB,this._state.positionsDecodeMatrix=$.mat4());if(e.positionsBuf=new lt(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(var i=0,a=this._portions.length;i0){var u=new Int8Array(n.normals);e.normalsBuf=new lt(t,t.ARRAY_BUFFER,u,n.normals.length,3,t.STATIC_DRAW,!0)}if(n.colors.length>0){var c=new Uint8Array(n.colors);e.colorsBuf=new lt(t,t.ARRAY_BUFFER,c,n.colors.length,4,t.DYNAMIC_DRAW,!1)}if(n.uv.length>0)if(e.uvDecodeMatrix){e.uvBuf=new lt(t,t.ARRAY_BUFFER,n.uv,n.uv.length,2,t.STATIC_DRAW,!1)}else{var f=ht.getUVBounds(n.uv),p=ht.compressUVs(n.uv,f.min,f.max),A=p.quantized;e.uvDecodeMatrix=$.mat3(p.decodeMatrix),e.uvBuf=new lt(t,t.ARRAY_BUFFER,A,A.length,2,t.STATIC_DRAW,!1)}if(n.metallicRoughness.length>0){var d=new Uint8Array(n.metallicRoughness);e.metallicRoughnessBuf=new lt(t,t.ARRAY_BUFFER,d,n.metallicRoughness.length,2,t.STATIC_DRAW,!1)}if(n.positions.length>0){var v=n.positions.length/3,h=new Float32Array(v);e.flagsBuf=new lt(t,t.ARRAY_BUFFER,h,h.length,1,t.DYNAMIC_DRAW,!1)}if(n.pickColors.length>0){var I=new Uint8Array(n.pickColors);e.pickColorsBuf=new lt(t,t.ARRAY_BUFFER,I,n.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var y=new Float32Array(n.offsets);e.offsetsBuf=new lt(t,t.ARRAY_BUFFER,y,n.offsets.length,3,t.DYNAMIC_DRAW)}if(n.indices.length>0){var m=new Uint32Array(n.indices);e.indicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,m,n.indices.length,1,t.STATIC_DRAW)}if(n.edgeIndices.length>0){var w=new Uint32Array(n.edgeIndices);e.edgeIndicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,w,n.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}}},{key:"isEmpty",value:function(){return!this._state.indicesBuf}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,n,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=e,r=this._portions[n],i=4*r.vertsBaseIndex,a=4*r.numVerts,s=this._scratchMemory.getUInt8Array(a),o=t[0],l=t[1],u=t[2],c=t[3],f=0;f3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=e,o=this._portions[s],l=o.vertsBaseIndex,u=o.numVerts,c=l,f=u,p=!!(t&Ee),A=!!(t&Ce),d=!!(t&_e),v=!!(t&Be),h=!!(t&Oe),I=!!(t&De),y=!!(t&be);i=!p||y||A||d&&!this.model.scene.highlightMaterial.glowThrough||v&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,a=!p||y?Ia.NOT_RENDERED:v?Ia.SILHOUETTE_SELECTED:d?Ia.SILHOUETTE_HIGHLIGHTED:A?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED;var m=0;m=!p||y?Ia.NOT_RENDERED:v?Ia.EDGES_SELECTED:d?Ia.EDGES_HIGHLIGHTED:A?Ia.EDGES_XRAYED:h?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED;var w=p&&!y&&I?Ia.PICK:Ia.NOT_RENDERED,g=t&Pe?1:0;if(r){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var T=c,E=c+f;TI)&&(I=b,r.set(y),i&&$.triangleNormal(A,d,v,i),h=!0)}}return h&&i&&($.transformVec3(this.model.worldNormalMatrix,i,i),$.normalizeVec3(i)),h}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}]),e}(),_s=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t,n,r=this._scene,i=r._sectionPlanesState,a=r._lightsState,s=i.sectionPlanes.length>0,o=[];for(o.push("#version 300 es"),o.push("// Instancing geometry drawing vertex shader"),o.push("uniform int renderPass;"),o.push("in vec3 position;"),o.push("in vec2 normal;"),o.push("in vec4 color;"),o.push("in float flags;"),r.entityOffsetsEnabled&&o.push("in vec3 offset;"),o.push("in vec4 modelMatrixCol0;"),o.push("in vec4 modelMatrixCol1;"),o.push("in vec4 modelMatrixCol2;"),o.push("in vec4 modelNormalMatrixCol0;"),o.push("in vec4 modelNormalMatrixCol1;"),o.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(o,!0),r.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;")),o.push("uniform vec4 lightAmbient;"),e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"),s&&(o.push("out vec4 vWorldPosition;"),o.push("out float vFlags;")),o.push("out vec4 vColor;"),o.push("void main(void) {"),o.push("int colorFlag = int(flags) & 0xF;"),o.push("if (colorFlag != renderPass) {"),o.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),o.push("} else {"),o.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),o.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),r.entityOffsetsEnabled&&o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix * worldPosition; "),o.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),o.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),o.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),e=0,t=a.lights.length;e0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),n}(),Bs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry flat-shading drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=n._lightsState,a=r.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),n.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),a){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var o=0,l=r.sectionPlanes.length;o> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var c=0,f=r.sectionPlanes.length;c 0.0) { "),s.push(" discard;"),s.push(" }"),s.push("}")}for(s.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),s.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),s.push("float lambertian = 1.0;"),s.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),s.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),s.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=i.lights.length;e0,n=[];return n.push("#version 300 es"),n.push("// Instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing fill fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ss=function(e){I(n,Ca);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles instancing edges vertex shader"),n.push("uniform int renderPass;"),n.push("uniform vec4 color;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ns=function(e){I(n,Ca);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles instancing edges vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ls=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry picking vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vPickColor; "),r.push("}"),r}}]),n}(),xs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Ms=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec2 normal;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("in vec4 modelNormalMatrixCol0;"),n.push("in vec4 modelNormalMatrixCol1;"),n.push("in vec4 modelNormalMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vWorldNormal;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),n.push(" vWorldNormal = worldNormal;"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}}]),n}(),Fs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// TrianglesInstancingOcclusionRenderer vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesInstancingOcclusionRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}]),n}(),Hs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry depth drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec2 vHighPrecisionZW;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),n.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}]),n}(),Us=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n,!0),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),Gs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry shadow drawing vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("bool visible = (colorFlag > 0);"),n.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push("if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),ks={3e3:"linearToLinear",3001:"sRGBToLinear"},js=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=e._lightsState,r=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),n.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),r&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),r&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),n.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._sectionPlanesState,r=e._lightsState,i=n.sectionPlanes.length>0,a=n.clippingCaps,s=[];s.push("#version 300 es"),s.push("// Instancing geometry quality drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform sampler2D uColorMap;"),s.push("uniform sampler2D uMetallicRoughMap;"),s.push("uniform sampler2D uEmissiveMap;"),s.push("uniform sampler2D uNormalMap;"),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),r.reflectionMaps.length>0&&s.push("uniform samplerCube reflectionMap;"),r.lightMaps.length>0&&s.push("uniform samplerCube lightMap;"),s.push("uniform vec4 lightAmbient;");for(var o=0,l=r.lights.length;o0&&s.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(s,!0),s.push("#define PI 3.14159265359"),s.push("#define RECIPROCAL_PI 0.31830988618"),s.push("#define RECIPROCAL_PI2 0.15915494"),s.push("#define EPSILON 1e-6"),s.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),s.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),s.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),s.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),s.push(" return normalize(surf_norm );"),s.push(" }"),s.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),s.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),s.push(" vec2 st0 = dFdx( uv.st );"),s.push(" vec2 st1 = dFdy( uv.st );"),s.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),s.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),s.push(" vec3 N = normalize( surf_norm );"),s.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),s.push(" mat3 tsn = mat3( S, T, N );"),s.push(" return normalize( tsn * mapN );"),s.push("}"),s.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),s.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),s.push("}"),s.push("struct IncidentLight {"),s.push(" vec3 color;"),s.push(" vec3 direction;"),s.push("};"),s.push("struct ReflectedLight {"),s.push(" vec3 diffuse;"),s.push(" vec3 specular;"),s.push("};"),s.push("struct Geometry {"),s.push(" vec3 position;"),s.push(" vec3 viewNormal;"),s.push(" vec3 worldNormal;"),s.push(" vec3 viewEyeDir;"),s.push("};"),s.push("struct Material {"),s.push(" vec3 diffuseColor;"),s.push(" float specularRoughness;"),s.push(" vec3 specularColor;"),s.push(" float shine;"),s.push("};"),s.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),s.push(" float r = ggxRoughness + 0.0001;"),s.push(" return (2.0 / (r * r) - 2.0);"),s.push("}"),s.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),s.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),s.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),s.push("}"),r.reflectionMaps.length>0&&(s.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),s.push(" vec3 envMapColor = "+ks[r.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),s.push(" return envMapColor;"),s.push("}")),s.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),s.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),s.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),s.push("}"),s.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" return 1.0 / ( gl * gv );"),s.push("}"),s.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" return 0.5 / max( gv + gl, EPSILON );"),s.push("}"),s.push("float D_GGX(const in float alpha, const in float dotNH) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),s.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float alpha = ( roughness * roughness );"),s.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),s.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),s.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),s.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),s.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),s.push(" vec3 F = F_Schlick( specularColor, dotLH );"),s.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),s.push(" float D = D_GGX( alpha, dotNH );"),s.push(" return F * (G * D);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),s.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),s.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),s.push(" vec4 r = roughness * c0 + c1;"),s.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),s.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),s.push(" return specularColor * AB.x + AB.y;"),s.push("}"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&(s.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.lightMaps.length>0&&(s.push(" vec3 irradiance = "+ks[r.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),s.push(" irradiance *= PI;"),s.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),r.reflectionMaps.length>0&&(s.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),s.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),s.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),s.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),s.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),s.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),s.push("}")),s.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),s.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),s.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),s.push("}"),s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var p=0,A=n.sectionPlanes.length;p (0.002 * vClipPosition.w)) {"),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" return;"),s.push("}")):(s.push(" if (dist > 0.0) { "),s.push(" discard;"),s.push(" }")),s.push("}")}s.push("IncidentLight light;"),s.push("Material material;"),s.push("Geometry geometry;"),s.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),s.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),s.push("float opacity = float(vColor.a) / 255.0;"),s.push("vec3 baseColor = rgb;"),s.push("float specularF0 = 1.0;"),s.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),s.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),s.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),s.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),s.push("baseColor *= colorTexel.rgb;"),s.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),s.push("metallic *= metalRoughTexel.b;"),s.push("roughness *= metalRoughTexel.g;"),s.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),s.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),s.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),s.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),s.push("geometry.position = vViewPosition.xyz;"),s.push("geometry.viewNormal = -normalize(viewNormal);"),s.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),r.lightMaps.length>0&&s.push("geometry.worldNormal = normalize(vWorldNormal);"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&s.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var d=0,v=r.lights.length;d0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&n.push("out float vFlags;"),n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&n.push("vFlags = flags;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}}]),n}(),Qs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n.gammaOutput,i=n._sectionPlanesState,a=n._lightsState,s=i.sectionPlanes.length>0,o=[];if(o.push("#version 300 es"),o.push("// Instancing geometry drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),n.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),o.push("uniform sampler2D uColorMap;"),this._withSAO&&(o.push("uniform sampler2D uOcclusionTexture;"),o.push("uniform vec4 uSAOParams;"),o.push("const float packUpscale = 256. / 255.;"),o.push("const float unpackDownScale = 255. / 256.;"),o.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),o.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),o.push("float unpackRGBToFloat( const in vec4 v ) {"),o.push(" return dot( v, unPackFactors );"),o.push("}")),o.push("uniform float gammaFactor;"),o.push("vec4 linearToLinear( in vec4 value ) {"),o.push(" return value;"),o.push("}"),o.push("vec4 sRGBToLinear( in vec4 value ) {"),o.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),o.push("}"),o.push("vec4 gammaToLinear( in vec4 value) {"),o.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),o.push("}"),r&&(o.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),o.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),o.push("}")),s){o.push("in vec4 vWorldPosition;"),o.push("in float vFlags;");for(var l=0,u=i.sectionPlanes.length;l> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var f=0,p=i.sectionPlanes.length;f 0.0) { "),o.push(" discard;"),o.push(" }"),o.push("}")}for(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),o.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),o.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),o.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=a.lights.length;e0,n=[];return n.push("#version 300 es"),n.push("// SnapInstancingDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),n}(),$s=$.vec3(),eo=$.vec3(),to=$.vec3(),no=$.vec3(),ro=$.mat4(),io=function(e){I(n,ba);var t=m(n);function n(e){return b(this,n),t.call(this,e,!1,{instancing:!0})}return P(n,[{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin,u=r.position,c=r.rotationMatrix,f=r.rotationMatrixConjugate,p=t.aabb,A=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?s.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(o));var d,v,h=$s;if(h[0]=$.safeInv(p[3]-p[0])*$.MAX_INT,h[1]=$.safeInv(p[4]-p[1])*$.MAX_INT,h[2]=$.safeInv(p[5]-p[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(h[0]),e.snapPickCoordinateScale[1]=$.safeInv(h[1]),e.snapPickCoordinateScale[2]=$.safeInv(h[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var I=eo;if(l){var y=$.transformPoint3(c,l,to);I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=u[0],I[1]+=u[1],I[2]+=u[2],d=ye(A,I,ro),(v=no)[0]=a.eye[0]-I[0],v[1]=a.eye[1]-I[1],v[2]=a.eye[2]-I[2],e.snapPickOrigin[0]=I[0],e.snapPickOrigin[1]=I[1],e.snapPickOrigin[2]=I[2]}else d=A,v=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),s.uniform3fv(this._uCoordinateScaler,h),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(f,0),this._matricesUniformBlockBufferData.set(d,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(o.positionsDecodeMatrix,m+=16),s.bindBuffer(s.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),s.bufferData(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,s.DYNAMIC_DRAW),s.bindBufferBase(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var w=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,w),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(o.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(o.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(o.modelMatrixCol2Buf),s.vertexAttribDivisor(this._aModelMatrixCol0.location,1),s.vertexAttribDivisor(this._aModelMatrixCol1.location,1),s.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(o.flagsBuf),s.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(o.edgeIndicesBuf.bind(),s.drawElementsInstanced(s.LINES,o.edgeIndicesBuf.numItems,o.edgeIndicesBuf.itemType,0,o.numInstances),o.edgeIndicesBuf.unbind()):s.drawArraysInstanced(s.POINTS,0,o.positionsBuf.numItems,o.numInstances),s.vertexAttribDivisor(this._aModelMatrixCol0.location,0),s.vertexAttribDivisor(this._aModelMatrixCol1.location,0),s.vertexAttribDivisor(this._aModelMatrixCol2.location,0),s.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&s.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){v(T(n.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// SnapInstancingDepthRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("gl_PointSize = 1.0;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// SnapInstancingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),n}(),ao=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Zs(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new io(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),so={};var oo=new Uint8Array(4),lo=new Float32Array(1),uo=$.vec4([0,0,0,1]),co=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]);var fo=new Float32Array(3),po=$.vec3(),Ao=$.vec3(),vo=$.vec3(),ho=$.vec3(),Io=$.vec3(),yo=$.vec3(),mo=$.vec3(),wo=function(){function e(t){var n,r,i;b(this,e),console.info("Creating TrianglesInstancingLayer"),this.model=t.model,this.sortId="TrianglesInstancingLayer"+(t.solid?"-solid":"-surface")+(t.normals?"-normals":"-autoNormals"),this.layerIndex=t.layerIndex,this._instancingRenderers=(n=t.model.scene,r=n.id,(i=zs[r])||(i=new Ws(n),zs[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete zs[r],i._destroy()}))),i),this._snapInstancingRenderers=function(e){var t=e.id,n=so[t];return n||(n=new ao(e),so[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete so[t],n._destroy()}))),n}(t.model.scene),this._aabb=$.collapseAABB3(),this._state=new ot({numInstances:0,obb:$.OBB3(),origin:$.vec3(),geometry:t.geometry,textureSet:t.textureSet,pbrSupported:!1,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],t.origin&&this._state.origin.set(t.origin),this._finalized=!1,this.aabb=$.collapseAABB3(),this.solid=!!t.solid,this.numIndices=t.geometry.numIndices}return P(e,[{key:"createPortion",value:function(e){var t=e.color,n=e.metallic,r=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,s=e.aabb,o=e.pickColor;if(this._finalized)throw"Already finalized";var l=t[0],u=t[1],c=t[2];if(this._colors.push(l),this._colors.push(u),this._colors.push(c),this._colors.push(i),this._metallicRoughness.push(null!=n?n:0),this._metallicRoughness.push(null!=r?r:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){var f=$.transposeMat4(a,$.mat4()),p=$.inverseMat4(f);this._modelNormalMatrixCol0.push(p[0]),this._modelNormalMatrixCol0.push(p[4]),this._modelNormalMatrixCol0.push(p[8]),this._modelNormalMatrixCol0.push(p[12]),this._modelNormalMatrixCol1.push(p[1]),this._modelNormalMatrixCol1.push(p[5]),this._modelNormalMatrixCol1.push(p[9]),this._modelNormalMatrixCol1.push(p[13]),this._modelNormalMatrixCol2.push(p[2]),this._modelNormalMatrixCol2.push(p[6]),this._modelNormalMatrixCol2.push(p[10]),this._modelNormalMatrixCol2.push(p[14])}this._pickColors.push(o[0]),this._pickColors.push(o[1]),this._pickColors.push(o[2]),this._pickColors.push(o[3]);for(var A=this._state.geometry.positionsCompressed.length,d=this._state.geometry.positionsCompressed,v=this._state.geometry.positionsDecodeMatrix,h=0;h0){e.colorsBuf=new lt(r,r.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,r.DYNAMIC_DRAW,!1),this._colors=[]}if(this._metallicRoughness.length>0){var s=new Uint8Array(this._metallicRoughness);e.metallicRoughnessBuf=new lt(r,r.ARRAY_BUFFER,s,this._metallicRoughness.length,2,r.STATIC_DRAW,!1)}if(a>0){e.flagsBuf=new lt(r,r.ARRAY_BUFFER,new Float32Array(a),a,1,r.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){e.offsetsBuf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,r.DYNAMIC_DRAW,!1),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){e.positionsBuf=new lt(r,r.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,r.STATIC_DRAW,!1),e.positionsDecodeMatrix=$.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){var o=new Uint8Array(t.colorsCompressed);e.colorsBuf=new lt(r,r.ARRAY_BUFFER,o,o.length,4,r.STATIC_DRAW,!1)}if(t.uvCompressed&&t.uvCompressed.length>0){var l=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new lt(r,r.ARRAY_BUFFER,l,l.length,2,r.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new lt(r,r.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,r.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new lt(r,r.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,r.STATIC_DRAW)),this._modelMatrixCol0.length>0){var u=!1;e.modelMatrixCol0Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,r.STATIC_DRAW,u),e.modelMatrixCol1Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,r.STATIC_DRAW,u),e.modelMatrixCol2Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,r.STATIC_DRAW,u),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,r.STATIC_DRAW,u),e.modelNormalMatrixCol1Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,r.STATIC_DRAW,u),e.modelNormalMatrixCol2Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,r.STATIC_DRAW,u),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){e.pickColorsBuf=new lt(r,r.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,r.STATIC_DRAW,!1),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&n&&n.colorTexture&&n.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!n&&!!n.colorTexture,this._state.geometry=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";oo[0]=t[0],oo[1]=t[1],oo[2]=t[2],oo[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(oo,4*e)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Ee),i=!!(t&Ce),a=!!(t&_e),s=!!(t&Be),o=!!(t&Oe),l=!!(t&De),u=!!(t&be),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.SILHOUETTE_SELECTED:a?Ia.SILHOUETTE_HIGHLIGHTED:i?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED)<<4,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.EDGES_SELECTED:a?Ia.EDGES_HIGHLIGHTED:i?Ia.EDGES_XRAYED:o?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED)<<8,c|=(r&&!u&&l?Ia.PICK:Ia.NOT_RENDERED)<<12,c|=(t&Pe?1:0)<<16,lo[0]=c,this._state.flagsBuf&&this._state.flagsBuf.setData(lo,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(fo[0]=t[0],fo[1]=t[1],fo[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(fo,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"getEachVertex",value:function(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var n=this._state,r=n.geometry,i=this._portions[e];if(i)for(var a=r.quantizedPositions,s=n.origin,o=i.offset,l=s[0]+o[0],u=s[1]+o[1],c=s[2]+o[2],f=uo,p=i.matrix,A=this.model.sceneModelMatrix,d=n.positionsDecodeMatrix,v=0,h=a.length;vy)&&(y=P,r.set(m),i&&$.triangleNormal(d,v,h,i),I=!0)}}return I&&i&&($.transformVec3(o.normalMatrix,i,i),$.transformVec3(this.model.worldNormalMatrix,i,i),$.normalizeVec3(i)),I}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}]),e}(),go=function(e){I(n,Oa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines batching color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),To=function(e){I(n,Oa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines batching silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = color;"),r.push("}"),r}}]),n}(),Eo=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new go(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new To(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),bo={};var Do=P((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]})),Po=$.vec4([0,0,0,1]),Ro=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]),$.OBB3();var Co=function(){function e(t){var n,r,i;b(this,e),this.layerIndex=t.layerIndex,this._batchingRenderers=(n=t.model.scene,r=n.id,(i=bo[r])||(i=new Eo(n),bo[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete bo[r],i._destroy()}))),i),this.model=t.model,this._buffer=new Do(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new ot({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:$.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=$.vec3(t.origin)),this.aabb=$.collapseAABB3()}return P(e,[{key:"canCreatePortion",value:function(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){var r=new Uint16Array(n.positions);e.positionsBuf=new lt(t,t.ARRAY_BUFFER,r,n.positions.length,3,t.STATIC_DRAW)}else{var i=$a(new Float32Array(n.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new lt(t,t.ARRAY_BUFFER,i,n.positions.length,3,t.STATIC_DRAW)}if(n.colors.length>0){var a=new Uint8Array(n.colors);e.colorsBuf=new lt(t,t.ARRAY_BUFFER,a,n.colors.length,4,t.DYNAMIC_DRAW,!1)}if(n.colors.length>0){var s=n.colors.length/4,o=new Float32Array(s);e.flagsBuf=new lt(t,t.ARRAY_BUFFER,o,o.length,1,t.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var l=new Float32Array(n.offsets);e.offsetsBuf=new lt(t,t.ARRAY_BUFFER,l,n.offsets.length,3,t.DYNAMIC_DRAW)}if(n.indices.length>0){var u=new Uint32Array(n.indices);e.indicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,u,n.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,n,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=2*e,r=4*this._portions[n],i=4*this._portions[n+1],a=this._scratchMemory.getUInt8Array(i),s=t[0],o=t[1],l=t[2],u=t[3],c=0;c3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=2*e,o=this._portions[s],l=this._portions[s+1],u=o,c=l,f=!!(t&Ee),p=!!(t&Ce),A=!!(t&_e),d=!!(t&Be),v=!!(t&De),h=!!(t&be);i=!f||h||p||A&&!this.model.scene.highlightMaterial.glowThrough||d&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,a=!f||h?Ia.NOT_RENDERED:d?Ia.SILHOUETTE_SELECTED:A?Ia.SILHOUETTE_HIGHLIGHTED:p?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED;var I=f&&!h&&v?Ia.PICK:Ia.NOT_RENDERED,y=t&Pe?1:0;if(r){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var m=u,w=u+c;m0,n=[];return n.push("#version 300 es"),n.push("// Lines instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 lightAmbient;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),Bo=function(e){I(n,Sa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 color;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines instancing silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = color;"),r.push("}"),r}}]),n}(),Oo=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new _o(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Bo(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),So={};var No=new Uint8Array(4),Lo=new Float32Array(1),xo=$.vec4([0,0,0,1]),Mo=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]);var Fo=new Float32Array(3),Ho=function(){function e(t){var n,r,i;b(this,e),this.model=t.model,this.material=t.material,this.sortId="LinesInstancingLayer",this.layerIndex=t.layerIndex,this._linesInstancingRenderers=(n=t.model.scene,r=n.id,(i=So[r])||(i=new Oo(n),So[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete So[r],i._destroy()}))),i),this._aabb=$.collapseAABB3(),this._state=new ot({obb:$.OBB3(),numInstances:0,origin:null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],t.origin&&(this._state.origin=$.vec3(t.origin)),this._finalized=!1,this.aabb=$.collapseAABB3()}return P(e,[{key:"createPortion",value:function(e){var t=e.color,n=e.opacity,r=e.meshMatrix,i=e.aabb;if(this._finalized)throw"Already finalized";var a=t[0],s=t[1],o=t[2];t[3],this._colors.push(a),this._colors.push(s),this._colors.push(o),this._colors.push(n),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(r[0]),this._modelMatrixCol0.push(r[4]),this._modelMatrixCol0.push(r[8]),this._modelMatrixCol0.push(r[12]),this._modelMatrixCol1.push(r[1]),this._modelMatrixCol1.push(r[5]),this._modelMatrixCol1.push(r[9]),this._modelMatrixCol1.push(r[13]),this._modelMatrixCol2.push(r[2]),this._modelMatrixCol2.push(r[6]),this._modelMatrixCol2.push(r[10]),this._modelMatrixCol2.push(r[14]),$.collapseAABB3(i);for(var l=this._state.obb,u=l.length,c=0;c0){this._state.colorsBuf=new lt(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,!1),this._colors=[]}if(n>0){this._state.flagsBuf=new lt(e,e.ARRAY_BUFFER,new Float32Array(n),n,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){this._state.offsetsBuf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(this._modelMatrixCol0.length>0){var r=!1;this._state.modelMatrixCol0Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,r),this._state.modelMatrixCol1Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,r),this._state.modelMatrixCol2Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,r),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";No[0]=t[0],No[1]=t[1],No[2]=t[2],No[3]=t[3],this._state.colorsBuf.setData(No,4*e,4)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Ee),i=!!(t&Ce),a=!!(t&_e),s=!!(t&Be),o=!!(t&Oe),l=!!(t&De),u=!!(t&be),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.SILHOUETTE_SELECTED:a?Ia.SILHOUETTE_HIGHLIGHTED:i?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED)<<4,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.EDGES_SELECTED:a?Ia.EDGES_HIGHLIGHTED:i?Ia.EDGES_XRAYED:o?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED)<<8,c|=(r&&!u&&l?Ia.PICK:Ia.NOT_RENDERED)<<12,c|=(t&Pe?255:0)<<16,Lo[0]=c,this._state.flagsBuf.setData(Lo,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Fo[0]=t[0],Fo[1]=t[1],Fo[2]=t[2],this._state.offsetsBuf.setData(Fo,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){}},{key:"drawPickDepths",value:function(e,t){}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}]),e}(),Uo=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial,r=[];return r.push("#version 300 es"),r.push("// Points batching color vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("in float flags;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),n.filterIntensity&&r.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),n.filterIntensity&&(r.push("float intensity = float(color.a) / 255.0;"),r.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {")),r.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),n.filterIntensity&&r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),Go=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching silhouette vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),this._addMatricesUniformBlockLines(r),r.push("uniform vec4 color;"),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),r.push("if (silhouetteFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}]),n}(),ko=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching pick mesh vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 pickColor;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vPickColor;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),r.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("gl_PointSize += 10.0;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching pick mesh vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vPickColor; "),r.push("}"),r}}]),n}(),jo=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batched pick depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vViewPosition;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vViewPosition = viewPosition;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("gl_PointSize += 10.0;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batched pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Vo=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching occlusion vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push(" gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching occlusion fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),r.push("}"),r}}]),n}(),Qo=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Uo(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Go(this._scene)),this._silhouetteRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new ko(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new jo(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Vo(this._scene)),this._occlusionRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}]),e}(),Wo={};var zo=P((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]})),Ko=$.vec4(),Yo=$.vec4(),Xo=$.vec4([0,0,0,1]),qo=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]),$.OBB3();var Jo=function(){function e(t){b(this,e),this.model=t.model,this.sortId="PointsBatchingLayer",this.layerIndex=t.layerIndex,this._pointsBatchingRenderers=function(e){var t=e.id,n=Wo[t];return n||(n=new Qo(e),Wo[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Wo[t],n._destroy()}))),n}(t.model.scene),this._buffer=new zo(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new ot({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:$.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=$.vec3(t.origin)),this.aabb=$.collapseAABB3()}return P(e,[{key:"canCreatePortion",value:function(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}},{key:"createPortion",value:function(e){if(this._finalized)throw"Already finalized";var t,n=e.positions,r=e.positionsCompressed,i=e.color,a=e.colorsCompressed,s=e.colors,o=e.meshMatrix,l=e.worldAABB,u=e.pickColor,c=this._buffer,f=c.positions.length/3;if(this._preCompressedPositionsExpected){if(!r)throw"positionsCompressed expected";for(var p=0,A=r.length;p0)if(this._preCompressedPositionsExpected){var r=new Uint16Array(n.positions);e.positionsBuf=new lt(t,t.ARRAY_BUFFER,r,n.positions.length,3,t.STATIC_DRAW)}else{var i=$a(new Float32Array(n.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new lt(t,t.ARRAY_BUFFER,i,n.positions.length,3,t.STATIC_DRAW)}if(n.colors.length>0){var a=new Uint8Array(n.colors);e.colorsBuf=new lt(t,t.ARRAY_BUFFER,a,n.colors.length,4,t.STATIC_DRAW,!1)}if(n.positions.length>0){var s=n.positions.length/3,o=new Float32Array(s);e.flagsBuf=new lt(t,t.ARRAY_BUFFER,o,o.length,1,t.DYNAMIC_DRAW,!1)}if(n.pickColors.length>0){var l=new Uint8Array(n.pickColors);e.pickColorsBuf=new lt(t,t.ARRAY_BUFFER,l,n.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var u=new Float32Array(n.offsets);e.offsetsBuf=new lt(t,t.ARRAY_BUFFER,u,n.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized"}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=2*e,r=4*this._portions[n],i=4*this._portions[n+1],a=this._scratchMemory.getUInt8Array(i),s=t[0],o=t[1],l=t[2],u=0;u0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing color vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("in float flags;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),n.filterIntensity&&r.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),n.filterIntensity&&(r.push("float intensity = float(color.a) / 255.0;"),r.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {")),r.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),n.filterIntensity&&r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),$o=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing silhouette vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 color;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),r.push("uniform vec4 silhouetteColor;"),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),r.push("if (silhouetteFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),el=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing pick mesh vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 pickColor;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vPickColor;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),r.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing pick mesh fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vPickColor; "),r.push("}"),r}}]),n}(),tl=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing pick depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vViewPosition;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push(" vViewPosition = viewPosition;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),nl=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing occlusion vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in vec4 color;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing occlusion vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),rl=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),il=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry shadow drawing vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("bool visible = (colorFlag > 0);"),n.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push("if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n.push("gl_PointSize = pointSize;"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),al=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Zo(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new $o(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new rl(this._scene)),this._depthRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new el(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new tl(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new nl(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new il(this._scene)),this._shadowRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}]),e}(),sl={};var ol=new Uint8Array(4),ll=new Float32Array(1),ul=$.vec4([0,0,0,1]),cl=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]);var fl=new Float32Array(3),pl=function(){function e(t){var n,r,i;b(this,e),this.model=t.model,this.material=t.material,this.sortId="PointsInstancingLayer",this.layerIndex=t.layerIndex,this._pointsInstancingRenderers=(n=t.model.scene,r=n.id,(i=sl[r])||(i=new al(n),sl[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete sl[r],i._destroy()}))),i),this._aabb=$.collapseAABB3(),this._state=new ot({obb:$.OBB3(),numInstances:0,origin:t.origin?$.vec3(t.origin):null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=$.collapseAABB3()}return P(e,[{key:"createPortion",value:function(e){var t=e.meshMatrix,n=e.aabb,r=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(r[0]),this._pickColors.push(r[1]),this._pickColors.push(r[2]),this._pickColors.push(r[3]),$.collapseAABB3(n);for(var i=this._state.obb,a=i.length,s=0;s0){n.flagsBuf=new lt(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){n.offsetsBuf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(r.positionsCompressed&&r.positionsCompressed.length>0){n.positionsBuf=new lt(e,e.ARRAY_BUFFER,r.positionsCompressed,r.positionsCompressed.length,3,e.STATIC_DRAW,!1),n.positionsDecodeMatrix=$.mat4(r.positionsDecodeMatrix)}if(r.colorsCompressed&&r.colorsCompressed.length>0){var i=new Uint8Array(r.colorsCompressed);n.colorsBuf=new lt(e,e.ARRAY_BUFFER,i,i.length,4,e.STATIC_DRAW,!1)}if(this._modelMatrixCol0.length>0){var a=!1;n.modelMatrixCol0Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,a),n.modelMatrixCol1Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,a),n.modelMatrixCol2Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,a),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){n.pickColorsBuf=new lt(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,!1),this._pickColors=[]}n.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";ol[0]=t[0],ol[1]=t[1],ol[2]=t[2],this._state.colorsBuf.setData(ol,3*e)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Ee),i=!!(t&Ce),a=!!(t&_e),s=!!(t&Be),o=!!(t&Oe),l=!!(t&De),u=!!(t&be),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.SILHOUETTE_SELECTED:a?Ia.SILHOUETTE_HIGHLIGHTED:i?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED)<<4,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.EDGES_SELECTED:a?Ia.EDGES_HIGHLIGHTED:i?Ia.EDGES_XRAYED:o?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED)<<8,c|=(r&&!u&&l?Ia.PICK:Ia.NOT_RENDERED)<<12,c|=(t&Pe?255:0)<<16,ll[0]=c,this._state.flagsBuf.setData(ll,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(fl[0]=t[0],fl[1]=t[1],fl[2]=t[2],this._state.offsetsBuf.setData(fl,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE)}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Ia.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Ia.PICK)}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}]),e}(),Al=function(){function e(t){b(this,e),this.id=t.id,this.colorTexture=t.colorTexture,this.metallicRoughnessTexture=t.metallicRoughnessTexture,this.normalsTexture=t.normalsTexture,this.emissiveTexture=t.emissiveTexture,this.occlusionTexture=t.occlusionTexture}return P(e,[{key:"destroy",value:function(){}}]),e}(),dl=function(){function e(t){b(this,e),this.id=t.id,this.texture=t.texture}return P(e,[{key:"destroy",value:function(){this.texture&&(this.texture.destroy(),this.texture=null)}}]),e}(),vl={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}},hl=function(){function e(t,n,r){b(this,e),this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=t,this.onProgress=n,this.onError=r}return P(e,[{key:"itemStart",value:function(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}},{key:"itemEnd",value:function(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}},{key:"itemError",value:function(e){void 0!==this.onError&&this.onError(e)}},{key:"resolveURL",value:function(e){return this.urlModifier?this.urlModifier(e):e}},{key:"setURLModifier",value:function(e){return this.urlModifier=e,this}},{key:"addHandler",value:function(e,t){return this.handlers.push(e,t),this}},{key:"removeHandler",value:function(e){var t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}},{key:"getHandler",value:function(e){for(var t=0,n=this.handlers.length;t0&&void 0!==arguments[0]?arguments[0]:4;b(this,e),this.pool=t,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}return P(e,[{key:"_initWorker",value:function(e){if(!this.workers[e]){var t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}},{key:"_getIdleWorker",value:function(){for(var e=0;e0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Tl++}return this._transcoderPending}},{key:"transcode",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,a){var s=r;n._init().then((function(){return n._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:s},e)})).then((function(e){var n=e.data,r=n.mipmaps,s=(n.width,n.height,n.format),o=n.type,l=n.error,u=n.dfdTransferFn,c=n.dfdFlags;if("error"===o)return a(l);t.setCompressedData({mipmaps:r,props:{format:s,minFilter:1===r.length?1006:1008,magFilter:1===r.length?1006:1008,encoding:2===u?3001:3e3,premultiplyAlpha:!!(1&c)}}),i()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),Tl--}}]),e}();El.BasisFormat={ETC1S:0,UASTC_4x4:1},El.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},El.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},El.BasisWorker=function(){var e,t,n,r=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(s){var c,f=s.data;switch(f.type){case"init":e=f.config,c=f.transcoderBinary,t=new Promise((function(e){n={wasmBinary:c,onRuntimeInitialized:e},BASIS(n)})).then((function(){n.initializeBasis(),void 0===n.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((function(){try{for(var t=function(t){var s=new n.KTX2File(new Uint8Array(t));function c(){s.close(),s.delete()}if(!s.isValid())throw c(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var f=s.isUASTC()?a.UASTC_4x4:a.ETC1S,p=s.getWidth(),A=s.getHeight(),d=s.getLevels(),v=s.getHasAlpha(),h=s.getDFDTransferFunc(),I=s.getDFDFlags(),y=function(t,n,s,c){for(var f,p,A=t===a.ETC1S?o:l,d=0;d=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var o=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(o&&l){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),b(n),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;b(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:P(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},e}function u(e,t,n,r,i,a,s){try{var o=e[a](s),l=o.value}catch(e){return void n(e)}o.done?t(l):Promise.resolve(l).then(r,i)}function c(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function s(e){u(a,r,i,s,o,"next",e)}function o(e){u(a,r,i,s,o,"throw",e)}s(void 0)}))}}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=A(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}(e,t)||A(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._id=k.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==n.hideOnMouseDown&&(document.addEventListener("mousedown",(function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),n.items&&(this.items=n.items),this._hideOnAction=!1!==n.hideOnAction,this.context=n.context,this.enabled=!1!==n.enabled,this.hide()}return P(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r0,c=t._getNextId(),f=a.getTitle||function(){return a.title||""},p=a.doAction||a.callback||function(){},A=a.getEnabled||function(){return!0},d=a.getShown||function(){return!0},v=new Q(c,f,p,A,d);if(v.parentMenu=i,l.items.push(v),u){var h=e(s);v.subMenu=h,h.parentItem=v}t._itemList.push(v),t._itemMap[v.id]=v},c=0,f=o.length;c'),r.push("
    "),n)for(var i=0,a=n.length;i'+A+" [MORE]"):r.push('
  • '+A+"
  • ")}}r.push("
"),r.push("");var d=r.join("");document.body.insertAdjacentHTML("beforeend",d);var v=document.querySelector("."+e.id);e.menuElement=v,v.style["border-radius"]="4px",v.style.display="none",v.style["z-index"]=3e5,v.style.background="white",v.style.border="1px solid black",v.style["box-shadow"]="0 4px 5px 0 gray",v.oncontextmenu=function(e){e.preventDefault()};var h=this,I=null;if(n)for(var y=0,m=n.length;ywindow.innerWidth?h._showMenu(t.id,a.left-200,a.top-1):h._showMenu(t.id,a.right-5,a.top-1),I=t}}else I&&(h._hideMenu(I.id),I=null)})),i||(r.itemElement.addEventListener("click",(function(e){e.preventDefault(),h._context&&!1!==r.enabled&&(r.doAction&&r.doAction(h._context),t._hideOnAction?h.hide():(h._updateItemsTitles(),h._updateItemsEnabledStatus()))})),r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==r.enabled&&r.doHover&&r.doHover(h._context)})))},T=0,E=w.length;Twindow.innerHeight&&(n=window.innerHeight-r),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=n+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),z=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this.viewer=t,this.scene=this.viewer.scene,this._lensCursorDiv=document.createElement("div"),this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._lensCursorDiv,this.viewer.scene.canvas.canvas),this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red",this._lensCursorDiv.style.borderRadius="20px",this._lensCursorDiv.style.width="10px",this._lensCursorDiv.style.height="10px",this._lensCursorDiv.style.margin="-200px -200px",this._lensCursorDiv.style.zIndex="100000",this._lensCursorDiv.style.position="absolute",this._lensCursorDiv.style.pointerEvents="none",this._lensContainer=document.createElement("div"),this._lensContainer.style.border="1px solid black",this._lensContainer.style.background="white",this._lensContainer.style.borderRadius="50%",this._lensContainer.style.width="300px",this._lensContainer.style.height="300px",this._lensContainer.style.marginTop="85px",this._lensContainer.style.marginLeft="25px",this._lensContainer.style.zIndex="15000",this._lensContainer.style.position="absolute",this._lensContainer.style.pointerEvents="none",this._lensContainer.style.visibility="hidden",this._lensCanvas=document.createElement("canvas"),this._lensCanvas.style.borderRadius="50%",this._lensCanvas.style.width="300px",this._lensCanvas.style.height="300px",this._lensCanvas.style.zIndex="15000",this._lensCanvas.style.pointerEvents="none",document.body.appendChild(this._lensContainer),this._lensContainer.appendChild(this._lensCanvas),this._lensCanvasContext=this._lensCanvas.getContext("2d"),this._canvasElement=this.viewer.scene.canvas.canvas,this._centerPos=null,this._cursorPos=null,this._lensPosToggle=!0,this._zoomLevel=r.zoomLevel||2,this._active=!1!==r.active,this._visible=!1,this._snapped=!1,this._onViewerRendering=this.viewer.scene.on("rendering",(function(){n._active&&n._visible&&n.update()}))}return P(e,[{key:"update",value:function(){if(this._active&&this._visible&&this._centerPos){var e=this._lensContainer.getBoundingClientRect(),t=this._canvasElement.getBoundingClientRect(),n=this._centerPos[0]e.left&&this._centerPos[1]e.top;this._lensContainer.style.marginLeft="25px",n&&(this._lensPosToggle?this._lensContainer.style.marginTop="".concat(t.bottom-t.top-this._lensCanvas.height-85,"px"):this._lensContainer.style.marginTop="85px",this._lensPosToggle=!this._lensPosToggle),this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);var r=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,this._centerPos[0]-r/2,this._centerPos[1]-r/2,r,r,0,0,this._lensCanvas.width,this._lensCanvas.height);var i=[(e.left+e.right)/2,(e.top+e.bottom)/2];if(this._cursorPos){var a=this._cursorPos[0]-this._centerPos[0],s=this._cursorPos[1]-this._centerPos[1];this._lensCursorDiv.style.marginLeft="".concat(i[0]+a*this._zoomLevel-10,"px"),this._lensCursorDiv.style.marginTop="".concat(i[1]+s*this._zoomLevel-10,"px")}else this._lensCursorDiv.style.marginLeft="".concat(i[0]-10,"px"),this._lensCursorDiv.style.marginTop="".concat(i[1]-10,"px")}}},{key:"zoomFactor",get:function(){return this._zoomFactor},set:function(e){this._zoomFactor=e,this.update()}},{key:"centerPos",get:function(){return this._centerPos},set:function(e){this._centerPos=e,this.update()}},{key:"cursorPos",get:function(){return this._cursorPos},set:function(e){this._cursorPos=e,this.update()}},{key:"snapped",get:function(){return this._snapped},set:function(e){this._snapped=e,e?(this._lensCursorDiv.style.background="greenyellow",this._lensCursorDiv.style.border="2px solid green"):(this._lensCursorDiv.style.background="pink",this._lensCursorDiv.style.border="2px solid red")}},{key:"active",get:function(){return this._active},set:function(e){this._active=e,this._lensContainer.style.visibility=e&&this._visible?"visible":"hidden",e&&this._visible||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=e,this._lensContainer.style.visibility=e&&this._active?"visible":"hidden",e&&this._active||(this._lensCursorDiv.style.marginLeft="-100px",this._lensCursorDiv.style.marginTop="-100px"),this.update()}},{key:"destroy",value:function(){this._destroyed||(this.viewer.scene.off(this._onViewerRendering),this._lensContainer.removeChild(this._lensCanvas),document.body.removeChild(this._lensContainer),this._destroyed=!0)}}]),e}(),K=function(){function e(t,n,r){b(this,e),this.id=r&&r.id?r.id:t,this.viewer=n,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,n.addPlugin(this)}return P(e,[{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){console.log("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"warn",value:function(e){console.warn("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"error",value:function(e){console.error("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.removePlugin(this)}}]),e}(),Y=!0,X=Y?Float64Array:Float32Array,q=new X(16),J=new X(16),Z=new X(4),$={setDoublePrecisionEnabled:function(e){X=(Y=e)?Float64Array:Float32Array},getDoublePrecisionEnabled:function(){return Y},MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId:function(e,t){var n=t.indexOf("#");return n===e.length&&t.startsWith(e)?t.substring(n+1):t},globalizeObjectId:function(e,t){return e+"#"+t},safeInv:function(e){var t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:function(e){return new X(e||2)},vec3:function(e){return new X(e||3)},vec4:function(e){return new X(e||4)},mat3:function(e){return new X(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new X(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},mat4:function(e){return new X(e||16)},mat4ToMat3:function(e,t){},doublesToFloats:function(e,t,n){for(var r=new X(2),i=0,a=e.length;i>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&n]).concat(e[n>>8&255],"-").concat(e[n>>16&15|64]).concat(e[n>>24&255],"-").concat(e[63&r|128]).concat(e[r>>8&255],"-").concat(e[r>>16&255]).concat(e[r>>24&255]).concat(e[255&i]).concat(e[i>>8&255]).concat(e[i>>16&255]).concat(e[i>>24&255])}}(),clamp:function(e,t,n){return Math.max(t,Math.min(n,e))},fmod:function(e,t){if(e1?1:n,Math.acos(n)},vec3FromMat4Scale:function(){var e=new X(3);return function(t,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],n[0]=$.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],n[1]=$.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],n[2]=$.lenVec3(e),n}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var n=0,r=(t=Array.prototype.slice.call(t)).length;n0&&void 0!==arguments[0]?arguments[0]:new X(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},identityMat3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new X(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},isIdentityMat4:function(e){return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]},negateMat4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t},addMat4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n[4]=e[4]+t[4],n[5]=e[5]+t[5],n[6]=e[6]+t[6],n[7]=e[7]+t[7],n[8]=e[8]+t[8],n[9]=e[9]+t[9],n[10]=e[10]+t[10],n[11]=e[11]+t[11],n[12]=e[12]+t[12],n[13]=e[13]+t[13],n[14]=e[14]+t[14],n[15]=e[15]+t[15],n},addMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n[4]=e[4]+t,n[5]=e[5]+t,n[6]=e[6]+t,n[7]=e[7]+t,n[8]=e[8]+t,n[9]=e[9]+t,n[10]=e[10]+t,n[11]=e[11]+t,n[12]=e[12]+t,n[13]=e[13]+t,n[14]=e[14]+t,n[15]=e[15]+t,n},addScalarMat4:function(e,t,n){return $.addMat4Scalar(t,e,n)},subMat4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n[4]=e[4]-t[4],n[5]=e[5]-t[5],n[6]=e[6]-t[6],n[7]=e[7]-t[7],n[8]=e[8]-t[8],n[9]=e[9]-t[9],n[10]=e[10]-t[10],n[11]=e[11]-t[11],n[12]=e[12]-t[12],n[13]=e[13]-t[13],n[14]=e[14]-t[14],n[15]=e[15]-t[15],n},subMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n[4]=e[4]-t,n[5]=e[5]-t,n[6]=e[6]-t,n[7]=e[7]-t,n[8]=e[8]-t,n[9]=e[9]-t,n[10]=e[10]-t,n[11]=e[11]-t,n[12]=e[12]-t,n[13]=e[13]-t,n[14]=e[14]-t,n[15]=e[15]-t,n},subScalarMat4:function(e,t,n){return n||(n=t),n[0]=e-t[0],n[1]=e-t[1],n[2]=e-t[2],n[3]=e-t[3],n[4]=e-t[4],n[5]=e-t[5],n[6]=e-t[6],n[7]=e-t[7],n[8]=e-t[8],n[9]=e-t[9],n[10]=e-t[10],n[11]=e-t[11],n[12]=e-t[12],n[13]=e-t[13],n[14]=e-t[14],n[15]=e-t[15],n},mulMat4:function(e,t,n){n||(n=e);var r=e[0],i=e[1],a=e[2],s=e[3],o=e[4],l=e[5],u=e[6],c=e[7],f=e[8],p=e[9],A=e[10],d=e[11],v=e[12],h=e[13],I=e[14],y=e[15],m=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],L=t[15];return n[0]=m*r+w*o+g*f+T*v,n[1]=m*i+w*l+g*p+T*h,n[2]=m*a+w*u+g*A+T*I,n[3]=m*s+w*c+g*d+T*y,n[4]=E*r+b*o+D*f+P*v,n[5]=E*i+b*l+D*p+P*h,n[6]=E*a+b*u+D*A+P*I,n[7]=E*s+b*c+D*d+P*y,n[8]=R*r+C*o+_*f+B*v,n[9]=R*i+C*l+_*p+B*h,n[10]=R*a+C*u+_*A+B*I,n[11]=R*s+C*c+_*d+B*y,n[12]=O*r+S*o+N*f+L*v,n[13]=O*i+S*l+N*p+L*h,n[14]=O*a+S*u+N*A+L*I,n[15]=O*s+S*c+N*d+L*y,n},mulMat3:function(e,t,n){n||(n=new X(9));var r=e[0],i=e[3],a=e[6],s=e[1],o=e[4],l=e[7],u=e[2],c=e[5],f=e[8],p=t[0],A=t[3],d=t[6],v=t[1],h=t[4],I=t[7],y=t[2],m=t[5],w=t[8];return n[0]=r*p+i*v+a*y,n[3]=r*A+i*h+a*m,n[6]=r*d+i*I+a*w,n[1]=s*p+o*v+l*y,n[4]=s*A+o*h+l*m,n[7]=s*d+o*I+l*w,n[2]=u*p+c*v+f*y,n[5]=u*A+c*h+f*m,n[8]=u*d+c*I+f*w,n},mulMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n[4]=e[4]*t,n[5]=e[5]*t,n[6]=e[6]*t,n[7]=e[7]*t,n[8]=e[8]*t,n[9]=e[9]*t,n[10]=e[10]*t,n[11]=e[11]*t,n[12]=e[12]*t,n[13]=e[13]*t,n[14]=e[14]*t,n[15]=e[15]*t,n},mulMat4v4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=t[0],i=t[1],a=t[2],s=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12]*s,n[1]=e[1]*r+e[5]*i+e[9]*a+e[13]*s,n[2]=e[2]*r+e[6]*i+e[10]*a+e[14]*s,n[3]=e[3]*r+e[7]*i+e[11]*a+e[15]*s,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],a=e[13],s=e[12],o=e[9];if(!t||e===t){var l=e[1],u=e[2],c=e[3],f=e[6],p=e[7],A=e[11];return e[1]=n,e[2]=i,e[3]=s,e[4]=l,e[6]=o,e[7]=a,e[8]=u,e[9]=f,e[11]=r,e[12]=c,e[13]=p,e[14]=A,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=s,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=r,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3:function(e,t){if(t===e){var n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4:function(e){var t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],s=e[5],o=e[6],l=e[7],u=e[8],c=e[9],f=e[10],p=e[11],A=e[12],d=e[13],v=e[14],h=e[15];return A*c*o*i-u*d*o*i-A*s*f*i+a*d*f*i+u*s*v*i-a*c*v*i-A*c*r*l+u*d*r*l+A*n*f*l-t*d*f*l-u*n*v*l+t*c*v*l+A*s*r*p-a*d*r*p-A*n*o*p+t*d*o*p+a*n*v*p-t*s*v*p-u*s*r*h+a*c*r*h+u*n*o*h-t*c*o*h-a*n*f*h+t*s*f*h},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],a=e[3],s=e[4],o=e[5],l=e[6],u=e[7],c=e[8],f=e[9],p=e[10],A=e[11],d=e[12],v=e[13],h=e[14],I=e[15],y=n*o-r*s,m=n*l-i*s,w=n*u-a*s,g=r*l-i*o,T=r*u-a*o,E=i*u-a*l,b=c*v-f*d,D=c*h-p*d,P=c*I-A*d,R=f*h-p*v,C=f*I-A*v,_=p*I-A*h,B=1/(y*_-m*C+w*R+g*P-T*D+E*b);return t[0]=(o*_-l*C+u*R)*B,t[1]=(-r*_+i*C-a*R)*B,t[2]=(v*E-h*T+I*g)*B,t[3]=(-f*E+p*T-A*g)*B,t[4]=(-s*_+l*P-u*D)*B,t[5]=(n*_-i*P+a*D)*B,t[6]=(-d*E+h*w-I*m)*B,t[7]=(c*E-p*w+A*m)*B,t[8]=(s*C-o*P+u*b)*B,t[9]=(-n*C+r*P-a*b)*B,t[10]=(d*T-v*w+I*y)*B,t[11]=(-c*T+f*w-A*y)*B,t[12]=(-s*R+o*D-l*b)*B,t[13]=(n*R-r*D+i*b)*B,t[14]=(-d*g+v*m-h*y)*B,t[15]=(c*g-f*m+p*y)*B,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var n=t||$.identityMat4();return n[12]=e[0],n[13]=e[1],n[14]=e[2],n},translationMat3v:function(e,t){var n=t||$.identityMat3();return n[6]=e[0],n[7]=e[1],n},translationMat4c:(H=new X(3),function(e,t,n,r){return H[0]=e,H[1]=t,H[2]=n,$.translationMat4v(H,r)}),translationMat4s:function(e,t){return $.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return $.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,n,r){var i=r[3];r[0]+=i*e,r[1]+=i*t,r[2]+=i*n;var a=r[7];r[4]+=a*e,r[5]+=a*t,r[6]+=a*n;var s=r[11];r[8]+=s*e,r[9]+=s*t,r[10]+=s*n;var o=r[15];return r[12]+=o*e,r[13]+=o*t,r[14]+=o*n,r},setMat4Translation:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=e[15],n},rotationMat4v:function(e,t,n){var r,i,a,s,o,l,u=$.normalizeVec4([t[0],t[1],t[2],0],[]),c=Math.sin(e),f=Math.cos(e),p=1-f,A=u[0],d=u[1],v=u[2];return r=A*d,i=d*v,a=v*A,s=A*c,o=d*c,l=v*c,(n=n||$.mat4())[0]=p*A*A+f,n[1]=p*r+l,n[2]=p*a-o,n[3]=0,n[4]=p*r-l,n[5]=p*d*d+f,n[6]=p*i+s,n[7]=0,n[8]=p*a+o,n[9]=p*i-s,n[10]=p*v*v+f,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},rotationMat4c:function(e,t,n,r,i){return $.rotationMat4v(e,[t,n,r],i)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.identityMat4();return t[0]=e[0],t[5]=e[1],t[10]=e[2],t},scalingMat3v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new X(3);return function(t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,$.scalingMat4v(e,i)}}(),scaleMat4c:function(e,t,n,r){return r[0]*=e,r[4]*=t,r[8]*=n,r[1]*=e,r[5]*=t,r[9]*=n,r[2]*=e,r[6]*=t,r[10]*=n,r[3]*=e,r[7]*=t,r[11]*=n,r},scaleMat4v:function(e,t){var n=e[0],r=e[1],i=e[2];return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,t},scalingMat4s:function(e){return $.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.mat4(),r=e[0],i=e[1],a=e[2],s=e[3],o=r+r,l=i+i,u=a+a,c=r*o,f=r*l,p=r*u,A=i*l,d=i*u,v=a*u,h=s*o,I=s*l,y=s*u;return n[0]=1-(A+v),n[1]=f+y,n[2]=p-I,n[3]=0,n[4]=f-y,n[5]=1-(c+v),n[6]=d+h,n[7]=0,n[8]=p+I,n[9]=d-h,n[10]=1-(c+A),n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n},mat4ToEuler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=$.clamp,i=e[0],a=e[4],s=e[8],o=e[1],l=e[5],u=e[9],c=e[2],f=e[6],p=e[10];return"XYZ"===t?(n[1]=Math.asin(r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(-u,p),n[2]=Math.atan2(-a,i)):(n[0]=Math.atan2(f,l),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(u,-1,1)),Math.abs(u)<.99999?(n[1]=Math.atan2(s,p),n[2]=Math.atan2(o,l)):(n[1]=Math.atan2(-c,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(f,-1,1)),Math.abs(f)<.99999?(n[1]=Math.atan2(-c,p),n[2]=Math.atan2(-a,l)):(n[1]=0,n[2]=Math.atan2(o,i))):"ZYX"===t?(n[1]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[0]=Math.atan2(f,p),n[2]=Math.atan2(o,i)):(n[0]=0,n[2]=Math.atan2(-a,l))):"YZX"===t?(n[2]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-u,l),n[1]=Math.atan2(-c,i)):(n[0]=0,n[1]=Math.atan2(s,p))):"XZY"===t&&(n[2]=Math.asin(-r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(f,l),n[1]=Math.atan2(s,i)):(n[0]=Math.atan2(-u,p),n[1]=0)),n},composeMat4:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:$.mat4();return $.quaternionToRotationMat4(t,r),$.scaleMat4v(n,r),$.translateMat4v(e,r),r},decomposeMat4:function(){var e=new X(3),t=new X(16);return function(n,r,i,a){e[0]=n[0],e[1]=n[1],e[2]=n[2];var s=$.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var o=$.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var l=$.lenVec3(e);$.determinantMat4(n)<0&&(s=-s),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var u=1/s,c=1/o,f=1/l;return t[0]*=u,t[1]*=u,t[2]*=u,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=f,t[9]*=f,t[10]*=f,$.mat4ToQuaternion(t,i),a[0]=s,a[1]=o,a[2]=l,this}}(),getColMat4:function(e,t){var n=4*t;return[e[n],e[n+1],e[n+2],e[n+3]]},setRowMat4:function(e,t,n){e[t]=n[0],e[t+4]=n[1],e[t+8]=n[2],e[t+12]=n[3]},lookAtMat4v:function(e,t,n,r){r||(r=$.mat4());var i,a,s,o,l,u,c,f,p,A,d=e[0],v=e[1],h=e[2],I=n[0],y=n[1],m=n[2],w=t[0],g=t[1],T=t[2];return d===w&&v===g&&h===T?$.identityMat4():(i=d-w,a=v-g,s=h-T,o=y*(s*=A=1/Math.sqrt(i*i+a*a+s*s))-m*(a*=A),l=m*(i*=A)-I*s,u=I*a-y*i,(A=Math.sqrt(o*o+l*l+u*u))?(o*=A=1/A,l*=A,u*=A):(o=0,l=0,u=0),c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,(A=Math.sqrt(c*c+f*f+p*p))?(c*=A=1/A,f*=A,p*=A):(c=0,f=0,p=0),r[0]=o,r[1]=c,r[2]=i,r[3]=0,r[4]=l,r[5]=f,r[6]=a,r[7]=0,r[8]=u,r[9]=p,r[10]=s,r[11]=0,r[12]=-(o*d+l*v+u*h),r[13]=-(c*d+f*v+p*h),r[14]=-(i*d+a*v+s*h),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,a,s,o,l){return $.lookAtMat4v([e,t,n],[r,i,a],[s,o,l],[])},orthoMat4c:function(e,t,n,r,i,a,s){s||(s=$.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2/l,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=-2/u,s[11]=0,s[12]=-(e+t)/o,s[13]=-(r+n)/l,s[14]=-(a+i)/u,s[15]=1,s},frustumMat4v:function(e,t,n){n||(n=$.mat4());var r=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];$.addVec4(i,r,q),$.subVec4(i,r,J);var a=2*r[2],s=J[0],o=J[1],l=J[2];return n[0]=a/s,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=a/o,n[6]=0,n[7]=0,n[8]=q[0]/s,n[9]=q[1]/o,n[10]=-q[2]/l,n[11]=-1,n[12]=0,n[13]=0,n[14]=-a*i[2]/l,n[15]=0,n},frustumMat4:function(e,t,n,r,i,a,s){s||(s=$.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2*i/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2*i/l,s[6]=0,s[7]=0,s[8]=(t+e)/o,s[9]=(r+n)/l,s[10]=-(a+i)/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i*2/u,s[15]=0,s},perspectiveMat4:function(e,t,n,r,i){var a=[],s=[];return a[2]=n,s[2]=r,s[1]=a[2]*Math.tan(e/2),a[1]=-s[1],s[0]=s[1]*t,a[0]=-s[0],$.frustumMat4v(a,s,i)},compareMat4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]},transformPoint3:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec3(),r=t[0],i=t[1],a=t[2];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12],n[1]=e[1]*r+e[5]*i+e[9]*a+e[13],n[2]=e[2]*r+e[6]*i+e[10]*a+e[14],n},transformPoint4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4();return n[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],n[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],n[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],n[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],n},transformPoints3:function(e,t,n){for(var r,i,a,s,o,l=n||[],u=t.length,c=e[0],f=e[1],p=e[2],A=e[3],d=e[4],v=e[5],h=e[6],I=e[7],y=e[8],m=e[9],w=e[10],g=e[11],T=e[12],E=e[13],b=e[14],D=e[15],P=0;P2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2];e[3];var f=e[4],p=e[5],A=e[6];e[7];var d=e[8],v=e[9],h=e[10];e[11];var I=e[12],y=e[13],m=e[14];for(e[15],n=0;n2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n3&&void 0!==arguments[3]?arguments[3]:e,i=Math.cos(n),a=Math.sin(n),s=e[0]-t[0],o=e[1]-t[1];return r[0]=s*i-o*a+t[0],r[1]=s*a+o*i+t[1],e},rotateVec3X:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Y:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Z:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},projectVec4:function(e,t){var n=1/e[3];return(t=t||$.vec2())[0]=e[0]*n,t[1]=e[1]*n,t},unprojectVec3:(x=new X(16),M=new X(16),F=new X(16),function(e,t,n,r){return this.transformVec3(this.mulMat4(this.inverseMat4(t,x),this.inverseMat4(n,M),F),e,r)}),lerpVec3:function(e,t,n,r,i,a){var s=a||$.vec3(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s},lerpMat4:function(e,t,n,r,i,a){var s=a||$.mat4(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s[3]=r[3]+o*(i[3]-r[3]),s[4]=r[4]+o*(i[4]-r[4]),s[5]=r[5]+o*(i[5]-r[5]),s[6]=r[6]+o*(i[6]-r[6]),s[7]=r[7]+o*(i[7]-r[7]),s[8]=r[8]+o*(i[8]-r[8]),s[9]=r[9]+o*(i[9]-r[9]),s[10]=r[10]+o*(i[10]-r[10]),s[11]=r[11]+o*(i[11]-r[11]),s[12]=r[12]+o*(i[12]-r[12]),s[13]=r[13]+o*(i[13]-r[13]),s[14]=r[14]+o*(i[14]-r[14]),s[15]=r[15]+o*(i[15]-r[15]),s},flatten:function(e){var t,n,r,i,a,s=[];for(t=0,n=e.length;t0&&void 0!==arguments[0]?arguments[0]:$.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=e[0]*$.DEGTORAD/2,i=e[1]*$.DEGTORAD/2,a=e[2]*$.DEGTORAD/2,s=Math.cos(r),o=Math.cos(i),l=Math.cos(a),u=Math.sin(r),c=Math.sin(i),f=Math.sin(a);return"XYZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"YXZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"ZXY"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"ZYX"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"YZX"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l-u*c*f):"XZY"===t&&(n[0]=u*o*l-s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l+u*c*f),n},mat4ToQuaternion:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),r=e[0],i=e[4],a=e[8],s=e[1],o=e[5],l=e[9],u=e[2],c=e[6],f=e[10],p=r+o+f;return p>0?(t=.5/Math.sqrt(p+1),n[3]=.25/t,n[0]=(c-l)*t,n[1]=(a-u)*t,n[2]=(s-i)*t):r>o&&r>f?(t=2*Math.sqrt(1+r-o-f),n[3]=(c-l)/t,n[0]=.25*t,n[1]=(i+s)/t,n[2]=(a+u)/t):o>f?(t=2*Math.sqrt(1+o-r-f),n[3]=(a-u)/t,n[0]=(i+s)/t,n[1]=.25*t,n[2]=(l+c)/t):(t=2*Math.sqrt(1+f-r-o),n[3]=(s-i)/t,n[0]=(a+u)/t,n[1]=(l+c)/t,n[2]=.25*t),n},vec3PairToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=Math.sqrt($.dotVec3(e,e)*$.dotVec3(t,t)),i=r+$.dotVec3(e,t);return i<1e-8*r?(i=0,Math.abs(e[0])>Math.abs(e[2])?(n[0]=-e[1],n[1]=e[0],n[2]=0):(n[0]=0,n[1]=-e[2],n[2]=e[1])):$.cross3Vec3(e,t,n),n[3]=i,$.normalizeQuaternion(n)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),n=e[3]/2,r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},quaternionToEuler:function(){var e=new X(16);return function(t,n,r){return r=r||$.vec3(),$.quaternionToRotationMat4(t,e),$.mat4ToEuler(e,n,r),r}}(),mulQuaternions:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec4(),r=e[0],i=e[1],a=e[2],s=e[3],o=t[0],l=t[1],u=t[2],c=t[3];return n[0]=s*o+r*c+i*u-a*l,n[1]=s*l+i*c+a*o-r*u,n[2]=s*u+a*c+r*l-i*o,n[3]=s*c-r*o-i*l-a*u,n},vec3ApplyQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:$.vec3(),r=t[0],i=t[1],a=t[2],s=e[0],o=e[1],l=e[2],u=e[3],c=u*r+o*a-l*i,f=u*i+l*r-s*a,p=u*a+s*i-o*r,A=-s*r-o*i-l*a;return n[0]=c*u+A*-s+f*-l-p*-o,n[1]=f*u+A*-o+p*-s-c*-l,n[2]=p*u+A*-l+c*-o-f*-s,n},quaternionToMat4:function(e,t){t=$.identityMat4(t);var n=e[0],r=e[1],i=e[2],a=e[3],s=2*n,o=2*r,l=2*i,u=s*a,c=o*a,f=l*a,p=s*n,A=o*n,d=l*n,v=o*r,h=l*r,I=l*i;return t[0]=1-(v+I),t[1]=A+f,t[2]=d-c,t[4]=A-f,t[5]=1-(p+I),t[6]=h+u,t[8]=d+c,t[9]=h-u,t[10]=1-(p+v),t},quaternionToRotationMat4:function(e,t){var n=e[0],r=e[1],i=e[2],a=e[3],s=n+n,o=r+r,l=i+i,u=n*s,c=n*o,f=n*l,p=r*o,A=r*l,d=i*l,v=a*s,h=a*o,I=a*l;return t[0]=1-(p+d),t[4]=c-I,t[8]=f+h,t[1]=c+I,t[5]=1-(u+d),t[9]=A-v,t[2]=f-h,t[6]=A+v,t[10]=1-(u+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=$.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n,t[3]=e[3]/n,t},conjugateQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},inverseQuaternion:function(e,t){return $.normalizeQuaternion($.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec4(),n=(e=$.normalizeQuaternion(e,Z))[3],r=2*Math.acos(n),i=Math.sqrt(1-n*n);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=r,t},AABB3:function(e){return new X(e||6)},AABB2:function(e){return new X(e||4)},OBB3:function(e){return new X(e||32)},OBB2:function(e){return new X(e||16)},Sphere3:function(e,t,n,r){return new X([e,t,n,r])},transformOBB3:function(e,t){var n,r,i,a,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;no?s:o,a[1]+=l>u?l:u,a[2]+=c>f?c:f,Math.abs($.lenVec3(a))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var n=t||$.vec3();return n[0]=(e[0]+e[3])/2,n[1]=(e[1]+e[4])/2,n[2]=(e[2]+e[5])/2,n},getAABB2Center:function(e,t){var n=t||$.vec2();return n[0]=(e[2]+e[0])/2,n[1]=(e[3]+e[1])/2,n},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:$.AABB3();return e[0]=$.MAX_DOUBLE,e[1]=$.MAX_DOUBLE,e[2]=$.MAX_DOUBLE,e[3]=$.MIN_DOUBLE,e[4]=$.MIN_DOUBLE,e[5]=$.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.OBB3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t},positions3ToAABB3:function(){var e=new X(3);return function(t,n,r){n=n||$.AABB3();for(var i,a,s,o=$.MAX_DOUBLE,l=$.MAX_DOUBLE,u=$.MAX_DOUBLE,c=$.MIN_DOUBLE,f=$.MIN_DOUBLE,p=$.MIN_DOUBLE,A=0,d=t.length;Ac&&(c=i),a>f&&(f=a),s>p&&(p=s);return n[0]=o,n[1]=l,n[2]=u,n[3]=c,n[4]=f,n[5]=p,n}}(),OBB3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB3(),a=$.MAX_DOUBLE,s=$.MAX_DOUBLE,o=$.MAX_DOUBLE,l=$.MIN_DOUBLE,u=$.MIN_DOUBLE,c=$.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB3(),a=$.MAX_DOUBLE,s=$.MAX_DOUBLE,o=$.MAX_DOUBLE,l=$.MIN_DOUBLE,u=$.MIN_DOUBLE,c=$.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToSphere3:function(){var e=new X(3);return function(t,n){n=n||$.vec4();var r,i=0,a=0,s=0,o=t.length;for(r=0;ru&&(u=l);return n[3]=u,n}}(),positions3ToSphere3:function(){var e=new X(3),t=new X(3);return function(n,r){r=r||$.vec4();var i,a=0,s=0,o=0,l=n.length,u=0;for(i=0;iu&&(u=c);return r[3]=u,r}}(),OBB3ToSphere3:function(){var e=new X(3),t=new X(3);return function(n,r){r=r||$.vec4();var i,a=0,s=0,o=0,l=n.length,u=l/4;for(i=0;if&&(f=c);return r[3]=f,r}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},getPositionsCenter:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec3(),n=0,r=0,i=0,a=0,s=e.length;at[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]n&&(e[0]=n),e[1]>r&&(e[1]=r),e[2]>i&&(e[2]=i),e[3]0&&void 0!==arguments[0]?arguments[0]:$.AABB2();return e[0]=$.MAX_DOUBLE,e[1]=$.MAX_DOUBLE,e[2]=$.MIN_DOUBLE,e[3]=$.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(r=e[0]*n[0],i=e[0]*n[3]):(r=e[0]*n[3],i=e[0]*n[0]),e[1]>0?(r+=e[1]*n[1],i+=e[1]*n[4]):(r+=e[1]*n[4],i+=e[1]*n[1]),e[2]>0?(r+=e[2]*n[2],i+=e[2]*n[5]):(r+=e[2]*n[5],i+=e[2]*n[2]),r<=-t&&i<=-t?-1:r>=-t&&i>=-t?1:0},OBB3ToAABB2:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.AABB2(),a=$.MAX_DOUBLE,s=$.MAX_DOUBLE,o=$.MIN_DOUBLE,l=$.MIN_DOUBLE,u=0,c=e.length;uo&&(o=t),n>l&&(l=n);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i},expandAABB2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]3&&void 0!==arguments[3]?arguments[3]:e,i=.5*(e[0]+1),a=.5*(e[1]+1),s=.5*(e[2]+1),o=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(o*n),r[2]=Math.floor(s*t),r[3]=n-Math.floor(a*n),r},tangentQuadraticBezier:function(e,t,n,r){return 2*(1-e)*(n-t)+2*e*(r-n)},tangentQuadraticBezier3:function(e,t,n,r,i){return-3*t*(1-e)*(1-e)+3*n*(1-e)*(1-e)-6*e*n*(1-e)+6*e*r*(1-e)-3*e*e*r+3*e*e*i},tangentSpline:function(e){return 6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e)},catmullRomInterpolate:function(e,t,n,r,i){var a=.5*(n-e),s=.5*(r-t),o=i*i;return(2*t-2*n+a+s)*(i*o)+(-3*t+3*n-2*a-s)*o+a*i+t},b2p0:function(e,t){var n=1-e;return n*n*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,n,r){return this.b2p0(e,t)+this.b2p1(e,n)+this.b2p2(e,r)},b3p0:function(e,t){var n=1-e;return n*n*n*t},b3p1:function(e,t){var n=1-e;return 3*n*n*e*t},b3p2:function(e,t){return 3*(1-e)*e*e*t},b3p3:function(e,t){return e*e*e*t},b3:function(e,t,n,r,i){return this.b3p0(e,t)+this.b3p1(e,n)+this.b3p2(e,r)+this.b3p3(e,i)},triangleNormal:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:$.vec3(),i=t[0]-e[0],a=t[1]-e[1],s=t[2]-e[2],o=n[0]-e[0],l=n[1]-e[1],u=n[2]-e[2],c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,A=Math.sqrt(c*c+f*f+p*p);return 0===A?(r[0]=0,r[1]=0,r[2]=0):(r[0]=c/A,r[1]=f/A,r[2]=p/A),r},rayTriangleIntersect:function(){var e=new X(3),t=new X(3),n=new X(3),r=new X(3),i=new X(3);return function(a,s,o,l,u,c){c=c||$.vec3();var f=$.subVec3(l,o,e),p=$.subVec3(u,o,t),A=$.cross3Vec3(s,p,n),d=$.dotVec3(f,A);if(d<1e-6)return null;var v=$.subVec3(a,o,r),h=$.dotVec3(v,A);if(h<0||h>d)return null;var I=$.cross3Vec3(v,f,i),y=$.dotVec3(s,I);if(y<0||h+y>d)return null;var m=$.dotVec3(p,I)/d;return c[0]=a[0]+m*s[0],c[1]=a[1]+m*s[1],c[2]=a[2]+m*s[2],c}}(),rayPlaneIntersect:function(){var e=new X(3),t=new X(3),n=new X(3),r=new X(3);return function(i,a,s,o,l,u){u=u||$.vec3(),a=$.normalizeVec3(a,e);var c=$.subVec3(o,s,t),f=$.subVec3(l,s,n),p=$.cross3Vec3(c,f,r);$.normalizeVec3(p,p);var A=-$.dotVec3(s,p),d=-($.dotVec3(i,p)+A)/$.dotVec3(a,p);return u[0]=i[0]+d*a[0],u[1]=i[1]+d*a[1],u[2]=i[2]+d*a[2],u}}(),cartesianToBarycentric:function(){var e=new X(3),t=new X(3),n=new X(3);return function(r,i,a,s,o){var l=$.subVec3(s,i,e),u=$.subVec3(a,i,t),c=$.subVec3(r,i,n),f=$.dotVec3(l,l),p=$.dotVec3(l,u),A=$.dotVec3(l,c),d=$.dotVec3(u,u),v=$.dotVec3(u,c),h=f*d-p*p;if(0===h)return null;var I=1/h,y=(d*A-p*v)*I,m=(f*v-p*A)*I;return o[0]=1-y-m,o[1]=m,o[2]=y,o}}(),barycentricInsideTriangle:function(e){var t=e[1],n=e[2];return n>=0&&t>=0&&n+t<1},barycentricToCartesian:function(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:$.vec3(),a=e[0],s=e[1],o=e[2];return i[0]=t[0]*a+n[0]*s+r[0]*o,i[1]=t[1]*a+n[1]*s+r[1]*o,i[2]=t[2]*a+n[2]*s+r[2]*o,i},mergeVertices:function(e,t,n,r){var i,a,s,o,l,u,c={},f=[],p=[],A=t?[]:null,d=n?[]:null,v=[],h=Math.pow(10,4),I=0;for(l=0,u=e.length;l>24&255,s=f>>16&255,a=f>>8&255,i=255&f,r=3*t[d],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+1],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+2],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,f++;return{positions:u,colors:c}},faceToVertexNormals:function(e,t){var n,r,i,a,s,o,l,u,c,f,p,A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},d=A.smoothNormalsAngleThreshold||20,v={},h=[],I={},y=4,m=Math.pow(10,y);for(l=0,c=e.length;ll[3]&&(l[3]=i[p]),i[p+1]l[4]&&(l[4]=i[p+1]),i[p+2]l[5]&&(l[5]=i[p+2])}if(n.length<20||a>10)return u.triangles=n,u.leaf=!0,u;e[0]=l[3]-l[0],e[1]=l[4]-l[1],e[2]=l[5]-l[2];var A=0;e[1]>e[A]&&(A=1),e[2]>e[A]&&(A=2),u.splitDim=A;var d=(l[A]+l[A+3])/2,v=new Array(n.length),h=0,I=new Array(n.length),y=0;for(s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t},octDecodeVec2s:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t}};$.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=$.vec3(),c=$.vec3(),f=$.vec3(),p=$.vec3(),A=$.vec3(),d=$.vec3(),v=$.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var ee=function(){function e(){b(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return P(e,[{key:"length",get:function(){return this._length}},{key:"shift",value:function(){if(this._index>=this._headLength){var e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}var t=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,t}},{key:"push",value:function(e){return this._length++,this._tail.push(e),this}},{key:"unshift",value:function(e){return this._head[--this._index]=e,this._length++,this}}]),e}(),te={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var ne=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],n=e[0].charCodeAt(0),r=n+e[1],i=n;i0&&void 0!==arguments[0]?arguments[0]:-1,r=(new Date).getTime(),i=0;ue.length>0&&(n<0||r0&&ae>0){var n=1e3/ae;Ae+=n,fe.push(n),fe.length>=30&&(Ae-=fe.shift()),te.frame.fps=Math.round(Ae/fe.length)}!function(e){var t=de.runTasks(e+10),n=de.getNumTasks();te.frame.tasksRun=t,te.frame.tasksScheduled=n,te.frame.tasksBudget=10}(t),function(e){for(var t in ce.time=e,de.scenes)if(de.scenes.hasOwnProperty(t)){var n=de.scenes[t];ce.sceneId=t,ce.startTime=n.startTime,ce.deltaTime=null!=ce.prevTime?ce.time-ce.prevTime:0,n.fire("tick",ce,!0)}ce.prevTime=e}(t),function(){var e,t,n,r,i,a=de.scenes,s=!1;for(i in a)a.hasOwnProperty(i)&&(e=a[i],(t=oe[i])||(t=oe[i]={}),n=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==n&&(t.ticksPerOcclusionTest=n,t.renderCountdown=n),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=n),r=e.ticksPerRender,t.ticksPerRender!==r&&(t.ticksPerRender=r,t.renderCountdown=r),0==--t.renderCountdown&&(e.render(s),t.renderCountdown=r))}(),pe=t,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(e):requestAnimationFrame(e)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(ve):requestAnimationFrame(ve);var he=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=n.viewer;else{if("Scene"===t.type)this.scene=t;else{if(!(t instanceof e))throw"Invalid param: owner must be a Component";this.scene=t.scene}this._owner=t}this._dontClear=!!n.dontClear,this._renderer=this.scene._renderer,this.meta=n.meta||{},this.id=n.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,t&&t._own(this)}return P(e,[{key:"type",get:function(){return"Component"}},{key:"isComponent",get:function(){return!0}},{key:"glRedraw",value:function(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}},{key:"glResort",value:function(){this._renderer&&this._renderer.needStateSort()}},{key:"owner",get:function(){return this._owner}},{key:"isType",value:function(e){return this.type===e}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}},{key:"_message",value:function(e){return" ["+this.type+" "+se.inQuotes(this.id)+"]: "+e}},{key:"warn",value:function(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}},{key:"error",value:function(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}},{key:"_attach",value:function(e){var t=e.name;if(t){var n=e.component,r=e.sceneDefault,i=e.sceneSingleton,a=e.type,s=e.on,o=!1!==e.recompiles;if(n&&(se.isNumeric(n)||se.isString(n))){var l=n;if(!(n=this.scene.components[l]))return void this.error("Component not found: "+se.inQuotes(l))}if(!n)if(!0===i){var u=this.scene.types[a];for(var c in u)if(u.hasOwnProperty){n=u[c];break}if(!n)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===r&&!(n=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(n){if(n.scene.id!==this.scene.id)return void this.error("Not in same scene: "+n.type+" "+se.inQuotes(n.id));if(a&&!n.isType(a))return void this.error("Expected a "+a+" type or subtype: "+n.type+" "+se.inQuotes(n.id))}this._attachments||(this._attachments={});var f,p,A,d=this._attached[t];if(d){if(n&&d.id===n.id)return;var v=this._attachments[d.id];for(p=0,A=(f=v.subs).length;p3&&void 0!==arguments[3]?arguments[3]:1e3,i=$.getPositionsCenter(e,Ie),a=Math.round(i[0]/r)*r,s=Math.round(i[1]/r)*r,o=Math.round(i[2]/r)*r;n[0]=a,n[1]=s,n[2]=o;var l=0!==n[0]||0!==n[1]||0!==n[2];if(l)for(var u=0,c=e.length;u0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,n=this.meshes[0]._colorize[3],r=255;if(t){if(e<0?e=0:e>1&&(e=1),n===(r=Math.floor(255*e)))return}else if(n===(r=255))return;for(var i=0,a=this.meshes.length;i1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._color=r.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=r.thickness||1,this._thicknessClickable=r.thicknessClickable||6;var i=this._wire,a=i.style;a.border="solid "+this._thickness+"px "+this._color,a.position="absolute",a["z-index"]=void 0===r.zIndex?"2000001":r.zIndex,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._wireClickable,o=s.style;o.border="solid "+this._thicknessClickable+"px "+this._color,o.position="absolute",o["z-index"]=void 0===r.zIndex?"2000002":r.zIndex+1,o.width="0px",o.height="0px",o.visibility="visible",o.top="0px",o.left="0px",o["-webkit-transform-origin"]="0 0",o["-moz-transform-origin"]="0 0",o["-ms-transform-origin"]="0 0",o["-o-transform-origin"]="0 0",o["transform-origin"]="0 0",o["-webkit-transform"]="rotate(0deg)",o["-moz-transform"]="rotate(0deg)",o["-ms-transform"]="rotate(0deg)",o["-o-transform"]="rotate(0deg)",o.transform="rotate(0deg)",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}return P(e,[{key:"_visible",get:function(){return"visible"===this._wire.style.visibility}},{key:"_update",value:function(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,n=this._wire.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)";var r=this._wireClickable.style;r.width=Math.round(e)+"px",r.left=Math.round(this._x1)+"px",r.top=Math.round(this._y1)+"px",r["-webkit-transform"]="rotate("+t+"deg)",r["-moz-transform"]="rotate("+t+"deg)",r["-ms-transform"]="rotate("+t+"deg)",r["-o-transform"]="rotate("+t+"deg)",r.transform="rotate("+t+"deg)"}},{key:"setStartAndEnd",value:function(e,t,n,r){this._x1=e,this._y1=t,this._x2=n,this._y2=r,this._update()}},{key:"setColor",value:function(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}},{key:"setOpacity",value:function(e){this._wire.style.opacity=e}},{key:"setVisible",value:function(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}},{key:"setClickable",value:function(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}},{key:"destroy",value:function(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}]),e}(),Ge=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var i=this._dot,a=i.style;a["border-radius"]="25px",a.border="solid 2px white",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"40000005":r.zIndex,a.width="8px",a.height="8px",a.visibility=!1!==r.visible?"visible":"hidden",a.top="0px",a.left="0px",a["box-shadow"]="0 2px 5px 0 #182A3D;",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._dotClickable,o=s.style;o["border-radius"]="35px",o.border="solid 10px white",o.position="absolute",o["z-index"]=void 0===r.zIndex?"40000007":r.zIndex+1,o.width="8px",o.height="8px",o.visibility="visible",o.top="0px",o.left="0px",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.borderColor)}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._dot.style;n.left=Math.round(e)-4+"px",n.top=Math.round(t)-4+"px";var r=this._dotClickable.style;r.left=Math.round(e)-9+"px",r.top=Math.round(t)-9+"px"}},{key:"setFillColor",value:function(e){this._dot.style.background=e||"lightgreen"}},{key:"setBorderColor",value:function(e){this._dot.style.border="solid 2px"+(e||"black")}},{key:"setOpacity",value:function(e){this._dot.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}},{key:"setClickable",value:function(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}},{key:"destroy",value:function(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}]),e}(),ke=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-label-highlighted",this._prefix=r.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var i=this._label,a=i.style;a["border-radius"]="5px",a.color="white",a.padding="4px",a.border="solid 1px",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"5000005":r.zIndex,a.width="auto",a.height="auto",a.visibility="visible",a.top="0px",a.left="0px",a["pointer-events"]="all",a.opacity=1,r.onContextMenu,i.innerText="",t.appendChild(i),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.fillColor),this.setText(r.text),r.onMouseOver&&i.addEventListener("mouseover",(function(e){r.onMouseOver(e,n),e.preventDefault()})),r.onMouseLeave&&i.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n),e.preventDefault()})),r.onMouseWheel&&i.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&i.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()}))}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._label.style;n.left=Math.round(e)-20+"px",n.top=Math.round(t)-12+"px"}},{key:"setPosOnWire",value:function(e,t,n,r){var i=e+.5*(n-e),a=t+.5*(r-t),s=this._label.style;s.left=Math.round(i)-20+"px",s.top=Math.round(a)-12+"px"}},{key:"setPosBetweenWires",value:function(e,t,n,r,i,a){var s=(e+n+i)/3,o=(t+r+a)/3,l=this._label.style;l.left=Math.round(s)-20+"px",l.top=Math.round(o)-12+"px"}},{key:"setText",value:function(e){this._label.innerHTML=this._prefix+(e||"")}},{key:"setFillColor",value:function(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}},{key:"setBorderColor",value:function(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}},{key:"setOpacity",value:function(e){this._label.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}},{key:"setClickable",value:function(e){this._label.style["pointer-events"]=e?"all":"none"}},{key:"destroy",value:function(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}]),e}(),je=$.vec3(),Ve=$.vec3(),Qe=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._color=i.color||e.defaultColor;var a=r.plugin.viewer.scene;r._originMarker=new He(a,i.origin),r._cornerMarker=new He(a,i.corner),r._targetMarker=new He(a,i.target),r._originWorld=$.vec3(),r._cornerWorld=$.vec3(),r._targetWorld=$.vec3(),r._wp=new Float64Array(12),r._vp=new Float64Array(12),r._pp=new Float64Array(12),r._cp=new Int16Array(6);var s=i.onMouseOver?function(e){i.onMouseOver(e,g(r))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,g(r))}:null,l=i.onContextMenu?function(e){i.onContextMenu(e,g(r))}:null,u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new Ge(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._cornerDot=new Ge(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetDot=new Ge(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._originWire=new Ue(r._container,{color:r._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetWire=new Ue(r._container,{color:r._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._angleLabel=new ke(r._container,{fillColor:r._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._visible=!1,r._originVisible=!1,r._cornerVisible=!1,r._targetVisible=!1,r._originWireVisible=!1,r._targetWireVisible=!1,r._angleVisible=!1,r._labelsVisible=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._cornerMarker.on("worldPos",(function(e){r._cornerWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.cornerVisible=i.cornerVisible,r.targetVisible=i.targetVisible,r.originWireVisible=i.originWireVisible,r.targetWireVisible=i.targetWireVisible,r.angleVisible=i.angleVisible,r.labelsVisible=i.labelsVisible,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&($.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){var t=-.3,n=this._originMarker.viewPos[2],r=this._cornerMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(n>t||r>t||i>t)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);$.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var a=this._pp,s=this._cp,o=e.canvas.canvas.getBoundingClientRect(),l=this._container.getBoundingClientRect(),u=o.top-l.top,c=o.left-l.left,f=e.canvas.boundary,p=f[2],A=f[3],d=0,v=0,h=a.length;v0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return P(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var n=this._messages[this._locale];if(!n)return null;var r=ze(e,n);return r?t?Ke(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=ze(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=Ke(i,[t]),n&&(i=Ke(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new G),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function ze(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,a=n.length;r&&i1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var Ye=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).t=i.t,r}return P(n,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),a=this.getPoint(r),s=$.subVec3(a,i,[]);return $.normalizeVec3(s,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,n,r=[],i=this.getPoint(0),a=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),a+=$.lenVec3($.subVec3(t,i,[])),r.push(a),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,a=r.length;n=t||e*r[a-1];for(var s,o=0,l=a-1;o<=l;)if((s=r[i=Math.floor(o+(l-o)/2)]-n)<0)o=i+1;else{if(!(s>0)){l=i;break}l=i-1}if(r[i=l]===n)return i/(a-1);var u=r[i];return(i+(n-u)/(r[i+1]-u))/(a-1)}}]),n}(),Xe=function(e){I(n,Ye);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return P(n,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var n=(t.length-1)*e,r=Math.floor(n),i=n-r,a=t[0===r?r:r-1],s=t[r],o=t[r>t.length-2?t.length-1:r+1],l=t[r>t.length-3?t.length-1:r+2],u=$.vec3();return u[0]=$.catmullRomInterpolate(a[0],s[0],o[0],l[0],i),u[1]=$.catmullRomInterpolate(a[1],s[1],o[1],l[1],i),u[2]=$.catmullRomInterpolate(a[2],s[2],o[2],l[2],i),u}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),n}(),qe=$.vec3(),Je=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new Xe(g(r)),r._lookCurve=new Xe(g(r)),r._upCurve=new Xe(g(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return P(n,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n1?1:e,t.eye=this._eyeCurve.getPoint(e,qe),t.look=this._lookCurve.getPoint(e,qe),t.up=this._upCurve.getPoint(e,qe)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=$.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,a=this._frames.length;i1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._look1=$.vec3(),r._eye1=$.vec3(),r._up1=$.vec3(),r._look2=$.vec3(),r._eye2=$.vec3(),r._up2=$.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return P(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=n;var r,i,a,s,o,l=this.scene.camera,u=!!e.projection&&e.projection!==l.projection;if(this._eye1[0]=l.eye[0],this._eye1[1]=l.eye[1],this._eye1[2]=l.eye[2],this._look1[0]=l.look[0],this._look1[1]=l.look[1],this._look1[2]=l.look[2],this._up1[0]=l.up[0],this._up1[1]=l.up[1],this._up1[2]=l.up[2],this._orthoScale1=l.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,a=e.look,s=e.up;else if(e.eye)i=e.eye;else if(e.look)a=e.look;else{var c=e;if((se.isNumeric(c)||se.isString(c))&&(o=c,!(c=this.scene.components[o])))return this.error("Component not found: "+se.inQuotes(o)),void(t&&(n?t.call(n):t()));u||(r=c.aabb||this.scene.aabb)}var f=e.poi;if(r){if(r[3]=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?($.subVec3(i.eye,i.look,nt),i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,et),i.look=$.subVec3(et,nt,$e)):this._flyingLook&&(i.look=$.lerpVec3(r,0,1,this._look1,this._look2,$e),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,tt)):this._flyingEyeLookUp&&(i.eye=$.lerpVec3(r,0,1,this._eye1,this._eye2,et),i.look=$.lerpVec3(r,0,1,this._look1,this._look2,$e),i.up=$.lerpVec3(r,0,1,this._up1,this._up2,tt)),this._projection2){var a="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=$.lerpMat4(a,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();de.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=e?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),v(T(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),it=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new rt(g(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,g(r)),r}return P(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),a=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==a)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*a,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*a*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=n.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();it.STOPPED=0,it.SCRUBBING=1,it.PLAYING=2,it.PLAYING_TO=3;var at=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),r=t.call(this,e,i),te.memory.meshes++,r}return P(n,[{key:"type",get:function(){return"Geometry"}},{key:"isGeometry",get:function(){return!0}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),te.memory.meshes--}}]),n}(),st=new G({}),ot=function(){function e(t){for(var n in b(this,e),this.id=st.addItem({}),t)t.hasOwnProperty(n)&&(this[n]=t[n])}return P(e,[{key:"destroy",value:function(){st.removeItem(this.id)}}]),e}(),lt=function(){function e(t,n,r,i,a,s,o,l,u){switch(b(this,e),this._gl=t,this.type=n,this.allocated=!1,r.constructor){case Uint8Array:this.itemType=t.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=t.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=t.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=t.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=t.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=t.INT,this.itemByteSize=4;break;default:this.itemType=t.FLOAT,this.itemByteSize=4}this.usage=s,this.length=0,this.dataLength=i,this.numItems=0,this.itemSize=a,this.normalized=!!o,this.stride=l||0,this.offset=u||0,this._allocate(r)}return P(e,[{key:"_allocate",value:function(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}},{key:"setData",value:function(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}},{key:"bind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}},{key:"unbind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,null)}},{key:"destroy",value:function(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}]),e}(),ut=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=$.vec3(),c=$.vec3(),f=$.vec3(),p=$.vec3(),A=$.vec3(),d=$.vec3(),v=$.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var ct=function(){var e=$.mat4(),t=$.mat4();return function(n,r){r=r||$.mat4();var i=n[0],a=n[1],s=n[2],o=n[3]-i,l=n[4]-a,u=n[5]-s,c=65535;return $.identityMat4(e),$.translationMat4v(n,e),$.identityMat4(t),$.scalingMat4v([o/c,l/c,u/c],t),$.mulMat4(e,t,r),r}}(),ft=function(){var e=$.mat4(),t=$.mat4();return function(n,r,i){var a,s=new Uint16Array(n.length),o=new Float32Array([i[0]!==r[0]?65535/(i[0]-r[0]):0,i[1]!==r[1]?65535/(i[1]-r[1]):0,i[2]!==r[2]?65535/(i[2]-r[2]):0]);for(a=0;a=0?1:-1),o=(1-Math.abs(i))*(a>=0?1:-1);i=s,a=o}return new Int8Array([Math[n](127.5*i+(i<0?-1:0)),Math[r](127.5*a+(a<0?-1:0))])}function dt(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}function vt(e,t,n){return e[t]*n[0]+e[t+1]*n[1]+e[t+2]*n[2]}var ht={getPositionsBounds:function(e){var t,n,r=new Float32Array(3),i=new Float32Array(3);for(t=0;t<3;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:e;return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n[3]=e[3]*t[0]+t[12],n[4]=e[4]*t[5]+t[13],n[5]=e[5]*t[10]+t[14],n},getUVBounds:function(e){var t,n,r=new Float32Array(2),i=new Float32Array(2);for(t=0;t<2;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;ri&&(n=t,i=r),(r=vt(e,s,dt(t=At(e,s,"floor","ceil"))))>i&&(n=t,i=r),(r=vt(e,s,dt(t=At(e,s,"ceil","ceil"))))>i&&(n=t,i=r),a[s]=n[0],a[s+1]=n[1];return a},decompressNormals:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t},decompressNormal:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t}},It=te.memory,yt=$.AABB3(),mt=function(e){I(n,at);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._state=new ot({compressGeometry:!!i.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._edgeIndicesBuf=null,r._pickTrianglePositionsBuf=null,r._pickTriangleColorsBuf=null,r._aabbDirty=!0,r._boundingSphere=!0,r._aabb=null,r._aabbDirty=!0,r._obb=null,r._obbDirty=!0;var a=r._state,s=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":a.primitive=s.POINTS,a.primitiveName=i.primitive;break;case"lines":a.primitive=s.LINES,a.primitiveName=i.primitive;break;case"line-loop":a.primitive=s.LINE_LOOP,a.primitiveName=i.primitive;break;case"line-strip":a.primitive=s.LINE_STRIP,a.primitiveName=i.primitive;break;case"triangles":a.primitive=s.TRIANGLES,a.primitiveName=i.primitive;break;case"triangle-strip":a.primitive=s.TRIANGLE_STRIP,a.primitiveName=i.primitive;break;case"triangle-fan":a.primitive=s.TRIANGLE_FAN,a.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),a.primitive=s.TRIANGLES,a.primitiveName=i.primitive}if(i.positions)if(r._state.compressGeometry){var o=ht.getPositionsBounds(i.positions),l=ht.compressPositions(i.positions,o.min,o.max);a.positions=l.quantized,a.positionsDecodeMatrix=l.decodeMatrix}else a.positions=i.positions.constructor===Float32Array?i.positions:new Float32Array(i.positions);if(i.colors&&(a.colors=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors)),i.uv)if(r._state.compressGeometry){var u=ht.getUVBounds(i.uv),c=ht.compressUVs(i.uv,u.min,u.max);a.uv=c.quantized,a.uvDecodeMatrix=c.decodeMatrix}else a.uv=i.uv.constructor===Float32Array?i.uv:new Float32Array(i.uv);return i.normals&&(r._state.compressGeometry?a.normals=ht.compressNormals(i.normals):a.normals=i.normals.constructor===Float32Array?i.normals:new Float32Array(i.normals)),i.indices&&(a.indices=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3)),r._buildHash(),It.meshes++,r._buildVBOs(),r}return P(n,[{key:"type",get:function(){return"ReadableGeometry"}},{key:"isReadableGeometry",get:function(){return!0}},{key:"_buildVBOs",value:function(){var e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),It.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new lt(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),It.positions+=e.positionsBuf.numItems),e.normals){var n=e.compressGeometry;e.normalsBuf=new lt(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,n),It.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new lt(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),It.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new lt(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),It.uvs+=e.uvBuf.numItems)}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}},{key:"_getPickTrianglePositions",value:function(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}},{key:"_getPickTriangleColors",value:function(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}},{key:"_buildEdgeIndices",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=ut(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,n,n.length,1,t.STATIC_DRAW),It.indices+=this._edgeIndicesBuf.numItems}}},{key:"_buildPickTriangleVBOs",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=$.buildPickTriangles(e.positions,e.indices,e.compressGeometry),r=n.positions,i=n.colors;this._pickTrianglePositionsBuf=new lt(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new lt(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),It.positions+=this._pickTrianglePositionsBuf.numItems,It.colors+=this._pickTriangleColorsBuf.numItems}}},{key:"_buildPickVertexVBOs",value:function(){}},{key:"_webglContextLost",value:function(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}},{key:"_webglContextRestored",value:function(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"compressGeometry",get:function(){return this._state.compressGeometry}},{key:"positions",get:function(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),ht.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null},set:function(e){var t=this._state,n=t.positions;if(n)if(n.length===e.length){if(this._state.compressGeometry){var r=ht.getPositionsBounds(e),i=ht.compressPositions(e,r.min,r.max);e=i.quantized,t.positionsDecodeMatrix=i.decodeMatrix}n.set(e),t.positionsBuf&&t.positionsBuf.setData(n),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}},{key:"normals",get:function(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){var e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),ht.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry normals - quantized geometry is immutable");else{var t=this._state,n=t.normals;n?n.length===e.length?(n.set(e),t.normalsBuf&&t.normalsBuf.setData(n),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}}},{key:"uv",get:function(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),ht.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry UVs - quantized geometry is immutable");else{var t=this._state,n=t.uv;n?n.length===e.length?(n.set(e),t.uvBuf&&t.uvBuf.setData(n),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}}},{key:"colors",get:function(){return this._state.colors},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry colors - quantized geometry is immutable");else{var t=this._state,n=t.colors;n?n.length===e.length?(n.set(e),t.colorsBuf&&t.colorsBuf.setData(n),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}}},{key:"indices",get:function(){return this._state.indices}},{key:"aabb",get:function(){return this._aabbDirty&&(this._aabb||(this._aabb=$.AABB3()),$.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}},{key:"obb",get:function(){return this._obbDirty&&(this._obb||(this._obb=$.OBB3()),$.positions3ToAABB3(this._state.positions,yt,this._state.positionsDecodeMatrix),$.AABB3ToOBB3(yt,this._obb),this._obbDirty=!1),this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_setAABBDirty",value:function(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),It.meshes--}}]),n}(),wt=te.memory,gt=$.AABB3(),Tt=function(e){I(n,at);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._state=new ot({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._aabb=null,r._obb=$.OBB3();var a,s=r._state,o=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":s.primitive=o.POINTS,s.primitiveName=i.primitive;break;case"lines":s.primitive=o.LINES,s.primitiveName=i.primitive;break;case"line-loop":s.primitive=o.LINE_LOOP,s.primitiveName=i.primitive;break;case"line-strip":s.primitive=o.LINE_STRIP,s.primitiveName=i.primitive;break;case"triangles":s.primitive=o.TRIANGLES,s.primitiveName=i.primitive;break;case"triangle-strip":s.primitive=o.TRIANGLE_STRIP,s.primitiveName=i.primitive;break;case"triangle-fan":s.primitive=o.TRIANGLE_FAN,s.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=o.TRIANGLES,s.primitiveName=i.primitive}if(!i.positions)return r.error("Config expected: positions"),w(r);if(!i.indices)return r.error("Config expected: indices"),w(r);var l=i.positionsDecodeMatrix;if(l);else{var u=ht.getPositionsBounds(i.positions),c=ht.compressPositions(i.positions,u.min,u.max);a=c.quantized,s.positionsDecodeMatrix=c.decodeMatrix,s.positionsBuf=new lt(o,o.ARRAY_BUFFER,a,a.length,3,o.STATIC_DRAW),wt.positions+=s.positionsBuf.numItems,$.positions3ToAABB3(i.positions,r._aabb),$.positions3ToAABB3(a,gt,s.positionsDecodeMatrix),$.AABB3ToOBB3(gt,r._obb)}if(i.colors){var f=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors);s.colorsBuf=new lt(o,o.ARRAY_BUFFER,f,f.length,4,o.STATIC_DRAW),wt.colors+=s.colorsBuf.numItems}if(i.uv){var p=ht.getUVBounds(i.uv),A=ht.compressUVs(i.uv,p.min,p.max),d=A.quantized;s.uvDecodeMatrix=A.decodeMatrix,s.uvBuf=new lt(o,o.ARRAY_BUFFER,d,d.length,2,o.STATIC_DRAW),wt.uvs+=s.uvBuf.numItems}if(i.normals){var v=ht.compressNormals(i.normals),h=s.compressGeometry;s.normalsBuf=new lt(o,o.ARRAY_BUFFER,v,v.length,3,o.STATIC_DRAW,h),wt.normals+=s.normalsBuf.numItems}var I=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices);s.indicesBuf=new lt(o,o.ELEMENT_ARRAY_BUFFER,I,I.length,1,o.STATIC_DRAW),wt.indices+=s.indicesBuf.numItems;var y=ut(a,I,s.positionsDecodeMatrix,r._edgeThreshold);return r._edgeIndicesBuf=new lt(o,o.ELEMENT_ARRAY_BUFFER,y,y.length,1,o.STATIC_DRAW),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3),r._buildHash(),wt.meshes++,r}return P(n,[{key:"type",get:function(){return"VBOGeometry"}},{key:"isVBOGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"aabb",get:function(){return this._aabb}},{key:"obb",get:function(){return this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),wt.meshes--}}]),n}(),Et={};function bt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("load3DSGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,se.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,r());var a=Et.parse.from3DS(e).edit.objects[0].mesh,s=a.vertices,o=a.uvt,l=a.indices;i.processes--,n(se.apply(t,{primitive:"triangles",positions:s,normals:null,uv:o,indices:l}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,r()}))}))}function Dt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,se.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,r());for(var a=Et.parse.fromOBJ(e),s=Et.edit.unwrap(a.i_verts,a.c_verts,3),o=Et.edit.unwrap(a.i_norms,a.c_norms,3),l=Et.edit.unwrap(a.i_uvt,a.c_uvt,2),u=new Int32Array(a.i_verts.length),c=0;c0?o:null,autoNormals:0===o.length,uv:l,indices:u}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,r()}))}))}function Pt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,a=i?i[0]:0,s=i?i[1]:0,o=i?i[2]:0,l=-t+a,u=-n+s,c=-r+o,f=t+a,p=n+s,A=r+o;return se.apply(e,{positions:[f,p,A,l,p,A,l,u,A,f,u,A,f,p,A,f,u,A,f,u,c,f,p,c,f,p,A,f,p,c,l,p,c,l,p,A,l,p,A,l,p,c,l,u,c,l,u,A,l,u,c,f,u,c,f,u,A,l,u,A,f,u,c,l,u,c,l,p,c,f,p,c],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function Rt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,a=i?i[0]:0,s=i?i[1]:0,o=i?i[2]:0,l=-t+a,u=-n+s,c=-r+o,f=t+a,p=n+s,A=r+o;return se.apply(e,{primitive:"lines",positions:[l,u,c,l,u,A,l,p,c,l,p,A,f,u,c,f,u,A,f,p,c,f,p,A],indices:[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,2,6,3,7]})}function Ct(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);var n=e.radiusBottom||1;n<0&&(console.error("negative radiusBottom not allowed - will invert"),n*=-1);var r=e.height||1;r<0&&(console.error("negative height not allowed - will invert"),r*=-1);var i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);var a=e.heightSegments||1;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),a<1&&(a=1);var s,o,l,u,c,f,p,A,d,v,h,I=!!e.openEnded,y=e.center,m=y?y[0]:0,w=y?y[1]:0,g=y?y[2]:0,T=r/2,E=r/a,b=2*Math.PI/i,D=1/i,P=(t-n)/a,R=[],C=[],_=[],B=[],O=(90-180*Math.atan(r/(n-t))/Math.PI)/90;for(s=0;s<=a;s++)for(c=t-s*P,f=T-s*E,o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),C.push(c*l),C.push(O),C.push(c*u),_.push(o*D),_.push(1*s/a),R.push(c*l+m),R.push(f+w),R.push(c*u+g);for(s=0;s0){for(d=R.length/3,C.push(0),C.push(1),C.push(0),_.push(.5),_.push(.5),R.push(0+m),R.push(T+w),R.push(0+g),o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),v=.5*Math.sin(o*b)+.5,h=.5*Math.cos(o*b)+.5,C.push(t*l),C.push(1),C.push(t*u),_.push(v),_.push(h),R.push(t*l+m),R.push(T+w),R.push(t*u+g);for(o=0;o0){for(d=R.length/3,C.push(0),C.push(-1),C.push(0),_.push(.5),_.push(.5),R.push(0+m),R.push(0-T+w),R.push(0+g),o=0;o<=i;o++)l=Math.sin(o*b),u=Math.cos(o*b),v=.5*Math.sin(o*b)+.5,h=.5*Math.cos(o*b)+.5,C.push(n*l),C.push(-1),C.push(n*u),_.push(v),_.push(h),R.push(n*l+m),R.push(0-T+w),R.push(n*u+g);for(o=0;o0&&void 0!==arguments[0]?arguments[0]:{},t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);var n=e.divisions||1;n<0&&(console.error("negative divisions not allowed - will invert"),n*=-1),n<1&&(n=1);for(var r=(t=t||10)/(n=n||10),i=t/2,a=[],s=[],o=0,l=0,u=-i;l<=n;l++,u+=r)a.push(-i),a.push(0),a.push(u),a.push(i),a.push(0),a.push(u),a.push(u),a.push(0),a.push(-i),a.push(u),a.push(0),a.push(i),s.push(o++),s.push(o++),s.push(o++),s.push(o++);return se.apply(e,{primitive:"lines",positions:a,indices:s})}function Bt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);var r=e.xSegments||1;r<0&&(console.error("negative xSegments not allowed - will invert"),r*=-1),r<1&&(r=1);var i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);var a,s,o,l,u,c,f,p=e.center,A=p?p[0]:0,d=p?p[1]:0,v=p?p[2]:0,h=t/2,I=n/2,y=Math.floor(r)||1,m=Math.floor(i)||1,w=y+1,g=m+1,T=t/y,E=n/m,b=new Float32Array(w*g*3),D=new Float32Array(w*g*3),P=new Float32Array(w*g*2),R=0,C=0;for(a=0;a65535?Uint32Array:Uint16Array)(y*m*6);for(a=0;a0&&void 0!==arguments[0]?arguments[0]:{},t=e.lod||1,n=e.center?e.center[0]:0,r=e.center?e.center[1]:0,i=e.center?e.center[2]:0,a=e.radius||1;a<0&&(console.error("negative radius not allowed - will invert"),a*=-1);var s=e.heightSegments||18;s<0&&(console.error("negative heightSegments not allowed - will invert"),s*=-1),(s=Math.floor(t*s))<18&&(s=18);var o=e.widthSegments||18;o<0&&(console.error("negative widthSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var l,u,c,f,p,A,d,v,h,I,y,m,w,g,T=[],E=[],b=[],D=[];for(l=0;l<=s;l++)for(c=l*Math.PI/s,f=Math.sin(c),p=Math.cos(c),u=0;u<=o;u++)A=2*u*Math.PI/o,d=Math.sin(A),v=Math.cos(A)*f,h=p,I=d*f,y=1-u/o,m=l/s,E.push(v),E.push(h),E.push(I),b.push(y),b.push(m),T.push(n+a*v),T.push(r+a*h),T.push(i+a*I);for(l=0;l0&&void 0!==arguments[0]?arguments[0]:{},t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;var n=e.tube||.3;n<0&&(console.error("negative tube not allowed - will invert"),n*=-1);var r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<4&&(r=4);var i=e.tubeSegments||24;i<0&&(console.error("negative tubeSegments not allowed - will invert"),i*=-1),i<4&&(i=4);var a=e.arc||2*Math.PI;a<0&&(console.warn("negative arc not allowed - will invert"),a*=-1),a>360&&(a=360);var s,o,l,u,c,f,p,A,d,v,h,I,y=e.center,m=y?y[0]:0,w=y?y[1]:0,g=y?y[2]:0,T=[],E=[],b=[],D=[];for(A=0;A<=i;A++)for(p=0;p<=r;p++)s=p/r*a,o=.785398+A/i*Math.PI*2,m=t*Math.cos(s),w=t*Math.sin(s),l=(t+n*Math.cos(o))*Math.cos(s),u=(t+n*Math.cos(o))*Math.sin(s),c=n*Math.sin(o),T.push(l+m),T.push(u+w),T.push(c+g),b.push(1-p/r),b.push(A/i),f=$.normalizeVec3($.subVec3([l,u,c],[m,w,g],[]),[]),E.push(f[0]),E.push(f[1]),E.push(f[2]);for(A=1;A<=i;A++)for(p=1;p<=r;p++)d=(r+1)*A+p-1,v=(r+1)*(A-1)+p-1,h=(r+1)*(A-1)+p,I=(r+1)*A+p,D.push(d),D.push(v),D.push(h),D.push(h),D.push(I),D.push(d);return se.apply(e,{positions:T,normals:E,uv:b,indices:D})}Et.load=function(e,t){var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=function(e){t(e.target.response)},n.send()},Et.save=function(e,t){var n="data:application/octet-stream;base64,"+btoa(Et.parse._buffToStr(e));window.location.href=n},Et.clone=function(e){return JSON.parse(JSON.stringify(e))},Et.bin={},Et.bin.f=new Float32Array(1),Et.bin.fb=new Uint8Array(Et.bin.f.buffer),Et.bin.rf=function(e,t){for(var n=Et.bin.f,r=Et.bin.fb,i=0;i<4;i++)r[i]=e[t+i];return n[0]},Et.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},Et.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},Et.bin.rASCII0=function(e,t){for(var n="";0!=e[t];)n+=String.fromCharCode(e[t++]);return n},Et.bin.wf=function(e,t,n){new Float32Array(e.buffer,t,1)[0]=n},Et.bin.wsl=function(e,t,n){e[t]=n,e[t+1]=n>>8},Et.bin.wil=function(e,t,n){e[t]=n,e[t+1]=n>>8,e[t+2]=n>>16,e[t+3]},Et.parse={},Et.parse._buffToStr=function(e){for(var t=new Uint8Array(e),n="",r=0;ri&&(i=l),ua&&(a=u),cs&&(s=c)}return{min:{x:t,y:n,z:r},max:{x:i,y:a,z:s}}};var Nt={" ":{width:16,points:[]},"!":{width:10,points:[[5,21],[5,7],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},'"':{width:16,points:[[4,21],[4,14],[-1,-1],[12,21],[12,14]]},"#":{width:21,points:[[11,25],[4,-7],[-1,-1],[17,25],[10,-7],[-1,-1],[4,12],[18,12],[-1,-1],[3,6],[17,6]]},$:{width:20,points:[[8,25],[8,-4],[-1,-1],[12,25],[12,-4],[-1,-1],[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},"%":{width:24,points:[[21,21],[3,0],[-1,-1],[8,21],[10,19],[10,17],[9,15],[7,14],[5,14],[3,16],[3,18],[4,20],[6,21],[8,21],[10,20],[13,19],[16,19],[19,20],[21,21],[-1,-1],[17,7],[15,6],[14,4],[14,2],[16,0],[18,0],[20,1],[21,3],[21,5],[19,7],[17,7]]},"&":{width:26,points:[[23,12],[23,13],[22,14],[21,14],[20,13],[19,11],[17,6],[15,3],[13,1],[11,0],[7,0],[5,1],[4,2],[3,4],[3,6],[4,8],[5,9],[12,13],[13,14],[14,16],[14,18],[13,20],[11,21],[9,20],[8,18],[8,16],[9,13],[11,10],[16,3],[18,1],[20,0],[22,0],[23,1],[23,2]]},"'":{width:10,points:[[5,19],[4,20],[5,21],[6,20],[6,18],[5,16],[4,15]]},"(":{width:14,points:[[11,25],[9,23],[7,20],[5,16],[4,11],[4,7],[5,2],[7,-2],[9,-5],[11,-7]]},")":{width:14,points:[[3,25],[5,23],[7,20],[9,16],[10,11],[10,7],[9,2],[7,-2],[5,-5],[3,-7]]},"*":{width:16,points:[[8,21],[8,9],[-1,-1],[3,18],[13,12],[-1,-1],[13,18],[3,12]]},"+":{width:26,points:[[13,18],[13,0],[-1,-1],[4,9],[22,9]]},",":{width:10,points:[[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"-":{width:26,points:[[4,9],[22,9]]},".":{width:10,points:[[5,2],[4,1],[5,0],[6,1],[5,2]]},"/":{width:22,points:[[20,25],[2,-7]]},0:{width:20,points:[[9,21],[6,20],[4,17],[3,12],[3,9],[4,4],[6,1],[9,0],[11,0],[14,1],[16,4],[17,9],[17,12],[16,17],[14,20],[11,21],[9,21]]},1:{width:20,points:[[6,17],[8,18],[11,21],[11,0]]},2:{width:20,points:[[4,16],[4,17],[5,19],[6,20],[8,21],[12,21],[14,20],[15,19],[16,17],[16,15],[15,13],[13,10],[3,0],[17,0]]},3:{width:20,points:[[5,21],[16,21],[10,13],[13,13],[15,12],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},4:{width:20,points:[[13,21],[3,7],[18,7],[-1,-1],[13,21],[13,0]]},5:{width:20,points:[[15,21],[5,21],[4,12],[5,13],[8,14],[11,14],[14,13],[16,11],[17,8],[17,6],[16,3],[14,1],[11,0],[8,0],[5,1],[4,2],[3,4]]},6:{width:20,points:[[16,18],[15,20],[12,21],[10,21],[7,20],[5,17],[4,12],[4,7],[5,3],[7,1],[10,0],[11,0],[14,1],[16,3],[17,6],[17,7],[16,10],[14,12],[11,13],[10,13],[7,12],[5,10],[4,7]]},7:{width:20,points:[[17,21],[7,0],[-1,-1],[3,21],[17,21]]},8:{width:20,points:[[8,21],[5,20],[4,18],[4,16],[5,14],[7,13],[11,12],[14,11],[16,9],[17,7],[17,4],[16,2],[15,1],[12,0],[8,0],[5,1],[4,2],[3,4],[3,7],[4,9],[6,11],[9,12],[13,13],[15,14],[16,16],[16,18],[15,20],[12,21],[8,21]]},9:{width:20,points:[[16,14],[15,11],[13,9],[10,8],[9,8],[6,9],[4,11],[3,14],[3,15],[4,18],[6,20],[9,21],[10,21],[13,20],[15,18],[16,14],[16,9],[15,4],[13,1],[10,0],[8,0],[5,1],[4,3]]},":":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[5,2],[4,1],[5,0],[6,1],[5,2]]},";":{width:10,points:[[5,14],[4,13],[5,12],[6,13],[5,14],[-1,-1],[6,1],[5,0],[4,1],[5,2],[6,1],[6,-1],[5,-3],[4,-4]]},"<":{width:24,points:[[20,18],[4,9],[20,0]]},"=":{width:26,points:[[4,12],[22,12],[-1,-1],[4,6],[22,6]]},">":{width:24,points:[[4,18],[20,9],[4,0]]},"?":{width:18,points:[[3,16],[3,17],[4,19],[5,20],[7,21],[11,21],[13,20],[14,19],[15,17],[15,15],[14,13],[13,12],[9,10],[9,7],[-1,-1],[9,2],[8,1],[9,0],[10,1],[9,2]]},"@":{width:27,points:[[18,13],[17,15],[15,16],[12,16],[10,15],[9,14],[8,11],[8,8],[9,6],[11,5],[14,5],[16,6],[17,8],[-1,-1],[12,16],[10,14],[9,11],[9,8],[10,6],[11,5],[-1,-1],[18,16],[17,8],[17,6],[19,5],[21,5],[23,7],[24,10],[24,12],[23,15],[22,17],[20,19],[18,20],[15,21],[12,21],[9,20],[7,19],[5,17],[4,15],[3,12],[3,9],[4,6],[5,4],[7,2],[9,1],[12,0],[15,0],[18,1],[20,2],[21,3],[-1,-1],[19,16],[18,8],[18,6],[19,5]]},A:{width:18,points:[[9,21],[1,0],[-1,-1],[9,21],[17,0],[-1,-1],[4,7],[14,7]]},B:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[-1,-1],[4,11],[13,11],[16,10],[17,9],[18,7],[18,4],[17,2],[16,1],[13,0],[4,0]]},C:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5]]},D:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[11,21],[14,20],[16,18],[17,16],[18,13],[18,8],[17,5],[16,3],[14,1],[11,0],[4,0]]},E:{width:19,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11],[-1,-1],[4,0],[17,0]]},F:{width:18,points:[[4,21],[4,0],[-1,-1],[4,21],[17,21],[-1,-1],[4,11],[12,11]]},G:{width:21,points:[[18,16],[17,18],[15,20],[13,21],[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[18,8],[-1,-1],[13,8],[18,8]]},H:{width:22,points:[[4,21],[4,0],[-1,-1],[18,21],[18,0],[-1,-1],[4,11],[18,11]]},I:{width:8,points:[[4,21],[4,0]]},J:{width:16,points:[[12,21],[12,5],[11,2],[10,1],[8,0],[6,0],[4,1],[3,2],[2,5],[2,7]]},K:{width:21,points:[[4,21],[4,0],[-1,-1],[18,21],[4,7],[-1,-1],[9,12],[18,0]]},L:{width:17,points:[[4,21],[4,0],[-1,-1],[4,0],[16,0]]},M:{width:24,points:[[4,21],[4,0],[-1,-1],[4,21],[12,0],[-1,-1],[20,21],[12,0],[-1,-1],[20,21],[20,0]]},N:{width:22,points:[[4,21],[4,0],[-1,-1],[4,21],[18,0],[-1,-1],[18,21],[18,0]]},O:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21]]},P:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,14],[17,12],[16,11],[13,10],[4,10]]},Q:{width:22,points:[[9,21],[7,20],[5,18],[4,16],[3,13],[3,8],[4,5],[5,3],[7,1],[9,0],[13,0],[15,1],[17,3],[18,5],[19,8],[19,13],[18,16],[17,18],[15,20],[13,21],[9,21],[-1,-1],[12,4],[18,-2]]},R:{width:21,points:[[4,21],[4,0],[-1,-1],[4,21],[13,21],[16,20],[17,19],[18,17],[18,15],[17,13],[16,12],[13,11],[4,11],[-1,-1],[11,11],[18,0]]},S:{width:20,points:[[17,18],[15,20],[12,21],[8,21],[5,20],[3,18],[3,16],[4,14],[5,13],[7,12],[13,10],[15,9],[16,8],[17,6],[17,3],[15,1],[12,0],[8,0],[5,1],[3,3]]},T:{width:16,points:[[8,21],[8,0],[-1,-1],[1,21],[15,21]]},U:{width:22,points:[[4,21],[4,6],[5,3],[7,1],[10,0],[12,0],[15,1],[17,3],[18,6],[18,21]]},V:{width:18,points:[[1,21],[9,0],[-1,-1],[17,21],[9,0]]},W:{width:24,points:[[2,21],[7,0],[-1,-1],[12,21],[7,0],[-1,-1],[12,21],[17,0],[-1,-1],[22,21],[17,0]]},X:{width:20,points:[[3,21],[17,0],[-1,-1],[17,21],[3,0]]},Y:{width:18,points:[[1,21],[9,11],[9,0],[-1,-1],[17,21],[9,11]]},Z:{width:20,points:[[17,21],[3,0],[-1,-1],[3,21],[17,21],[-1,-1],[3,0],[17,0]]},"[":{width:14,points:[[4,25],[4,-7],[-1,-1],[5,25],[5,-7],[-1,-1],[4,25],[11,25],[-1,-1],[4,-7],[11,-7]]},"\\":{width:14,points:[[0,21],[14,-3]]},"]":{width:14,points:[[9,25],[9,-7],[-1,-1],[10,25],[10,-7],[-1,-1],[3,25],[10,25],[-1,-1],[3,-7],[10,-7]]},"^":{width:16,points:[[6,15],[8,18],[10,15],[-1,-1],[3,12],[8,17],[13,12],[-1,-1],[8,17],[8,0]]},_:{width:16,points:[[0,-2],[16,-2]]},"`":{width:10,points:[[6,21],[5,20],[4,18],[4,16],[5,15],[6,16],[5,17]]},a:{width:19,points:[[15,14],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},b:{width:19,points:[[4,21],[4,0],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},c:{width:18,points:[[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},d:{width:19,points:[[15,21],[15,0],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},e:{width:18,points:[[3,8],[15,8],[15,10],[14,12],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},f:{width:12,points:[[10,21],[8,21],[6,20],[5,17],[5,0],[-1,-1],[2,14],[9,14]]},g:{width:19,points:[[15,14],[15,-2],[14,-5],[13,-6],[11,-7],[8,-7],[6,-6],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},h:{width:19,points:[[4,21],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},i:{width:8,points:[[3,21],[4,20],[5,21],[4,22],[3,21],[-1,-1],[4,14],[4,0]]},j:{width:10,points:[[5,21],[6,20],[7,21],[6,22],[5,21],[-1,-1],[6,14],[6,-3],[5,-6],[3,-7],[1,-7]]},k:{width:17,points:[[4,21],[4,0],[-1,-1],[14,14],[4,4],[-1,-1],[8,8],[15,0]]},l:{width:8,points:[[4,21],[4,0]]},m:{width:30,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0],[-1,-1],[15,10],[18,13],[20,14],[23,14],[25,13],[26,10],[26,0]]},n:{width:19,points:[[4,14],[4,0],[-1,-1],[4,10],[7,13],[9,14],[12,14],[14,13],[15,10],[15,0]]},o:{width:19,points:[[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3],[16,6],[16,8],[15,11],[13,13],[11,14],[8,14]]},p:{width:19,points:[[4,14],[4,-7],[-1,-1],[4,11],[6,13],[8,14],[11,14],[13,13],[15,11],[16,8],[16,6],[15,3],[13,1],[11,0],[8,0],[6,1],[4,3]]},q:{width:19,points:[[15,14],[15,-7],[-1,-1],[15,11],[13,13],[11,14],[8,14],[6,13],[4,11],[3,8],[3,6],[4,3],[6,1],[8,0],[11,0],[13,1],[15,3]]},r:{width:13,points:[[4,14],[4,0],[-1,-1],[4,8],[5,11],[7,13],[9,14],[12,14]]},s:{width:17,points:[[14,11],[13,13],[10,14],[7,14],[4,13],[3,11],[4,9],[6,8],[11,7],[13,6],[14,4],[14,3],[13,1],[10,0],[7,0],[4,1],[3,3]]},t:{width:12,points:[[5,21],[5,4],[6,1],[8,0],[10,0],[-1,-1],[2,14],[9,14]]},u:{width:19,points:[[4,14],[4,4],[5,1],[7,0],[10,0],[12,1],[15,4],[-1,-1],[15,14],[15,0]]},v:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0]]},w:{width:22,points:[[3,14],[7,0],[-1,-1],[11,14],[7,0],[-1,-1],[11,14],[15,0],[-1,-1],[19,14],[15,0]]},x:{width:17,points:[[3,14],[14,0],[-1,-1],[14,14],[3,0]]},y:{width:16,points:[[2,14],[8,0],[-1,-1],[14,14],[8,0],[6,-4],[4,-6],[2,-7],[1,-7]]},z:{width:17,points:[[14,14],[3,0],[-1,-1],[3,14],[14,14],[-1,-1],[3,0],[14,0]]},"{":{width:14,points:[[9,25],[7,24],[6,23],[5,21],[5,19],[6,17],[7,16],[8,14],[8,12],[6,10],[-1,-1],[7,24],[6,22],[6,20],[7,18],[8,17],[9,15],[9,13],[8,11],[4,9],[8,7],[9,5],[9,3],[8,1],[7,0],[6,-2],[6,-4],[7,-6],[-1,-1],[6,8],[8,6],[8,4],[7,2],[6,1],[5,-1],[5,-3],[6,-5],[7,-6],[9,-7]]},"|":{width:8,points:[[4,25],[4,-7]]},"}":{width:14,points:[[5,25],[7,24],[8,23],[9,21],[9,19],[8,17],[7,16],[6,14],[6,12],[8,10],[-1,-1],[7,24],[8,22],[8,20],[7,18],[6,17],[5,15],[5,13],[6,11],[10,9],[6,7],[5,5],[5,3],[6,1],[7,0],[8,-2],[8,-4],[7,-6],[-1,-1],[8,8],[6,6],[6,4],[7,2],[8,1],[9,-1],[9,-3],[8,-5],[7,-6],[5,-7]]},"~":{width:24,points:[[3,6],[3,8],[4,11],[6,12],[8,12],[10,11],[14,8],[16,7],[18,7],[20,8],[21,10],[-1,-1],[3,8],[4,10],[6,11],[8,11],[10,10],[14,7],[16,6],[18,6],[20,7],[21,10],[21,12]]}};function Lt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.origin||[0,0,0],n=t[0],r=t[1],i=t[2],a=e.size||1,s=[],o=[],l=e.text;se.isNumeric(l)&&(l=""+l);for(var u,c,f,p,A,d,v,h,I,y=(l||"").split("\n"),m=0,w=0,g=.04,T=0;T1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e,i))._parentNode=null,r._children=[],r._aabb=null,r._aabbDirty=!0,r.scene._aabbDirty=!0,r._numTriangles=0,r._scale=$.vec3(),r._quaternion=$.identityQuaternion(),r._rotation=$.vec3(),r._position=$.vec3(),r._offset=$.vec3(),r._localMatrix=$.identityMat4(),r._worldMatrix=$.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(g(r)),r.origin=i.origin,r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.children)for(var a=i.children,s=0,o=a.length;s0,l=!!i.compressGeometry,u=[];u.push("#version 300 es"),u.push("// Lambertian drawing vertex shader"),u.push("in vec3 position;"),u.push("uniform mat4 modelMatrix;"),u.push("uniform mat4 viewMatrix;"),u.push("uniform mat4 projMatrix;"),u.push("uniform vec4 colorize;"),u.push("uniform vec3 offset;"),l&&u.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(u.push("uniform float logDepthBufFC;"),u.push("out float vFragDepth;"),u.push("bool isPerspectiveMatrix(mat4 m) {"),u.push(" return (m[2][3] == - 1.0);"),u.push("}"),u.push("out float isPerspective;"));o&&u.push("out vec4 vWorldPosition;");if(u.push("uniform vec4 lightAmbient;"),u.push("uniform vec4 materialColor;"),u.push("uniform vec3 materialEmissive;"),i.normalsBuf){u.push("in vec3 normal;"),u.push("uniform mat4 modelNormalMatrix;"),u.push("uniform mat4 viewNormalMatrix;");for(var c=0,f=r.lights.length;c= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),u.push(" }"),u.push(" return normalize(v);"),u.push("}"))}u.push("out vec4 vColor;"),"points"===i.primitiveName&&u.push("uniform float pointSize;");"spherical"!==a&&"cylindrical"!==a||(u.push("void billboard(inout mat4 mat) {"),u.push(" mat[0][0] = 1.0;"),u.push(" mat[0][1] = 0.0;"),u.push(" mat[0][2] = 0.0;"),"spherical"===a&&(u.push(" mat[1][0] = 0.0;"),u.push(" mat[1][1] = 1.0;"),u.push(" mat[1][2] = 0.0;")),u.push(" mat[2][0] = 0.0;"),u.push(" mat[2][1] = 0.0;"),u.push(" mat[2][2] =1.0;"),u.push("}"));u.push("void main(void) {"),u.push("vec4 localPosition = vec4(position, 1.0); "),u.push("vec4 worldPosition;"),l&&u.push("localPosition = positionsDecodeMatrix * localPosition;");i.normalsBuf&&(l?u.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):u.push("vec4 localNormal = vec4(normal, 0.0); "),u.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),u.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));u.push("mat4 viewMatrix2 = viewMatrix;"),u.push("mat4 modelMatrix2 = modelMatrix;"),s&&u.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===a||"cylindrical"===a?(u.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),u.push("billboard(modelMatrix2);"),u.push("billboard(viewMatrix2);"),u.push("billboard(modelViewMatrix);"),i.normalsBuf&&(u.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),u.push("billboard(modelNormalMatrix2);"),u.push("billboard(viewNormalMatrix2);"),u.push("billboard(modelViewNormalMatrix);")),u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(u.push("worldPosition = modelMatrix2 * localPosition;"),u.push("worldPosition.xyz = worldPosition.xyz + offset;"),u.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));i.normalsBuf&&u.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(u.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),u.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),u.push("float lambertian = 1.0;"),i.normalsBuf)for(var A=0,d=r.lights.length;A0,a=t.gammaOutput,s=[];s.push("#version 300 es"),s.push("// Lambertian drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;"));if(i){s.push("in vec4 vWorldPosition;"),s.push("uniform bool clippable;");for(var o=0,l=n.sectionPlanes.length;o 0.0) { discard; }"),s.push("}")}"points"===r.primitiveName&&(s.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),s.push("float r = dot(cxy, cxy);"),s.push("if (r > 1.0) {"),s.push(" discard;"),s.push("}"));t.logarithmicDepthBufferEnabled&&s.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");a?s.push("outColor = linearToGamma(vColor, gammaFactor);"):s.push("outColor = vColor;");return s.push("}"),s}(e)):(this.vertex=function(e){var t=e.scene;e._material;var n,r=e._state,i=t._sectionPlanesState,a=e._geometry._state,s=t._lightsState,o=r.billboard,l=r.background,u=r.stationary,c=function(e){if(!e._geometry._state.uvBuf)return!1;var t=e._material;return!!(t._ambientMap||t._occlusionMap||t._baseColorMap||t._diffuseMap||t._alphaMap||t._specularMap||t._glossinessMap||t._specularGlossinessMap||t._emissiveMap||t._metallicMap||t._roughnessMap||t._metallicRoughnessMap||t._reflectivityMap||t._normalMap)}(e),f=ur(e),p=i.sectionPlanes.length>0,A=lr(e),d=!!a.compressGeometry,v=[];v.push("#version 300 es"),v.push("// Drawing vertex shader"),v.push("in vec3 position;"),d&&v.push("uniform mat4 positionsDecodeMatrix;");v.push("uniform mat4 modelMatrix;"),v.push("uniform mat4 viewMatrix;"),v.push("uniform mat4 projMatrix;"),v.push("out vec3 vViewPosition;"),v.push("uniform vec3 offset;"),p&&v.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(v.push("uniform float logDepthBufFC;"),v.push("out float vFragDepth;"),v.push("bool isPerspectiveMatrix(mat4 m) {"),v.push(" return (m[2][3] == - 1.0);"),v.push("}"),v.push("out float isPerspective;"));s.lightMaps.length>0&&v.push("out vec3 vWorldNormal;");if(f){v.push("in vec3 normal;"),v.push("uniform mat4 modelNormalMatrix;"),v.push("uniform mat4 viewNormalMatrix;"),v.push("out vec3 vViewNormal;");for(var h=0,I=s.lights.length;h= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),v.push(" }"),v.push(" return normalize(v);"),v.push("}"))}c&&(v.push("in vec2 uv;"),v.push("out vec2 vUV;"),d&&v.push("uniform mat3 uvDecodeMatrix;"));a.colors&&(v.push("in vec4 color;"),v.push("out vec4 vColor;"));"points"===a.primitiveName&&v.push("uniform float pointSize;");"spherical"!==o&&"cylindrical"!==o||(v.push("void billboard(inout mat4 mat) {"),v.push(" mat[0][0] = 1.0;"),v.push(" mat[0][1] = 0.0;"),v.push(" mat[0][2] = 0.0;"),"spherical"===o&&(v.push(" mat[1][0] = 0.0;"),v.push(" mat[1][1] = 1.0;"),v.push(" mat[1][2] = 0.0;")),v.push(" mat[2][0] = 0.0;"),v.push(" mat[2][1] = 0.0;"),v.push(" mat[2][2] =1.0;"),v.push("}"));if(A){v.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");for(var y=0,m=s.lights.length;y0&&v.push("vWorldNormal = worldNormal;"),v.push("vViewNormal = normalize((viewNormalMatrix2 * vec4(worldNormal, 1.0)).xyz);"),v.push("vec3 tmpVec3;"),v.push("float lightDist;");for(var w=0,g=s.lights.length;w0,l=ur(e),u=r.uvBuf,c="PhongMaterial"===s.type,f="MetallicMaterial"===s.type,p="SpecularMaterial"===s.type,A=lr(e);t.gammaInput;var d=t.gammaOutput,v=[];v.push("#version 300 es"),v.push("// Drawing fragment shader"),v.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),v.push("precision highp float;"),v.push("precision highp int;"),v.push("#else"),v.push("precision mediump float;"),v.push("precision mediump int;"),v.push("#endif"),t.logarithmicDepthBufferEnabled&&(v.push("in float isPerspective;"),v.push("uniform float logDepthBufFC;"),v.push("in float vFragDepth;"));A&&(v.push("float unpackDepth (vec4 color) {"),v.push(" const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"),v.push(" return dot(color, bitShift);"),v.push("}"));v.push("uniform float gammaFactor;"),v.push("vec4 linearToLinear( in vec4 value ) {"),v.push(" return value;"),v.push("}"),v.push("vec4 sRGBToLinear( in vec4 value ) {"),v.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),v.push("}"),v.push("vec4 gammaToLinear( in vec4 value) {"),v.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),v.push("}"),d&&(v.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),v.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),v.push("}"));if(o){v.push("in vec4 vWorldPosition;"),v.push("uniform bool clippable;");for(var h=0;h0&&(v.push("uniform samplerCube lightMap;"),v.push("uniform mat4 viewNormalMatrix;")),a.reflectionMaps.length>0&&v.push("uniform samplerCube reflectionMap;"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("uniform mat4 viewMatrix;"),v.push("#define PI 3.14159265359"),v.push("#define RECIPROCAL_PI 0.31830988618"),v.push("#define RECIPROCAL_PI2 0.15915494"),v.push("#define EPSILON 1e-6"),v.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),v.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),v.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),v.push("}"),v.push("struct IncidentLight {"),v.push(" vec3 color;"),v.push(" vec3 direction;"),v.push("};"),v.push("struct ReflectedLight {"),v.push(" vec3 diffuse;"),v.push(" vec3 specular;"),v.push("};"),v.push("struct Geometry {"),v.push(" vec3 position;"),v.push(" vec3 viewNormal;"),v.push(" vec3 worldNormal;"),v.push(" vec3 viewEyeDir;"),v.push("};"),v.push("struct Material {"),v.push(" vec3 diffuseColor;"),v.push(" float specularRoughness;"),v.push(" vec3 specularColor;"),v.push(" float shine;"),v.push("};"),c&&((a.lightMaps.length>0||a.reflectionMaps.length>0)&&(v.push("void computePhongLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(v.push(" vec3 irradiance = "+or[a.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),v.push(" irradiance *= PI;"),v.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(v.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),v.push(" vec3 radiance = texture(reflectionMap, reflectVec).rgb * 0.2;"),v.push(" radiance *= PI;"),v.push(" reflectedLight.specular += radiance;")),v.push("}")),v.push("void computePhongLighting(const in IncidentLight directLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),v.push(" float dotNL = saturate(dot(geometry.viewNormal, directLight.direction));"),v.push(" vec3 irradiance = dotNL * directLight.color * PI;"),v.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.specular += directLight.color * material.specularColor * pow(max(dot(reflect(-directLight.direction, -geometry.viewNormal), geometry.viewEyeDir), 0.0), material.shine);"),v.push("}")),(f||p)&&(v.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),v.push(" float r = ggxRoughness + 0.0001;"),v.push(" return (2.0 / (r * r) - 2.0);"),v.push("}"),v.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),v.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),v.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),v.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),v.push("}"),a.reflectionMaps.length>0&&(v.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),v.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),v.push(" vec3 envMapColor = "+or[a.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),v.push(" return envMapColor;"),v.push("}")),v.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),v.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),v.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),v.push("}"),v.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),v.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),v.push(" return 1.0 / ( gl * gv );"),v.push("}"),v.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),v.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),v.push(" return 0.5 / max( gv + gl, EPSILON );"),v.push("}"),v.push("float D_GGX(const in float alpha, const in float dotNH) {"),v.push(" float a2 = ( alpha * alpha );"),v.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),v.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),v.push("}"),v.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),v.push(" float alpha = ( roughness * roughness );"),v.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),v.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),v.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),v.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),v.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),v.push(" vec3 F = F_Schlick( specularColor, dotLH );"),v.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),v.push(" float D = D_GGX( alpha, dotNH );"),v.push(" return F * (G * D);"),v.push("}"),v.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),v.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),v.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),v.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),v.push(" vec4 r = roughness * c0 + c1;"),v.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),v.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),v.push(" return specularColor * AB.x + AB.y;"),v.push("}"),(a.lightMaps.length>0||a.reflectionMaps.length>0)&&(v.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),a.lightMaps.length>0&&(v.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),v.push(" irradiance *= PI;"),v.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),a.reflectionMaps.length>0&&(v.push(" vec3 reflectVec = reflect(-geometry.viewEyeDir, geometry.viewNormal);"),v.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),v.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),v.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),v.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),v.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),v.push("}")),v.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),v.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),v.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),v.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),v.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),v.push("}")));v.push("in vec3 vViewPosition;"),r.colors&&v.push("in vec4 vColor;");u&&(l&&n._normalMap||n._ambientMap||n._baseColorMap||n._diffuseMap||n._emissiveMap||n._metallicMap||n._roughnessMap||n._metallicRoughnessMap||n._specularMap||n._glossinessMap||n._specularGlossinessMap||n._occlusionMap||n._alphaMap)&&v.push("in vec2 vUV;");l&&(a.lightMaps.length>0&&v.push("in vec3 vWorldNormal;"),v.push("in vec3 vViewNormal;"));s.ambient&&v.push("uniform vec3 materialAmbient;");s.baseColor&&v.push("uniform vec3 materialBaseColor;");void 0!==s.alpha&&null!==s.alpha&&v.push("uniform vec4 materialAlphaModeCutoff;");s.emissive&&v.push("uniform vec3 materialEmissive;");s.diffuse&&v.push("uniform vec3 materialDiffuse;");void 0!==s.glossiness&&null!==s.glossiness&&v.push("uniform float materialGlossiness;");void 0!==s.shininess&&null!==s.shininess&&v.push("uniform float materialShininess;");s.specular&&v.push("uniform vec3 materialSpecular;");void 0!==s.metallic&&null!==s.metallic&&v.push("uniform float materialMetallic;");void 0!==s.roughness&&null!==s.roughness&&v.push("uniform float materialRoughness;");void 0!==s.specularF0&&null!==s.specularF0&&v.push("uniform float materialSpecularF0;");u&&n._ambientMap&&(v.push("uniform sampler2D ambientMap;"),n._ambientMap._state.matrix&&v.push("uniform mat4 ambientMapMatrix;"));u&&n._baseColorMap&&(v.push("uniform sampler2D baseColorMap;"),n._baseColorMap._state.matrix&&v.push("uniform mat4 baseColorMapMatrix;"));u&&n._diffuseMap&&(v.push("uniform sampler2D diffuseMap;"),n._diffuseMap._state.matrix&&v.push("uniform mat4 diffuseMapMatrix;"));u&&n._emissiveMap&&(v.push("uniform sampler2D emissiveMap;"),n._emissiveMap._state.matrix&&v.push("uniform mat4 emissiveMapMatrix;"));l&&u&&n._metallicMap&&(v.push("uniform sampler2D metallicMap;"),n._metallicMap._state.matrix&&v.push("uniform mat4 metallicMapMatrix;"));l&&u&&n._roughnessMap&&(v.push("uniform sampler2D roughnessMap;"),n._roughnessMap._state.matrix&&v.push("uniform mat4 roughnessMapMatrix;"));l&&u&&n._metallicRoughnessMap&&(v.push("uniform sampler2D metallicRoughnessMap;"),n._metallicRoughnessMap._state.matrix&&v.push("uniform mat4 metallicRoughnessMapMatrix;"));l&&n._normalMap&&(v.push("uniform sampler2D normalMap;"),n._normalMap._state.matrix&&v.push("uniform mat4 normalMapMatrix;"),v.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),v.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),v.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),v.push(" vec2 st0 = dFdx( uv.st );"),v.push(" vec2 st1 = dFdy( uv.st );"),v.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),v.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),v.push(" vec3 N = normalize( surf_norm );"),v.push(" vec3 mapN = texture( normalMap, uv ).xyz * 2.0 - 1.0;"),v.push(" mat3 tsn = mat3( S, T, N );"),v.push(" return normalize( tsn * mapN );"),v.push("}"));u&&n._occlusionMap&&(v.push("uniform sampler2D occlusionMap;"),n._occlusionMap._state.matrix&&v.push("uniform mat4 occlusionMapMatrix;"));u&&n._alphaMap&&(v.push("uniform sampler2D alphaMap;"),n._alphaMap._state.matrix&&v.push("uniform mat4 alphaMapMatrix;"));l&&u&&n._specularMap&&(v.push("uniform sampler2D specularMap;"),n._specularMap._state.matrix&&v.push("uniform mat4 specularMapMatrix;"));l&&u&&n._glossinessMap&&(v.push("uniform sampler2D glossinessMap;"),n._glossinessMap._state.matrix&&v.push("uniform mat4 glossinessMapMatrix;"));l&&u&&n._specularGlossinessMap&&(v.push("uniform sampler2D materialSpecularGlossinessMap;"),n._specularGlossinessMap._state.matrix&&v.push("uniform mat4 materialSpecularGlossinessMapMatrix;"));l&&(n._diffuseFresnel||n._specularFresnel||n._alphaFresnel||n._emissiveFresnel||n._reflectivityFresnel)&&(v.push("float fresnel(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {"),v.push(" float fr = abs(dot(eyeDir, normal));"),v.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),v.push(" return pow(finalFr, power);"),v.push("}"),n._diffuseFresnel&&(v.push("uniform float diffuseFresnelCenterBias;"),v.push("uniform float diffuseFresnelEdgeBias;"),v.push("uniform float diffuseFresnelPower;"),v.push("uniform vec3 diffuseFresnelCenterColor;"),v.push("uniform vec3 diffuseFresnelEdgeColor;")),n._specularFresnel&&(v.push("uniform float specularFresnelCenterBias;"),v.push("uniform float specularFresnelEdgeBias;"),v.push("uniform float specularFresnelPower;"),v.push("uniform vec3 specularFresnelCenterColor;"),v.push("uniform vec3 specularFresnelEdgeColor;")),n._alphaFresnel&&(v.push("uniform float alphaFresnelCenterBias;"),v.push("uniform float alphaFresnelEdgeBias;"),v.push("uniform float alphaFresnelPower;"),v.push("uniform vec3 alphaFresnelCenterColor;"),v.push("uniform vec3 alphaFresnelEdgeColor;")),n._reflectivityFresnel&&(v.push("uniform float materialSpecularF0FresnelCenterBias;"),v.push("uniform float materialSpecularF0FresnelEdgeBias;"),v.push("uniform float materialSpecularF0FresnelPower;"),v.push("uniform vec3 materialSpecularF0FresnelCenterColor;"),v.push("uniform vec3 materialSpecularF0FresnelEdgeColor;")),n._emissiveFresnel&&(v.push("uniform float emissiveFresnelCenterBias;"),v.push("uniform float emissiveFresnelEdgeBias;"),v.push("uniform float emissiveFresnelPower;"),v.push("uniform vec3 emissiveFresnelCenterColor;"),v.push("uniform vec3 emissiveFresnelEdgeColor;")));if(v.push("uniform vec4 lightAmbient;"),l)for(var I=0,y=a.lights.length;I 0.0) { discard; }"),v.push("}")}"points"===r.primitiveName&&(v.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),v.push("float r = dot(cxy, cxy);"),v.push("if (r > 1.0) {"),v.push(" discard;"),v.push("}"));v.push("float occlusion = 1.0;"),s.ambient?v.push("vec3 ambientColor = materialAmbient;"):v.push("vec3 ambientColor = vec3(1.0, 1.0, 1.0);");s.diffuse?v.push("vec3 diffuseColor = materialDiffuse;"):s.baseColor?v.push("vec3 diffuseColor = materialBaseColor;"):v.push("vec3 diffuseColor = vec3(1.0, 1.0, 1.0);");r.colors&&v.push("diffuseColor *= vColor.rgb;");s.emissive?v.push("vec3 emissiveColor = materialEmissive;"):v.push("vec3 emissiveColor = vec3(0.0, 0.0, 0.0);");s.specular?v.push("vec3 specular = materialSpecular;"):v.push("vec3 specular = vec3(1.0, 1.0, 1.0);");void 0!==s.alpha?v.push("float alpha = materialAlphaModeCutoff[0];"):v.push("float alpha = 1.0;");r.colors&&v.push("alpha *= vColor.a;");void 0!==s.glossiness?v.push("float glossiness = materialGlossiness;"):v.push("float glossiness = 1.0;");void 0!==s.metallic?v.push("float metallic = materialMetallic;"):v.push("float metallic = 1.0;");void 0!==s.roughness?v.push("float roughness = materialRoughness;"):v.push("float roughness = 1.0;");void 0!==s.specularF0?v.push("float specularF0 = materialSpecularF0;"):v.push("float specularF0 = 1.0;");u&&(l&&n._normalMap||n._ambientMap||n._baseColorMap||n._diffuseMap||n._occlusionMap||n._emissiveMap||n._metallicMap||n._roughnessMap||n._metallicRoughnessMap||n._specularMap||n._glossinessMap||n._specularGlossinessMap||n._alphaMap)&&(v.push("vec4 texturePos = vec4(vUV.s, vUV.t, 1.0, 1.0);"),v.push("vec2 textureCoord;"));u&&n._ambientMap&&(n._ambientMap._state.matrix?v.push("textureCoord = (ambientMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 ambientTexel = texture(ambientMap, textureCoord).rgb;"),v.push("ambientTexel = "+or[n._ambientMap._state.encoding]+"(ambientTexel);"),v.push("ambientColor *= ambientTexel.rgb;"));u&&n._diffuseMap&&(n._diffuseMap._state.matrix?v.push("textureCoord = (diffuseMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 diffuseTexel = texture(diffuseMap, textureCoord);"),v.push("diffuseTexel = "+or[n._diffuseMap._state.encoding]+"(diffuseTexel);"),v.push("diffuseColor *= diffuseTexel.rgb;"),v.push("alpha *= diffuseTexel.a;"));u&&n._baseColorMap&&(n._baseColorMap._state.matrix?v.push("textureCoord = (baseColorMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 baseColorTexel = texture(baseColorMap, textureCoord);"),v.push("baseColorTexel = "+or[n._baseColorMap._state.encoding]+"(baseColorTexel);"),v.push("diffuseColor *= baseColorTexel.rgb;"),v.push("alpha *= baseColorTexel.a;"));u&&n._emissiveMap&&(n._emissiveMap._state.matrix?v.push("textureCoord = (emissiveMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 emissiveTexel = texture(emissiveMap, textureCoord);"),v.push("emissiveTexel = "+or[n._emissiveMap._state.encoding]+"(emissiveTexel);"),v.push("emissiveColor = emissiveTexel.rgb;"));u&&n._alphaMap&&(n._alphaMap._state.matrix?v.push("textureCoord = (alphaMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("alpha *= texture(alphaMap, textureCoord).r;"));u&&n._occlusionMap&&(n._occlusionMap._state.matrix?v.push("textureCoord = (occlusionMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("occlusion *= texture(occlusionMap, textureCoord).r;"));if(l&&(a.lights.length>0||a.lightMaps.length>0||a.reflectionMaps.length>0)){u&&n._normalMap?(n._normalMap._state.matrix?v.push("textureCoord = (normalMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition, normalize(vViewNormal), textureCoord );")):v.push("vec3 viewNormal = normalize(vViewNormal);"),u&&n._specularMap&&(n._specularMap._state.matrix?v.push("textureCoord = (specularMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("specular *= texture(specularMap, textureCoord).rgb;")),u&&n._glossinessMap&&(n._glossinessMap._state.matrix?v.push("textureCoord = (glossinessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("glossiness *= texture(glossinessMap, textureCoord).r;")),u&&n._specularGlossinessMap&&(n._specularGlossinessMap._state.matrix?v.push("textureCoord = (materialSpecularGlossinessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec4 specGlossRGB = texture(materialSpecularGlossinessMap, textureCoord).rgba;"),v.push("specular *= specGlossRGB.rgb;"),v.push("glossiness *= specGlossRGB.a;")),u&&n._metallicMap&&(n._metallicMap._state.matrix?v.push("textureCoord = (metallicMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("metallic *= texture(metallicMap, textureCoord).r;")),u&&n._roughnessMap&&(n._roughnessMap._state.matrix?v.push("textureCoord = (roughnessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("roughness *= texture(roughnessMap, textureCoord).r;")),u&&n._metallicRoughnessMap&&(n._metallicRoughnessMap._state.matrix?v.push("textureCoord = (metallicRoughnessMapMatrix * texturePos).xy;"):v.push("textureCoord = texturePos.xy;"),v.push("vec3 metalRoughRGB = texture(metallicRoughnessMap, textureCoord).rgb;"),v.push("metallic *= metalRoughRGB.b;"),v.push("roughness *= metalRoughRGB.g;")),v.push("vec3 viewEyeDir = normalize(-vViewPosition);"),n._diffuseFresnel&&(v.push("float diffuseFresnel = fresnel(viewEyeDir, viewNormal, diffuseFresnelEdgeBias, diffuseFresnelCenterBias, diffuseFresnelPower);"),v.push("diffuseColor *= mix(diffuseFresnelEdgeColor, diffuseFresnelCenterColor, diffuseFresnel);")),n._specularFresnel&&(v.push("float specularFresnel = fresnel(viewEyeDir, viewNormal, specularFresnelEdgeBias, specularFresnelCenterBias, specularFresnelPower);"),v.push("specular *= mix(specularFresnelEdgeColor, specularFresnelCenterColor, specularFresnel);")),n._alphaFresnel&&(v.push("float alphaFresnel = fresnel(viewEyeDir, viewNormal, alphaFresnelEdgeBias, alphaFresnelCenterBias, alphaFresnelPower);"),v.push("alpha *= mix(alphaFresnelEdgeColor.r, alphaFresnelCenterColor.r, alphaFresnel);")),n._emissiveFresnel&&(v.push("float emissiveFresnel = fresnel(viewEyeDir, viewNormal, emissiveFresnelEdgeBias, emissiveFresnelCenterBias, emissiveFresnelPower);"),v.push("emissiveColor *= mix(emissiveFresnelEdgeColor, emissiveFresnelCenterColor, emissiveFresnel);")),v.push("if (materialAlphaModeCutoff[1] == 1.0 && alpha < materialAlphaModeCutoff[2]) {"),v.push(" discard;"),v.push("}"),v.push("IncidentLight light;"),v.push("Material material;"),v.push("Geometry geometry;"),v.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),v.push("vec3 viewLightDir;"),c&&(v.push("material.diffuseColor = diffuseColor;"),v.push("material.specularColor = specular;"),v.push("material.shine = materialShininess;")),p&&(v.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),v.push("material.diffuseColor = diffuseColor * oneMinusSpecularStrength;"),v.push("material.specularRoughness = clamp( 1.0 - glossiness, 0.04, 1.0 );"),v.push("material.specularColor = specular;")),f&&(v.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),v.push("material.diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),v.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),v.push("material.specularColor = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),v.push("geometry.position = vViewPosition;"),a.lightMaps.length>0&&v.push("geometry.worldNormal = normalize(vWorldNormal);"),v.push("geometry.viewNormal = viewNormal;"),v.push("geometry.viewEyeDir = viewEyeDir;"),c&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("computePhongLightMapping(geometry, material, reflectedLight);"),(p||f)&&(a.lightMaps.length>0||a.reflectionMaps.length>0)&&v.push("computePBRLightMapping(geometry, material, reflectedLight);"),v.push("float shadow = 1.0;"),v.push("float shadowAcneRemover = 0.007;"),v.push("vec3 fragmentDepth;"),v.push("float texelSize = 1.0 / 1024.0;"),v.push("float amountInLight = 0.0;"),v.push("vec3 shadowCoord;"),v.push("vec4 rgbaDepth;"),v.push("float depth;");for(var T=0,E=a.lights.length;T0&&"/"===t.charAt(n+1)&&(t=t.substring(0,n)),r.push(t);return r.join("\n")}function vr(e){console.error(e.join("\n"))}var hr=function(){function e(t,n){b(this,e),this.id=Ar.addItem({}),this.source=n,this.init(t)}return P(e,[{key:"init",value:function(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new cr(e,e.VERTEX_SHADER,dr(this.source.vertex)),this._fragmentShader=new cr(e,e.FRAGMENT_SHADER,dr(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void vr(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void vr(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void vr(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void vr(this.errors);var t,n,r,i,a;if(this.compiled=!0,this.handle=e.createProgram(),this.handle){if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void vr(this.errors);var s=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(n=0;n0?Ir.FS_MAX_FLOAT_PRECISION="highp":mr.getShaderPrecisionFormat(mr.FRAGMENT_SHADER,mr.MEDIUM_FLOAT).precision>0?Ir.FS_MAX_FLOAT_PRECISION="mediump":Ir.FS_MAX_FLOAT_PRECISION="lowp":Ir.FS_MAX_FLOAT_PRECISION="mediump",Ir.DEPTH_BUFFER_BITS=mr.getParameter(mr.DEPTH_BITS),Ir.MAX_TEXTURE_SIZE=mr.getParameter(mr.MAX_TEXTURE_SIZE),Ir.MAX_CUBE_MAP_SIZE=mr.getParameter(mr.MAX_CUBE_MAP_TEXTURE_SIZE),Ir.MAX_RENDERBUFFER_SIZE=mr.getParameter(mr.MAX_RENDERBUFFER_SIZE),Ir.MAX_TEXTURE_UNITS=mr.getParameter(mr.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Ir.MAX_TEXTURE_IMAGE_UNITS=mr.getParameter(mr.MAX_TEXTURE_IMAGE_UNITS),Ir.MAX_VERTEX_ATTRIBS=mr.getParameter(mr.MAX_VERTEX_ATTRIBS),Ir.MAX_VERTEX_UNIFORM_VECTORS=mr.getParameter(mr.MAX_VERTEX_UNIFORM_VECTORS),Ir.MAX_FRAGMENT_UNIFORM_VECTORS=mr.getParameter(mr.MAX_FRAGMENT_UNIFORM_VECTORS),Ir.MAX_VARYING_VECTORS=mr.getParameter(mr.MAX_VARYING_VECTORS),mr.getSupportedExtensions().forEach((function(e){Ir.SUPPORTED_EXTENSIONS[e]=!0})))}var wr=$.vec3(),gr=new G({}),Tr=function(e,t){this.id=gr.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new sr(t),this._allocate(t)},Er={};Tr.get=function(e){var t=e.scene,n=[t.canvas.canvas.id,(t.gammaInput?"gi;":";")+(t.gammaOutput?"go":""),t._lightsState.getHash(),t._sectionPlanesState.getHash(),e._geometry._state.hash,e._material._state.hash,e._state.drawHash].join(";"),r=Er[n];if(!r){if((r=new Tr(n,e)).errors)return console.log(r.errors.join("\n")),null;Er[n]=r,te.memory.programs++}return r._useCount++,r},Tr.prototype.put=function(){0==--this._useCount&&(gr.removeItem(this.id),this._program&&this._program.destroy(),delete Er[this._hash],te.memory.programs--)},Tr.prototype.webglContextRestored=function(){this._program=null},Tr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=Ir.MAX_TEXTURE_UNITS,r=t.scene,i=t._material,a=r.canvas.gl,s=this._program,o=t._state,l=t._material._state,u=t._geometry._state,c=r.camera,f=t.origin,p=o.background;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,p&&a.depthFunc(a.LEQUAL),this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,f?e.getRTCViewMatrix(o.originHash,f):c.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,c.viewNormalMatrix),o.clippable){var A=r._sectionPlanesState.sectionPlanes.length;if(A>0)for(var d=r._sectionPlanesState.sectionPlanes,v=t.renderFlags,h=0;h0&&(this._uLightMap="lightMap"),i.reflectionMaps.length>0&&(this._uReflectionMap="reflectionMap"),this._uSectionPlanes=[];for(c=0,f=a.sectionPlanes.length;c0&&a.lightMaps[0].texture&&this._uLightMap&&(o.bindTexture(this._uLightMap,a.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++),a.reflectionMaps.length>0&&a.reflectionMaps[0].texture&&this._uReflectionMap&&(o.bindTexture(this._uReflectionMap,a.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%n,e.bindTexture++),this._uGammaFactor&&i.uniform1f(this._uGammaFactor,r.gammaFactor),this._baseTextureUnit=e.textureUnit};var br=P((function e(t){b(this,e),this.vertex=function(e){var t=e.scene,n=t._lightsState,r=function(e){var t=e._geometry._state.primitiveName;if((e._geometry._state.autoVertexNormals||e._geometry._state.normalsBuf)&&("triangles"===t||"triangle-strip"===t||"triangle-fan"===t))return!0;return!1}(e),i=t._sectionPlanesState.sectionPlanes.length>0,a=!!e._geometry._state.compressGeometry,s=e._state.billboard,o=e._state.stationary,l=[];l.push("#version 300 es"),l.push("// EmphasisFillShaderSource vertex shader"),l.push("in vec3 position;"),l.push("uniform mat4 modelMatrix;"),l.push("uniform mat4 viewMatrix;"),l.push("uniform mat4 projMatrix;"),l.push("uniform vec4 colorize;"),l.push("uniform vec3 offset;"),a&&l.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;"));i&&l.push("out vec4 vWorldPosition;");if(l.push("uniform vec4 lightAmbient;"),l.push("uniform vec4 fillColor;"),r){l.push("in vec3 normal;"),l.push("uniform mat4 modelNormalMatrix;"),l.push("uniform mat4 viewNormalMatrix;");for(var u=0,c=n.lights.length;u= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"))}l.push("out vec4 vColor;"),("spherical"===s||"cylindrical"===s)&&(l.push("void billboard(inout mat4 mat) {"),l.push(" mat[0][0] = 1.0;"),l.push(" mat[0][1] = 0.0;"),l.push(" mat[0][2] = 0.0;"),"spherical"===s&&(l.push(" mat[1][0] = 0.0;"),l.push(" mat[1][1] = 1.0;"),l.push(" mat[1][2] = 0.0;")),l.push(" mat[2][0] = 0.0;"),l.push(" mat[2][1] = 0.0;"),l.push(" mat[2][2] =1.0;"),l.push("}"));l.push("void main(void) {"),l.push("vec4 localPosition = vec4(position, 1.0); "),l.push("vec4 worldPosition;"),a&&l.push("localPosition = positionsDecodeMatrix * localPosition;");r&&(a?l.push("vec4 localNormal = vec4(octDecode(normal.xy), 0.0); "):l.push("vec4 localNormal = vec4(normal, 0.0); "),l.push("mat4 modelNormalMatrix2 = modelNormalMatrix;"),l.push("mat4 viewNormalMatrix2 = viewNormalMatrix;"));l.push("mat4 viewMatrix2 = viewMatrix;"),l.push("mat4 modelMatrix2 = modelMatrix;"),o&&l.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===s||"cylindrical"===s?(l.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),l.push("billboard(modelMatrix2);"),l.push("billboard(viewMatrix2);"),l.push("billboard(modelViewMatrix);"),r&&(l.push("mat4 modelViewNormalMatrix = viewNormalMatrix2 * modelNormalMatrix2;"),l.push("billboard(modelNormalMatrix2);"),l.push("billboard(viewNormalMatrix2);"),l.push("billboard(modelViewNormalMatrix);")),l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(l.push("worldPosition = modelMatrix2 * localPosition;"),l.push("worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));r&&l.push("vec3 viewNormal = normalize((viewNormalMatrix2 * modelNormalMatrix2 * localNormal).xyz);");if(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),r)for(var p=0,A=n.lights.length;p0,a=[];a.push("#version 300 es"),a.push("// Lambertian drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));r&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(var s=0,o=n.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}"points"===e._geometry._state.primitiveName&&(a.push("vec2 cxy = 2.0 * gl_PointCoord - 1.0;"),a.push("float r = dot(cxy, cxy);"),a.push("if (r > 1.0) {"),a.push(" discard;"),a.push("}"));t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");r?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(t)}));var Dr=new G({}),Pr=$.vec3(),Rr=function(e,t){this.id=Dr.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new br(t),this._allocate(t)},Cr={};Rr.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.normalsBuf?"n":"",e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Cr[t];return n||(n=new Rr(t,e),Cr[t]=n,te.memory.programs++),n._useCount++,n},Rr.prototype.put=function(){0==--this._useCount&&(Dr.removeItem(this.id),this._program&&this._program.destroy(),delete Cr[this._hash],te.memory.programs--)},Rr.prototype.webglContextRestored=function(){this._program=null},Rr.prototype.drawMesh=function(e,t,n){this._program||this._allocate(t);var r=this._scene,i=r.camera,a=r.canvas.gl,s=0===n?t._xrayMaterial._state:1===n?t._highlightMaterial._state:t._selectedMaterial._state,o=t._state,l=t._geometry._state,u=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),a.uniformMatrix4fv(this._uViewMatrix,!1,u?e.getRTCViewMatrix(o.originHash,u):i.viewMatrix),a.uniformMatrix4fv(this._uViewNormalMatrix,!1,i.viewNormalMatrix),o.clippable){var c=r._sectionPlanesState.sectionPlanes.length;if(c>0)for(var f=r._sectionPlanesState.sectionPlanes,p=t.renderFlags,A=0;A0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Edges drawing vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform vec4 edgeColor;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));n&&s.push("out vec4 vWorldPosition;");s.push("out vec4 vColor;"),("spherical"===i||"cylindrical"===i)&&(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"),s.push("billboard(modelViewMatrix);"),s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));s.push("vColor = edgeColor;"),n&&s.push("vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=e.scene._sectionPlanesState,r=e.scene.gammaOutput,i=n.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Edges drawing fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),t.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;"));r&&(a.push("uniform float gammaFactor;"),a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}"));if(i){a.push("in vec4 vWorldPosition;"),a.push("uniform bool clippable;");for(var s=0,o=n.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}t.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");r?a.push("outColor = linearToGamma(vColor, gammaFactor);"):a.push("outColor = vColor;");return a.push("}"),a}(t)}));var Br=new G({}),Or=$.vec3(),Sr=function(e,t){this.id=Br.addItem({}),this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new _r(t),this._allocate(t)},Nr={};Sr.get=function(e){var t=[e.scene.id,e.scene.gammaOutput?"go":"",e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=Nr[t];return n||(n=new Sr(t,e),Nr[t]=n,te.memory.programs++),n._useCount++,n},Sr.prototype.put=function(){0==--this._useCount&&(Br.removeItem(this.id),this._program&&this._program.destroy(),delete Nr[this._hash],te.memory.programs--)},Sr.prototype.webglContextRestored=function(){this._program=null},Sr.prototype.drawMesh=function(e,t,n){this._program||this._allocate(t);var r,i,a=this._scene,s=a.camera,o=a.canvas.gl,l=t._state,u=t._geometry,c=u._state,f=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),o.uniformMatrix4fv(this._uViewMatrix,!1,f?e.getRTCViewMatrix(l.originHash,f):s.viewMatrix),l.clippable){var p=a._sectionPlanesState.sectionPlanes.length;if(p>0)for(var A=a._sectionPlanesState.sectionPlanes,d=t.renderFlags,v=0;v0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Mesh picking vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("out vec4 vViewPosition;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");n&&s.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("uniform vec2 pickClipPos;"),s.push("vec4 remapClipPos(vec4 clipPos) {"),s.push(" clipPos.xy /= clipPos.w;"),s.push(" clipPos.xy -= pickClipPos;"),s.push(" clipPos.xy *= clipPos.w;"),s.push(" return clipPos;"),s.push("}"),s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"!==i&&"cylindrical"!==i||(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"));s.push(" vec4 worldPosition = modelMatrix2 * localPosition;"),s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix2 * worldPosition;"),n&&s.push(" vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = remapClipPos(clipPos);"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(i.push("uniform vec4 pickColor;"),r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = pickColor; "),i.push("}"),i}(t)}));var xr=$.vec3(),Mr=function(e,t){this._hash=e,this._shaderSource=new Lr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Fr={};Mr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),n=Fr[t];if(!n){if((n=new Mr(t,e)).errors)return console.log(n.errors.join("\n")),null;Fr[t]=n,te.memory.programs++}return n._useCount++,n},Mr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Fr[this._hash],te.memory.programs--)},Mr.prototype.webglContextRestored=function(){this._program=null},Mr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._state,a=t._material._state,s=t._geometry._state,o=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCPickViewMatrix(i.originHash,o):e.pickViewMatrix),i.clippable){var l=n._sectionPlanesState.sectionPlanes.length;if(l>0)for(var u=n._sectionPlanesState.sectionPlanes,c=t.renderFlags,f=0;f>24&255,m=I>>16&255,w=I>>8&255,g=255&I;r.uniform4f(this._uPickColor,g/255,w/255,m/255,y/255),r.uniform2fv(this._uPickClipPos,e.pickClipPos),s.indicesBuf?(r.drawElements(s.primitive,s.indicesBuf.numItems,s.indicesBuf.itemType,0),e.drawElements++):s.positions&&r.drawArrays(r.TRIANGLES,0,s.positions.numItems)},Mr.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new hr(n,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uPositionsDecodeMatrix=r.getLocation("positionsDecodeMatrix"),this._uModelMatrix=r.getLocation("modelMatrix"),this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i0,r=!!e._geometry._state.compressGeometry,i=[];i.push("#version 300 es"),i.push("// Surface picking vertex shader"),i.push("in vec3 position;"),i.push("in vec4 color;"),i.push("uniform mat4 modelMatrix;"),i.push("uniform mat4 viewMatrix;"),i.push("uniform mat4 projMatrix;"),i.push("uniform vec3 offset;"),n&&(i.push("uniform bool clippable;"),i.push("out vec4 vWorldPosition;"));t.logarithmicDepthBufferEnabled&&(i.push("uniform float logDepthBufFC;"),i.push("out float vFragDepth;"),i.push("bool isPerspectiveMatrix(mat4 m) {"),i.push(" return (m[2][3] == - 1.0);"),i.push("}"),i.push("out float isPerspective;"));i.push("uniform vec2 pickClipPos;"),i.push("vec4 remapClipPos(vec4 clipPos) {"),i.push(" clipPos.xy /= clipPos.w;"),i.push(" clipPos.xy -= pickClipPos;"),i.push(" clipPos.xy *= clipPos.w;"),i.push(" return clipPos;"),i.push("}"),i.push("out vec4 vColor;"),r&&i.push("uniform mat4 positionsDecodeMatrix;");i.push("void main(void) {"),i.push("vec4 localPosition = vec4(position, 1.0); "),r&&i.push("localPosition = positionsDecodeMatrix * localPosition;");i.push(" vec4 worldPosition = modelMatrix * localPosition; "),i.push(" worldPosition.xyz = worldPosition.xyz + offset;"),i.push(" vec4 viewPosition = viewMatrix * worldPosition;"),n&&i.push(" vWorldPosition = worldPosition;");i.push(" vColor = color;"),i.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(i.push("vFragDepth = 1.0 + clipPos.w;"),i.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return i.push("gl_Position = remapClipPos(clipPos);"),i.push("}"),i}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Surface picking fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),i.push("in vec4 vColor;"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push(" outColor = vColor;"),i.push("}"),i}(t)}));var Ur=$.vec3(),Gr=function(e,t){this._hash=e,this._scene=t.scene,this._useCount=0,this._shaderSource=new Hr(t),this._allocate(t)},kr={};Gr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.compressGeometry?"cp":"",e._state.hash].join(";"),n=kr[t];if(!n){if((n=new Gr(t,e)).errors)return console.log(n.errors.join("\n")),null;kr[t]=n,te.memory.programs++}return n._useCount++,n},Gr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete kr[this._hash],te.memory.programs--)},Gr.prototype.webglContextRestored=function(){this._program=null},Gr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._state,a=t._material._state,s=t._geometry,o=t._geometry._state,l=t.origin,u=a.backfaces,c=a.frontface,f=n.camera.project,p=s._getPickTrianglePositions(),A=s._getPickTriangleColors();if(this._program.bind(),e.useProgram++,n.logarithmicDepthBufferEnabled){var d=2/(Math.log(f.far+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,d)}if(r.uniformMatrix4fv(this._uViewMatrix,!1,l?e.getRTCPickViewMatrix(i.originHash,l):e.pickViewMatrix),i.clippable){var v=n._sectionPlanesState.sectionPlanes.length;if(v>0)for(var h=n._sectionPlanesState.sectionPlanes,I=t.renderFlags,y=0;y0,r=!!e._geometry._state.compressGeometry,i=e._state.billboard,a=e._state.stationary,s=[];s.push("#version 300 es"),s.push("// Mesh occlusion vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform vec3 offset;"),r&&s.push("uniform mat4 positionsDecodeMatrix;");n&&s.push("out vec4 vWorldPosition;");t.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;"));"spherical"!==i&&"cylindrical"!==i||(s.push("void billboard(inout mat4 mat) {"),s.push(" mat[0][0] = 1.0;"),s.push(" mat[0][1] = 0.0;"),s.push(" mat[0][2] = 0.0;"),"spherical"===i&&(s.push(" mat[1][0] = 0.0;"),s.push(" mat[1][1] = 1.0;"),s.push(" mat[1][2] = 0.0;")),s.push(" mat[2][0] = 0.0;"),s.push(" mat[2][1] = 0.0;"),s.push(" mat[2][2] =1.0;"),s.push("}"));s.push("void main(void) {"),s.push("vec4 localPosition = vec4(position, 1.0); "),s.push("vec4 worldPosition;"),r&&s.push("localPosition = positionsDecodeMatrix * localPosition;");s.push("mat4 viewMatrix2 = viewMatrix;"),s.push("mat4 modelMatrix2 = modelMatrix;"),a&&s.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");"spherical"===i||"cylindrical"===i?(s.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;"),s.push("billboard(modelMatrix2);"),s.push("billboard(viewMatrix2);"),s.push("billboard(modelViewMatrix);"),s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = modelViewMatrix * localPosition;")):(s.push("worldPosition = modelMatrix2 * localPosition;"),s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix2 * worldPosition; "));n&&s.push(" vWorldPosition = worldPosition;");s.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"));return s.push("gl_Position = clipPos;"),s.push("}"),s}(t),this.fragment=function(e){var t=e.scene,n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];i.push("#version 300 es"),i.push("// Mesh occlusion fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),t.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;"));if(r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}i.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),t.logarithmicDepthBufferEnabled&&i.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");return i.push("}"),i}(t)}));var Vr=$.vec3(),Qr=function(e,t){this._hash=e,this._shaderSource=new jr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Wr={};Qr.get=function(e){var t=[e.scene.canvas.canvas.id,e.scene._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.occlusionHash].join(";"),n=Wr[t];if(!n){if((n=new Qr(t,e)).errors)return console.log(n.errors.join("\n")),null;Wr[t]=n,te.memory.programs++}return n._useCount++,n},Qr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Wr[this._hash],te.memory.programs--)},Qr.prototype.webglContextRestored=function(){this._program=null},Qr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene,r=n.canvas.gl,i=t._material._state,a=t._state,s=t._geometry._state,o=t.origin;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),i.id!==this._lastMaterialId){var l=i.backfaces;e.backfaces!==l&&(l?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),e.backfaces=l);var u=i.frontface;e.frontface!==u&&(u?r.frontFace(r.CCW):r.frontFace(r.CW),e.frontface=u),this._lastMaterialId=i.id}var c=n.camera;if(r.uniformMatrix4fv(this._uViewMatrix,!1,o?e.getRTCViewMatrix(a.originHash,o):c.viewMatrix),a.clippable){var f=n._sectionPlanesState.sectionPlanes.length;if(f>0)for(var p=n._sectionPlanesState.sectionPlanes,A=t.renderFlags,d=0;d0,n=!!e._geometry._state.compressGeometry,r=[];r.push("// Mesh shadow vertex shader"),r.push("in vec3 position;"),r.push("uniform mat4 modelMatrix;"),r.push("uniform mat4 shadowViewMatrix;"),r.push("uniform mat4 shadowProjMatrix;"),r.push("uniform vec3 offset;"),n&&r.push("uniform mat4 positionsDecodeMatrix;");t&&r.push("out vec4 vWorldPosition;");r.push("void main(void) {"),r.push("vec4 localPosition = vec4(position, 1.0); "),r.push("vec4 worldPosition;"),n&&r.push("localPosition = positionsDecodeMatrix * localPosition;");r.push("worldPosition = modelMatrix * localPosition;"),r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&r.push("vWorldPosition = worldPosition;");return r.push(" gl_Position = shadowProjMatrix * viewPosition;"),r.push("}"),r}(t),this.fragment=function(e){var t=e.scene;t.canvas.gl;var n=t._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];if(i.push("// Mesh shadow fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),r){i.push("uniform bool clippable;"),i.push("in vec4 vWorldPosition;");for(var a=0;a 0.0) { discard; }"),i.push("}")}return i.push("outColor = encodeFloat(gl_FragCoord.z);"),i.push("}"),i}(t)}));var Kr=function(e,t){this._hash=e,this._shaderSource=new zr(t),this._scene=t.scene,this._useCount=0,this._allocate(t)},Yr={};Kr.get=function(e){var t=e.scene,n=[t.canvas.canvas.id,t._sectionPlanesState.getHash(),e._geometry._state.hash,e._state.hash].join(";"),r=Yr[n];if(!r){if((r=new Kr(n,e)).errors)return console.log(r.errors.join("\n")),null;Yr[n]=r,te.memory.programs++}return r._useCount++,r},Kr.prototype.put=function(){0==--this._useCount&&(this._program&&this._program.destroy(),delete Yr[this._hash],te.memory.programs--)},Kr.prototype.webglContextRestored=function(){this._program=null},Kr.prototype.drawMesh=function(e,t){this._program||this._allocate(t);var n=this._scene.canvas.gl,r=t._material._state,i=t._geometry._state;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),r.id!==this._lastMaterialId){var a=r.backfaces;e.backfaces!==a&&(a?n.disable(n.CULL_FACE):n.enable(n.CULL_FACE),e.backfaces=a);var s=r.frontface;e.frontface!==s&&(s?n.frontFace(n.CCW):n.frontFace(n.CW),e.frontface=s),e.lineWidth!==r.lineWidth&&(n.lineWidth(r.lineWidth),e.lineWidth=r.lineWidth),this._uPointSize&&n.uniform1i(this._uPointSize,r.pointSize),this._lastMaterialId=r.id}if(n.uniformMatrix4fv(this._uModelMatrix,n.FALSE,t.worldMatrix),i.combineGeometry){var o=t.vertexBufs;o.id!==this._lastVertexBufsId&&(o.positionsBuf&&this._aPosition&&(this._aPosition.bindArrayBuffer(o.positionsBuf,o.compressGeometry?n.UNSIGNED_SHORT:n.FLOAT),e.bindArray++),this._lastVertexBufsId=o.id)}this._uClippable&&n.uniform1i(this._uClippable,t._state.clippable),n.uniform3fv(this._uOffset,t._state.offset),i.id!==this._lastGeometryId&&(this._uPositionsDecodeMatrix&&n.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,i.positionsDecodeMatrix),i.combineGeometry?i.indicesBufCombined&&(i.indicesBufCombined.bind(),e.bindArray++):(this._aPosition&&(this._aPosition.bindArrayBuffer(i.positionsBuf,i.compressGeometry?n.UNSIGNED_SHORT:n.FLOAT),e.bindArray++),i.indicesBuf&&(i.indicesBuf.bind(),e.bindArray++)),this._lastGeometryId=i.id),i.combineGeometry?i.indicesBufCombined&&(n.drawElements(i.primitive,i.indicesBufCombined.numItems,i.indicesBufCombined.itemType,0),e.drawElements++):i.indicesBuf?(n.drawElements(i.primitive,i.indicesBuf.numItems,i.indicesBuf.itemType,0),e.drawElements++):i.positions&&(n.drawArrays(n.TRIANGLES,0,i.positions.numItems),e.drawArrays++)},Kr.prototype._allocate=function(e){var t=e.scene,n=t.canvas.gl;if(this._program=new hr(n,this._shaderSource),this._scene=t,this._useCount=0,this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uPositionsDecodeMatrix=r.getLocation("positionsDecodeMatrix"),this._uModelMatrix=r.getLocation("modelMatrix"),this._uShadowViewMatrix=r.getLocation("shadowViewMatrix"),this._uShadowProjMatrix=r.getLocation("shadowProjMatrix"),this._uSectionPlanes={};for(var i=0,a=t._sectionPlanesState.sectionPlanes.length;i0)for(var i,a,s,o=0,l=this._uSectionPlanes.length;o1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).originalSystemId=i.originalSystemId||r.id,r.renderFlags=new Xr,r._state=new ot({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==i.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!i.stationary,background:!!i.background,billboard:r._checkBillboard(i.billboard),layer:null,colorize:null,pickID:r.scene._renderer.getPickID(g(r)),drawHash:"",pickHash:"",offset:$.vec3(),origin:null,originHash:null}),r._drawRenderer=null,r._shadowRenderer=null,r._emphasisFillRenderer=null,r._emphasisEdgesRenderer=null,r._pickMeshRenderer=null,r._pickTriangleRenderer=null,r._occlusionRenderer=null,r._geometry=i.geometry?r._checkComponent2(["ReadableGeometry","VBOGeometry"],i.geometry):r.scene.geometry,r._material=i.material?r._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],i.material):r.scene.material,r._xrayMaterial=i.xrayMaterial?r._checkComponent("EmphasisMaterial",i.xrayMaterial):r.scene.xrayMaterial,r._highlightMaterial=i.highlightMaterial?r._checkComponent("EmphasisMaterial",i.highlightMaterial):r.scene.highlightMaterial,r._selectedMaterial=i.selectedMaterial?r._checkComponent("EmphasisMaterial",i.selectedMaterial):r.scene.selectedMaterial,r._edgeMaterial=i.edgeMaterial?r._checkComponent("EdgeMaterial",i.edgeMaterial):r.scene.edgeMaterial,r._parentNode=null,r._aabb=null,r._aabbDirty=!0,r._numTriangles=r._geometry?r._geometry.numTriangles:0,r.scene._aabbDirty=!0,r._scale=$.vec3(),r._quaternion=$.identityQuaternion(),r._rotation=$.vec3(),r._position=$.vec3(),r._worldMatrix=$.identityMat4(),r._worldNormalMatrix=$.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,r._worldNormalMatrixDirty=!0;var a=i.origin||i.rtcCenter;if(a&&(r._state.origin=$.vec3(a),r._state.originHash=a.join()),i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(g(r)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.layer=i.layer,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.parentId){var s=r.scene.components[i.parentId];s?s.isNode?s.addChild(g(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'"),r._parentNode=s}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(g(r)),r._parentNode=i.parent);return r.compile(),r}return P(n,[{key:"type",get:function(){return"Mesh"}},{key:"isMesh",get:function(){return!0}},{key:"parent",get:function(){return this._parentNode}},{key:"geometry",get:function(){return this._geometry}},{key:"material",get:function(){return this._material}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=$.identityMat4()),$.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix},set:function(e){this.__localMatrix||(this.__localMatrix=$.identityMat4()),this.__localMatrix.set(e||ai),$.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._state.origin},set:function(e){e?(this._state.origin||(this._state.origin=$.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._state.visible},set:function(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}},{key:"xrayed",get:function(){return this._state.xrayed},set:function(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}},{key:"highlighted",get:function(){return this._state.highlighted},set:function(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}},{key:"selected",get:function(){return this._state.selected},set:function(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}},{key:"culled",get:function(){return this._state.culled},set:function(e){this._state.culled=!!e,this.glRedraw()}},{key:"clippable",get:function(){return this._state.clippable},set:function(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}},{key:"collidable",get:function(){return this._state.collidable},set:function(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"pickable",get:function(){return this._state.pickable},set:function(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._state.receivesShadow},set:function(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}},{key:"saoEnabled",get:function(){return!1}},{key:"colorize",get:function(){return this._state.colorize},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);var n=!!e;this.scene._objectColorizeUpdated(this,n),this.glRedraw()}},{key:"opacity",get:function(){return this._state.colorize[3]},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1);var n=null!=e;t[3]=n?e:1,this.scene._objectOpacityUpdated(this,n),this.glRedraw()}},{key:"transparent",get:function(){return 2===this._material.alphaMode||this._state.colorize[3]<1}},{key:"layer",get:function(){return this._state.layer},set:function(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}},{key:"stationary",get:function(){return this._state.stationary}},{key:"billboard",get:function(){return this._state.billboard}},{key:"offset",get:function(){return this._state.offset},set:function(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!0}},{key:"xrayMaterial",get:function(){return this._xrayMaterial}},{key:"highlightMaterial",get:function(){return this._highlightMaterial}},{key:"selectedMaterial",get:function(){return this._selectedMaterial}},{key:"edgeMaterial",get:function(){return this._edgeMaterial}},{key:"_checkBillboard",value:function(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}},{key:"compile",value:function(){var e=this._makeDrawHash();this._state.drawHash!==e&&(this._state.drawHash=e,this._putDrawRenderers(),this._drawRenderer=Tr.get(this),this._emphasisFillRenderer=Rr.get(this),this._emphasisEdgesRenderer=Sr.get(this));var t=this._makePickHash();if(this._state.pickHash!==t&&(this._state.pickHash=t,this._putPickRenderers(),this._pickMeshRenderer=Mr.get(this)),this._state.occluder){var n=this._makeOcclusionHash();this._state.occlusionHash!==n&&(this._state.occlusionHash=n,this._putOcclusionRenderer(),this._occlusionRenderer=Qr.get(this))}}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)$.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t0)for(var n=0;n-1){var x=B.geometry._state,M=B.scene,F=M.camera,H=M.canvas;if("triangles"===x.primitiveName){N.primitive="triangle";var U,G,k,j=L,V=x.indices,Q=x.positions;if(V){var W=V[j+0],z=V[j+1],K=V[j+2];a[0]=W,a[1]=z,a[2]=K,N.indices=a,U=3*W,G=3*z,k=3*K}else k=(G=(U=3*j)+3)+3;if(n[0]=Q[U+0],n[1]=Q[U+1],n[2]=Q[U+2],r[0]=Q[G+0],r[1]=Q[G+1],r[2]=Q[G+2],i[0]=Q[k+0],i[1]=Q[k+1],i[2]=Q[k+2],x.compressGeometry){var Y=x.positionsDecodeMatrix;Y&&(ht.decompressPosition(n,Y,n),ht.decompressPosition(r,Y,r),ht.decompressPosition(i,Y,i))}N.canvasPos?$.canvasPosToLocalRay(H.canvas,B.origin?ye(O,B.origin):O,S,B.worldMatrix,N.canvasPos,e,t):N.origin&&N.direction&&$.worldRayToLocalRay(B.worldMatrix,N.origin,N.direction,e,t),$.normalizeVec3(t),$.rayPlaneIntersect(e,t,n,r,i,s),N.localPos=s,N.position=s,h[0]=s[0],h[1]=s[1],h[2]=s[2],h[3]=1,$.transformVec4(B.worldMatrix,h,I),o[0]=I[0],o[1]=I[1],o[2]=I[2],N.canvasPos&&B.origin&&(o[0]+=B.origin[0],o[1]+=B.origin[1],o[2]+=B.origin[2]),N.worldPos=o,$.transformVec4(F.matrix,I,y),l[0]=y[0],l[1]=y[1],l[2]=y[2],N.viewPos=l,$.cartesianToBarycentric(s,n,r,i,u),N.bary=u;var X=x.normals;if(X){if(x.compressGeometry){var q=3*W,J=3*z,Z=3*K;ht.decompressNormal(X.subarray(q,q+2),c),ht.decompressNormal(X.subarray(J,J+2),f),ht.decompressNormal(X.subarray(Z,Z+2),p)}else c[0]=X[U],c[1]=X[U+1],c[2]=X[U+2],f[0]=X[G],f[1]=X[G+1],f[2]=X[G+2],p[0]=X[k],p[1]=X[k+1],p[2]=X[k+2];var ee=$.addVec3($.addVec3($.mulVec3Scalar(c,u[0],m),$.mulVec3Scalar(f,u[1],w),g),$.mulVec3Scalar(p,u[2],T),E);N.worldNormal=$.normalizeVec3($.transformVec3(B.worldNormalMatrix,ee,b))}var te=x.uv;if(te){if(A[0]=te[2*W],A[1]=te[2*W+1],d[0]=te[2*z],d[1]=te[2*z+1],v[0]=te[2*K],v[1]=te[2*K+1],x.compressGeometry){var ne=x.uvDecodeMatrix;ne&&(ht.decompressUV(A,ne,A),ht.decompressUV(d,ne,d),ht.decompressUV(v,ne,v))}N.uv=$.addVec3($.addVec3($.mulVec2Scalar(A,u[0],D),$.mulVec2Scalar(d,u[1],P),R),$.mulVec2Scalar(v,u[2],C),_)}}}}}(),li=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),r=t.call(this,e,i),te.memory.materials++,r}return P(n,[{key:"type",get:function(){return"Material"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),te.memory.materials--}}]),n}(),ui={opaque:0,mask:1,blend:2},ci=["opaque","mask","blend"],fi=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"PhongMaterial",ambient:$.vec3([1,1,1]),diffuse:$.vec3([1,1,1]),specular:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.ambient=i.ambient,r.diffuse=i.diffuse,r.specular=i.specular,r.emissive=i.emissive,r.alpha=i.alpha,r.shininess=i.shininess,r.reflectivity=i.reflectivity,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,i.ambientMap&&(r._ambientMap=r._checkComponent("Texture",i.ambientMap)),i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.reflectivityMap&&(r._reflectivityMap=r._checkComponent("Texture",i.reflectivityMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.diffuseFresnel&&(r._diffuseFresnel=r._checkComponent("Fresnel",i.diffuseFresnel)),i.specularFresnel&&(r._specularFresnel=r._checkComponent("Fresnel",i.specularFresnel)),i.emissiveFresnel&&(r._emissiveFresnel=r._checkComponent("Fresnel",i.emissiveFresnel)),i.alphaFresnel&&(r._alphaFresnel=r._checkComponent("Fresnel",i.alphaFresnel)),i.reflectivityFresnel&&(r._reflectivityFresnel=r._checkComponent("Fresnel",i.reflectivityFresnel)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"PhongMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"shininess",get:function(){return this._state.shininess},set:function(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"reflectivity",get:function(){return this._state.reflectivity},set:function(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}},{key:"normalMap",get:function(){return this._normalMap}},{key:"ambientMap",get:function(){return this._ambientMap}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specularMap",get:function(){return this._specularMap}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"reflectivityMap",get:function(){return this._reflectivityMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"diffuseFresnel",get:function(){return this._diffuseFresnel}},{key:"specularFresnel",get:function(){return this._specularFresnel}},{key:"emissiveFresnel",get:function(){return this._emissiveFresnel}},{key:"alphaFresnel",get:function(){return this._alphaFresnel}},{key:"reflectivityFresnel",get:function(){return this._reflectivityFresnel}},{key:"alphaMode",get:function(){return ci[this._state.alphaMode]},set:function(e){var t=ui[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function pi(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var n;switch(t){case"WEBGL_depth_texture":n=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=e.getExtension(t)}return e._cachedExtensions[t]=n,n}function Ai(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===r){var a=pi(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===a)return null;if(33776===i)return a.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(n=pi(e,"WEBGL_compressed_texture_s3tc")))return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){var s=pi(e,"WEBGL_compressed_texture_pvrtc");if(null===s)return null;if(35840===i)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){var o=pi(e,"WEBGL_compressed_texture_etc1");return null!==o?o.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){var l=pi(e,"WEBGL_compressed_texture_etc");if(null===l)return null;if(37492===i)return 3001===r?l.COMPRESSED_SRGB8_ETC2:l.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===r?l.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:l.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){var u=pi(e,"WEBGL_compressed_texture_astc");if(null===u)return null;if(37808===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:u.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:u.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:u.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:u.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:u.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:u.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:u.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:u.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:u.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:u.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:u.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:u.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:u.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:u.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){var c=pi(e,"EXT_texture_compression_bptc");if(null===c)return null;if(36492===i)return 3001===r?c.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:c.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}var di=new Uint8Array([0,0,0,1]),vi=function(){function e(t){var n=t.gl,r=t.target,i=t.format,a=t.type,s=t.wrapS,o=t.wrapT,l=t.wrapR,u=t.encoding,c=t.preloadColor,f=t.premultiplyAlpha,p=t.flipY;b(this,e),this.gl=n,this.target=r||n.TEXTURE_2D,this.format=i||1023,this.type=a||1009,this.internalFormat=null,this.premultiplyAlpha=!!f,this.flipY=!!p,this.unpackAlignment=4,this.wrapS=s||1e3,this.wrapT=o||1e3,this.wrapR=l||1e3,this.encoding=u||3001,this.texture=n.createTexture(),c&&this.setPreloadColor(c),this.allocated=!0}return P(e,[{key:"setPreloadColor",value:function(e){e?(di[0]=Math.floor(255*e[0]),di[1]=Math.floor(255*e[1]),di[2]=Math.floor(255*e[2]),di[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(di[0]=0,di[1]=0,di[2]=0,di[3]=255);var t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP)for(var n=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],r=0,i=n.length;r1&&void 0!==arguments[1]?arguments[1]:{},n=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);var r=!1;n.bindTexture(this.target,this.texture);var i=n.getParameter(n.UNPACK_FLIP_Y_WEBGL);n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,this.flipY);var a=n.getParameter(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL);n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);var s=n.getParameter(n.UNPACK_ALIGNMENT);n.pixelStorei(n.UNPACK_ALIGNMENT,this.unpackAlignment);var o=n.getParameter(n.UNPACK_COLORSPACE_CONVERSION_WEBGL);n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,n.NONE);var l=Ai(n,this.minFilter);n.texParameteri(this.target,n.TEXTURE_MIN_FILTER,l),l!==n.NEAREST_MIPMAP_NEAREST&&l!==n.LINEAR_MIPMAP_NEAREST&&l!==n.NEAREST_MIPMAP_LINEAR&&l!==n.LINEAR_MIPMAP_LINEAR||(r=!0);var u=Ai(n,this.magFilter);u&&n.texParameteri(this.target,n.TEXTURE_MAG_FILTER,u);var c=Ai(n,this.wrapS);c&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,c);var f=Ai(n,this.wrapT);f&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,f);var p=Ai(n,this.format,this.encoding),A=Ai(n,this.type),d=hi(n,this.internalFormat,p,A,this.encoding,!1);if(this.target===n.TEXTURE_CUBE_MAP){if(se.isArray(e))for(var v=e,h=[n.TEXTURE_CUBE_MAP_POSITIVE_X,n.TEXTURE_CUBE_MAP_NEGATIVE_X,n.TEXTURE_CUBE_MAP_POSITIVE_Y,n.TEXTURE_CUBE_MAP_NEGATIVE_Y,n.TEXTURE_CUBE_MAP_POSITIVE_Z,n.TEXTURE_CUBE_MAP_NEGATIVE_Z],I=0,y=h.length;I1;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);var o=Ai(i,this.wrapS);o&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,o);var l=Ai(i,this.wrapT);if(l&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,l),this.type===i.TEXTURE_3D||this.type===i.TEXTURE_2D_ARRAY){var u=Ai(i,this.wrapR);u&&i.texParameteri(this.target,i.TEXTURE_WRAP_R,u),i.texParameteri(this.type,i.TEXTURE_WRAP_R,u)}s?(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Ii(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ii(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Ai(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ai(i,this.magFilter)));var c=Ai(i,this.format,this.encoding),f=Ai(i,this.type),p=hi(i,this.internalFormat,c,f,this.encoding,!1);i.texStorage2D(i.TEXTURE_2D,a,p,t[0].width,t[0].height);for(var A=0,d=t.length;A5&&void 0!==arguments[5]&&arguments[5];if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}var s=n;return n===e.RED&&(r===e.FLOAT&&(s=e.R32F),r===e.HALF_FLOAT&&(s=e.R16F),r===e.UNSIGNED_BYTE&&(s=e.R8)),n===e.RG&&(r===e.FLOAT&&(s=e.RG32F),r===e.HALF_FLOAT&&(s=e.RG16F),r===e.UNSIGNED_BYTE&&(s=e.RG8)),n===e.RGBA&&(r===e.FLOAT&&(s=e.RGBA32F),r===e.HALF_FLOAT&&(s=e.RGBA16F),r===e.UNSIGNED_BYTE&&(s=3001===i&&!1===a?e.SRGB8_ALPHA8:e.RGBA8),r===e.UNSIGNED_SHORT_4_4_4_4&&(s=e.RGBA4),r===e.UNSIGNED_SHORT_5_5_5_1&&(s=e.RGB5_A1)),s!==e.R16F&&s!==e.R32F&&s!==e.RG16F&&s!==e.RG32F&&s!==e.RGBA16F&&s!==e.RGBA32F||pi(e,"EXT_color_buffer_float"),s}function Ii(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function yi(e){if(!mi(e.width)||!mi(e.height)){var t=document.createElement("canvas");t.width=wi(e.width),t.height=wi(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function mi(e){return 0==(e&e-1)}function wi(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var gi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({texture:new vi({gl:r.scene.canvas.gl}),matrix:$.identityMat4(),hasMatrix:i.translate&&(0!==i.translate[0]||0!==i.translate[1])||!!i.rotate||i.scale&&(0!==i.scale[0]||0!==i.scale[1]),minFilter:r._checkMinFilter(i.minFilter),magFilter:r._checkMagFilter(i.magFilter),wrapS:r._checkWrapS(i.wrapS),wrapT:r._checkWrapT(i.wrapT),flipY:r._checkFlipY(i.flipY),encoding:r._checkEncoding(i.encoding)}),r._src=null,r._image=null,r._translate=$.vec2([0,0]),r._scale=$.vec2([1,1]),r._rotate=$.vec2([0,0]),r._matrixDirty=!1,r.translate=i.translate,r.scale=i.scale,r.rotate=i.rotate,i.src?r.src=i.src:i.image&&(r.image=i.image),te.memory.textures++,r}return P(n,[{key:"type",get:function(){return"Texture"}},{key:"_checkMinFilter",value:function(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}},{key:"_checkMagFilter",value:function(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}},{key:"_checkWrapS",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkWrapT",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this._state.texture=new vi({gl:this.scene.canvas.gl}),this._image?this.image=this._image:this._src&&(this.src=this._src)}},{key:"_update",value:function(){var e,t,n=this._state;this._matrixDirty&&(0===this._translate[0]&&0===this._translate[1]||(e=$.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(t=$.scalingMat4v([this._scale[0],this._scale[1],1]),e=e?$.mulMat4(e,t):t),0!==this._rotate&&(t=$.rotationMat4v(.0174532925*this._rotate,[0,0,1]),e=e?$.mulMat4(e,t):t),e&&(n.matrix=e),this._matrixDirty=!1);this.glRedraw()}},{key:"image",get:function(){return this._image},set:function(e){this._image=yi(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}},{key:"src",get:function(){return this._src},set:function(e){this.scene.loading++,this.scene.canvas.spinner.processes++;var t=this,n=new Image;n.onload=function(){n=yi(n),t._state.texture.setImage(n,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},n.src=e,this._src=e,this._image=null}},{key:"translate",get:function(){return this._translate},set:function(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}},{key:"rotate",get:function(){return this._rotate},set:function(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}},{key:"minFilter",get:function(){return this._state.minFilter}},{key:"magFilter",get:function(){return this._state.magFilter}},{key:"wrapS",get:function(){return this._state.wrapS}},{key:"wrapT",get:function(){return this._state.wrapT}},{key:"flipY",get:function(){return this._state.flipY}},{key:"encoding",get:function(){return this._state.encoding}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),te.memory.textures--}}]),n}(),Ti=$.vec3(),Ei=$.vec3();$.vec3();var bi=$.vec3([0,-1,0]),Di=$.vec4([0,0,0,1]),Pi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new gi(g(r)),r._plane=new si(g(r),{geometry:new mt(g(r),Bt({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new fi(g(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new si(g(r),{geometry:new mt(g(r),_t({size:1,divisions:10})),material:new fi(g(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new Qt(g(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),me(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,n=[-this._dir[0],-this._dir[1],-this._dir[2]];$.subVec3(t,this.position,Ti);var r=-$.dotVec3(n,Ti);$.normalizeVec3(n),$.mulVec3Scalar(n,r,Ei),$.vec3PairToQuaternion(bi,e,Di),this._node.quaternion=Di}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),Ri=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"LambertMaterial",ambient:$.vec3([1,1,1]),color:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),r.ambient=i.ambient,r.color=i.color,r.emissive=i.emissive,r.alpha=i.alpha,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r.backfaces=i.backfaces,r.frontface=i.frontface,r}return P(n,[{key:"type",get:function(){return"LambertMaterial"}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){var t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ci={opaque:0,mask:1,blend:2},_i=["opaque","mask","blend"],Bi=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"MetallicMaterial",baseColor:$.vec4([1,1,1]),emissive:$.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.baseColor=i.baseColor,r.metallic=i.metallic,r.roughness=i.roughness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.baseColorMap&&(r._baseColorMap=r._checkComponent("Texture",i.baseColorMap)),i.metallicMap&&(r._metallicMap=r._checkComponent("Texture",i.metallicMap)),i.roughnessMap&&(r._roughnessMap=r._checkComponent("Texture",i.roughnessMap)),i.metallicRoughnessMap&&(r._metallicRoughnessMap=r._checkComponent("Texture",i.metallicRoughnessMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"MetallicMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"baseColor",get:function(){return this._state.baseColor},set:function(e){var t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"baseColorMap",get:function(){return this._baseColorMap}},{key:"metallic",get:function(){return this._state.metallic},set:function(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}},{key:"metallicMap",get:function(){return this._attached.metallicMap}},{key:"roughness",get:function(){return this._state.roughness},set:function(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}},{key:"roughnessMap",get:function(){return this._attached.roughnessMap}},{key:"metallicRoughnessMap",get:function(){return this._attached.metallicRoughnessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._attached.emissiveMap}},{key:"occlusionMap",get:function(){return this._attached.occlusionMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._attached.alphaMap}},{key:"normalMap",get:function(){return this._attached.normalMap}},{key:"alphaMode",get:function(){return _i[this._state.alphaMode]},set:function(e){var t=Ci[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Oi={opaque:0,mask:1,blend:2},Si=["opaque","mask","blend"],Ni=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"SpecularMaterial",diffuse:$.vec3([1,1,1]),emissive:$.vec3([0,0,0]),specular:$.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.diffuse=i.diffuse,r.specular=i.specular,r.glossiness=i.glossiness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.glossinessMap&&(r._glossinessMap=r._checkComponent("Texture",i.glossinessMap)),i.specularGlossinessMap&&(r._specularGlossinessMap=r._checkComponent("Texture",i.specularGlossinessMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"SpecularMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specularMap",get:function(){return this._specularMap}},{key:"specularGlossinessMap",get:function(){return this._specularGlossinessMap}},{key:"glossiness",get:function(){return this._state.glossiness},set:function(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}},{key:"glossinessMap",get:function(){return this._glossinessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"normalMap",get:function(){return this._normalMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"alphaMode",get:function(){return Si[this._state.alphaMode]},set:function(e){var t=Oi[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Li={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}},xi=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),r._preset="default",i.preset?(r.preset=i.preset,void 0!==i.fill&&(r.fill=i.fill),i.fillColor&&(r.fillColor=i.fillColor),void 0!==i.fillAlpha&&(r.fillAlpha=i.fillAlpha),void 0!==i.edges&&(r.edges=i.edges),i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth),void 0!==i.backfaces&&(r.backfaces=i.backfaces),void 0!==i.glowThrough&&(r.glowThrough=i.glowThrough)):(r.fill=i.fill,r.fillColor=i.fillColor,r.fillAlpha=i.fillAlpha,r.edges=i.edges,r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth,r.backfaces=i.backfaces,r.glowThrough=i.glowThrough),r}return P(n,[{key:"type",get:function(){return"EmphasisMaterial"}},{key:"presets",get:function(){return Li}},{key:"fill",get:function(){return this._state.fill},set:function(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}},{key:"fillColor",get:function(){return this._state.fillColor},set:function(e){var t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}},{key:"fillAlpha",get:function(){return this._state.fillAlpha},set:function(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"glowThrough",get:function(){return this._state.glowThrough},set:function(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Li[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Li).join(", "))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Mi={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}},Fi=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),r._preset="default",i.preset?(r.preset=i.preset,i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth)):(r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth),r.edges=!1!==i.edges,r}return P(n,[{key:"type",get:function(){return"EdgeMaterial"}},{key:"presets",get:function(){return Mi}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Mi[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Mi).join(", "))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Hi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({edgeColor:$.vec3([0,0,0]),centerColor:$.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),r.edgeColor=i.edgeColor,r.centerColor=i.centerColor,r.edgeBias=i.edgeBias,r.centerBias=i.centerBias,r.power=i.power,r}return P(n,[{key:"type",get:function(){return"Fresnel"}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}},{key:"centerColor",get:function(){return this._state.centerColor},set:function(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}},{key:"edgeBias",get:function(){return this._state.edgeBias},set:function(e){this._state.edgeBias=e||0,this.glRedraw()}},{key:"centerBias",get:function(){return this._state.centerBias},set:function(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}},{key:"power",get:function(){return this._state.power},set:function(e){this._state.power=null!=e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ui=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._type=i.type||(i.src?i.src.split(".").pop():null)||"jpg",r._pos=$.vec3(i.pos||[0,0,0]),r._up=$.vec3(i.up||[0,1,0]),r._normal=$.vec3(i.normal||[0,0,1]),r._height=i.height||1,r._origin=$.vec3(),r._rtcPos=$.vec3(),r._imageSize=$.vec2(),r._texture=new gi(g(r)),r._image=new Image,"jpg"!==r._type&&"png"!==r._type&&(r.error('Unsupported type - defaulting to "jpg"'),r._type="jpg"),r._node=new Qt(g(r),{matrix:$.inverseMat4($.lookAtMat4v(r._pos,$.subVec3(r._pos,r._normal,$.mat4()),r._up,$.mat4())),children:[r._bitmapMesh=new si(g(r),{scale:[1,1,1],rotation:[-90,0,0],collidable:i.collidable,pickable:i.pickable,opacity:i.opacity,clippable:i.clippable,geometry:new mt(g(r),Bt({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new fi(g(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0})})]}),i.image?r.image=i.image:i.src?r.src=i.src:i.imageData&&(r.imageData=i.imageData),r.scene._bitmapCreated(g(r)),r}return P(n,[{key:"visible",get:function(){return this._bitmapMesh.visible},set:function(e){this._bitmapMesh.visible=e}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}},{key:"src",get:function(){return this._image.src},set:function(e){var t=this;if(e)switch(this._image.onload=function(){t._texture.image=t._image,t._imageSize[0]=t._image.width,t._imageSize[1]=t._image.height,t._updateBitmapMeshScale()},this._image.src=e,e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}},{key:"imageData",get:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")},set:function(e){var t=this;this._image.onload=function(){t._texture.image=image,t._imageSize[0]=image.width,t._imageSize[1]=image.height,t._updateBitmapMeshScale()},this._image.src=e}},{key:"type",get:function(){return this._type},set:function(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}},{key:"pos",get:function(){return this._pos}},{key:"normal",get:function(){return this._normal}},{key:"up",get:function(){return this._up}},{key:"height",get:function(){return this._height},set:function(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}},{key:"collidable",get:function(){return this._bitmapMesh.collidable},set:function(e){this._bitmapMesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._bitmapMesh.clippable},set:function(e){this._bitmapMesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._bitmapMesh.pickable},set:function(e){this._bitmapMesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._bitmapMesh.opacity},set:function(e){this._bitmapMesh.opacity=e}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._bitmapDestroyed(this)}},{key:"_updateBitmapMeshScale",value:function(){var e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height*e,1,this._height]}}]),n}(),Gi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e,i))._positions=i.positions||[],r._origin=$.vec3(i.origin||[0,0,0]),i.indices)r._indices=i.indices;else{r._indices=[];for(var a=0,s=r._positions.length/3-1;a1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n,[{key:"type",get:function(){return"Light"}},{key:"isLight",get:function(){return!0}}]),n}(),ji=function(e){I(n,ki);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state={type:"ambient",color:$.vec3([.7,.7,.7]),intensity:1},r.color=i.color,r.intensity=i.intensity,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"AmbientLight"}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lightDestroyed(this)}}]),n}(),Vi=function(){function e(t,n,r){b(this,e),r=r||{},this.gl=n,this.allocated=!1,this.canvas=t,this.buffer=null,this.bound=!1,this.size=r.size,this._hasDepthTexture=!!r.depthTexture}return P(e,[{key:"setSize",value:function(e){this.size=e}},{key:"webglContextRestored",value:function(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}},{key:"bind",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(this._touch(e),!this.bound){var t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"_touch",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=this.gl;if(this.size?(e=this.size[0],t=this.size[1]):(e=r.drawingBufferWidth,t=r.drawingBufferHeight),this.buffer){if(this.buffer.width===e&&this.buffer.height===t)return;r.deleteTexture(this.buffer.texture),r.deleteFramebuffer(this.buffer.framebuf),r.deleteRenderbuffer(this.buffer.renderbuf)}var i,a=r.createTexture();r.bindTexture(r.TEXTURE_2D,a),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),n?r.texStorage2D(r.TEXTURE_2D,1,n,e,t):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),this._hasDepthTexture&&(i=r.createTexture(),r.bindTexture(r.TEXTURE_2D,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.DEPTH_COMPONENT32F,e,t,0,r.DEPTH_COMPONENT,r.FLOAT,null));var s=r.createRenderbuffer();r.bindRenderbuffer(r.RENDERBUFFER,s),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT32F,e,t);var o=r.createFramebuffer();if(r.bindFramebuffer(r.FRAMEBUFFER,o),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,a,0),this._hasDepthTexture?r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,i,0):r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,s),r.bindTexture(r.TEXTURE_2D,null),r.bindRenderbuffer(r.RENDERBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,o),!r.isFramebuffer(o))throw"Invalid framebuffer";r.bindFramebuffer(r.FRAMEBUFFER,null);var l=r.checkFramebufferStatus(r.FRAMEBUFFER);switch(l){case r.FRAMEBUFFER_COMPLETE:break;case r.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case r.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+l}this.buffer={framebuf:o,renderbuf:s,texture:a,depthTexture:i,width:e,height:t},this.bound=!1}},{key:"clear",value:function(){if(!this.bound)throw"Render buffer not bound";var e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}},{key:"read",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,s=e,o=this.buffer.height?this.buffer.height-t-1:this.gl.drawingBufferHeight-t,l=new i(a),u=this.gl;return u.readPixels(s,o,1,1,n||u.RGBA,r||u.UNSIGNED_BYTE,l,0),l}},{key:"readArray",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Uint8Array,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:4,i=new n(this.buffer.width*this.buffer.height*r),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}},{key:"readImageAsCanvas",value:function(){var e=this.gl,t=this._getImageDataCache(),n=t.pixelData,r=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,n);for(var s=this.buffer.width,o=this.buffer.height,l=o/2|0,u=4*s,c=new Uint8Array(4*s),f=0;f0&&void 0!==arguments[0]?arguments[0]:Uint8Array,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,n=this.buffer.width,r=this.buffer.height,i=this._imageDataCache;if(i&&(i.width===n&&i.height===r||(this._imageDataCache=null,i=null)),!i){var a=document.createElement("canvas"),s=a.getContext("2d");a.width=n,a.height=r,i={pixelData:new e(n*r*t),canvas:a,context:s,imageData:s.createImageData(n,r),width:n,height:r},this._imageDataCache=i}return i.context.resetTransform(),i}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"getTexture",value:function(){var e=this;return this._texture||(this._texture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.texture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.texture),!0)},unbind:function(t){e.buffer&&e.buffer.texture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"hasDepthTexture",value:function(){return this._hasDepthTexture}},{key:"getDepthTexture",value:function(){if(!this._hasDepthTexture)return null;var e=this;return this._depthTexture||(this._dethTexture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.depthTexture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.depthTexture),!0)},unbind:function(t){e.buffer&&e.buffer.depthTexture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"destroy",value:function(){if(this.allocated){var e=this.gl;e.deleteTexture(this.buffer.texture),e.deleteTexture(this.buffer.depthTexture),e.deleteFramebuffer(this.buffer.framebuf),e.deleteRenderbuffer(this.buffer.renderbuf),this.allocated=!1,this.buffer=null,this.bound=!1}this._imageDataCache=null,this._texture=null,this._depthTexture=null}}]),e}(),Qi=function(e){I(n,ki);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var a=r.scene.camera,s=r.scene.canvas;return r._onCameraViewMatrix=a.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=a.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=s.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new ot({type:"dir",dir:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(r._shadowViewMatrixDirty){r._shadowViewMatrix||(r._shadowViewMatrix=$.identityMat4());var e=r.scene.camera,t=r._state.dir,n=e.look,i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]];$.lookAtMat4v(i,n,[0,1,0],r._shadowViewMatrix),r._shadowViewMatrixDirty=!1}return r._shadowViewMatrix},getShadowProjMatrix:function(){return r._shadowProjMatrixDirty&&(r._shadowProjMatrix||(r._shadowProjMatrix=$.identityMat4()),$.orthoMat4c(-40,40,-40,40,-40,80,r._shadowProjMatrix),r._shadowProjMatrixDirty=!1),r._shadowProjMatrix},getShadowRenderBuf:function(){return r._shadowRenderBuf||(r._shadowRenderBuf=new Vi(r.scene.canvas.canvas,r.scene.canvas.gl,{size:[1024,1024]})),r._shadowRenderBuf}}),r.dir=i.dir,r.color=i.color,r.intensity=i.intensity,r.castsShadow=i.castsShadow,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"DirLight"}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}(),Wi=function(e){I(n,ki);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=g(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new ot({type:"point",pos:$.vec3([1,1,1]),color:$.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(a._shadowViewMatrixDirty){a._shadowViewMatrix||(a._shadowViewMatrix=$.identityMat4());var e=a._state.pos,t=s.look,n=s.up;$.lookAtMat4v(e,t,n,a._shadowViewMatrix),a._shadowViewMatrixDirty=!1}return a._shadowViewMatrix},getShadowProjMatrix:function(){if(a._shadowProjMatrixDirty){a._shadowProjMatrix||(a._shadowProjMatrix=$.identityMat4());var e=a.scene.canvas.canvas;$.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,a._shadowProjMatrix),a._shadowProjMatrixDirty=!1}return a._shadowProjMatrix},getShadowRenderBuf:function(){return a._shadowRenderBuf||(a._shadowRenderBuf=new Vi(a.scene.canvas.canvas,a.scene.canvas.gl,{size:[1024,1024]})),a._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function zi(e){return 0==(e&e-1)}function Ki(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var Yi=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n);var a=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new ot({texture:new vi({gl:a,target:a.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),te.memory.textures++,r}return P(n,[{key:"type",get:function(){return"CubeTexture"}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_webglContextRestored",value:function(){this.scene.canvas.gl,this._state.texture=null,this._src&&this._loadSrc(this._src)}},{key:"_loadSrc",value:function(e){var t=this,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,a=function(a){var s=new Image;s.onload=function(){var e=s,o=a;return function(){if(!r&&(e=function(e){if(!zi(e.width)||!zi(e.height)){var t=document.createElement("canvas");t.width=Ki(e.width),t.height=Ki(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(e),t._images[o]=e,6===++i)){var a=t._state.texture;a||(a=new vi({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=a),a.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}}(),s.onerror=function(){r=!0},s.src=e[a]},s=0;s1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),qi=function(e){I(n,Yi);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).scene._lightMapCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),Ji=function(e){I(n,He);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._src=null,r._image=null,r._pos=$.vec3(),r._origin=$.vec3(),r._rtcPos=$.vec3(),r._dir=$.vec3(),r._size=1,r._imageSize=$.vec2(),r._texture=new gi(g(r),{src:i.src}),r._geometry=new mt(g(r),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),r._mesh=new si(g(r),{geometry:r._geometry,material:new fi(g(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return P(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,v(T(n.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),Zi=$.vec3(),$i=$.vec3(),ea=$.mat4(),ta=function(){function e(){b(this,e),this.normal=$.vec3(),this.offset=0,this.testVertex=$.vec3()}return P(e,[{key:"set",value:function(e,t,n,r){var i=1/Math.sqrt(e*e+t*t+n*n);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=n*i,this.offset=r*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}]),e}(),na=P((function e(){b(this,e),this.planes=[new ta,new ta,new ta,new ta,new ta,new ta]}));function ra(e,t,n){var r=$.mulMat4(n,t,ea),i=r[0],a=r[1],s=r[2],o=r[3],l=r[4],u=r[5],c=r[6],f=r[7],p=r[8],A=r[9],d=r[10],v=r[11],h=r[12],I=r[13],y=r[14],m=r[15];e.planes[0].set(o-i,f-l,v-p,m-h),e.planes[1].set(o+i,f+l,v+p,m+h),e.planes[2].set(o-a,f-u,v-A,m-I),e.planes[3].set(o+a,f+u,v+A,m+I),e.planes[4].set(o-s,f-c,v-d,m-y),e.planes[5].set(o+s,f+c,v+d,m+y)}function ia(e,t){var n=na.INSIDE,r=Zi,i=$i;r[0]=t[0],r[1]=t[1],r[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];for(var a=[r,i],s=0;s<6;++s){var o=e.planes[s];if(o.normal[0]*a[o.testVertex[0]][0]+o.normal[1]*a[o.testVertex[1]][1]+o.normal[2]*a[o.testVertex[2]][2]+o.offset<0)return na.OUTSIDE;o.normal[0]*a[1-o.testVertex[0]][0]+o.normal[1]*a[1-o.testVertex[1]][1]+o.normal[2]*a[1-o.testVertex[2]][2]+o.offset<0&&(n=na.INTERSECT)}return n}na.INSIDE=0,na.INTERSECT=1,na.OUTSIDE=2;var aa=function(){function e(t){b(this,e),this._eye=$.vec3(),this._look=$.vec3(),this._up=$.vec3(),this._projection={},t&&this.saveCamera(t)}return P(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),sa=$.vec3(),oa=function(){function e(t){if(b(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var n=t.metaScene.scene;this.saveObjects(n,t)}}return P(e,[{key:"saveObjects",value:function(e,t,n){this.numObjects=0,this._mask=n?se.apply(n,{}):null;for(var r=!n||n.visible,i=!n||n.edges,a=!n||n.xrayed,s=!n||n.highlighted,o=!n||n.selected,l=!n||n.clippable,u=!n||n.pickable,c=!n||n.colorize,f=!n||n.opacity,p=t.metaObjects,A=e.objects,d=0,v=p.length;d1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||$.vec3([0,0,0]))}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=$.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=$.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),n}(),fa=function(e){I(n,Ye);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return P(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,n=e*this.length,r=this._getCurveLengths(),i=0;i=n){var a=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(a)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return P(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||$.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||$.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||$.vec3([0,0,0])}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=$.vec3();return t[0]=$.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=$.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=$.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),n}(),Aa=function(){function e(t,n,r,i){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;b(this,e),this.model=t,this.object=null,this.parent=null,this.id=n,this._aabb=null,this.layer=a,this.portionId=s,this._color=[r[0],r[1],r[2],i],this._colorize=[r[0],r[1],r[2],i],this._colorizing=!1,this._transparent=i<255,this.numTriangles=0,this.origin=null}return P(e,[{key:"_finalize",value:function(e){this.layer.initFlags(this.portionId,e,this._transparent)}},{key:"_finalize2",value:function(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}},{key:"_setVisible",value:function(e){this.layer.setVisible(this.portionId,e,this._transparent)}},{key:"_setColor",value:function(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}},{key:"_setColorize",value:function(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}},{key:"_setOpacity",value:function(e,t){var n=e<255,r=this._transparent!==n;this._color[3]=e,this._colorize[3]=e,this._transparent=n,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),r&&this.layer.setTransparent(this.portionId,t,n)}},{key:"_setOffset",value:function(e){this.layer.setOffset(this.portionId,e)}},{key:"_setHighlighted",value:function(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}},{key:"_setXRayed",value:function(e){this.layer.setXRayed(this.portionId,e,this._transparent)}},{key:"_setSelected",value:function(e){this.layer.setSelected(this.portionId,e,this._transparent)}},{key:"_setEdges",value:function(e){this.layer.setEdges(this.portionId,e,this._transparent)}},{key:"_setClippable",value:function(e){this.layer.setClippable(this.portionId,e,this._transparent)}},{key:"_setCollidable",value:function(e){this.layer.setCollidable(this.portionId,e)}},{key:"_setPickable",value:function(e){this.layer.setPickable(this.portionId,e,this._transparent)}},{key:"_setCulled",value:function(e){this.layer.setCulled(this.portionId,e,this._transparent)}},{key:"canPickTriangle",value:function(){return!1}},{key:"drawPickTriangles",value:function(e,t){}},{key:"pickTriangleSurface",value:function(e){}},{key:"precisionRayPickSurface",value:function(e,t,n,r){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,n,r)}},{key:"canPickWorldPos",value:function(){return!0}},{key:"drawPickDepths",value:function(e){this.model.drawPickDepths(e)}},{key:"drawPickNormals",value:function(e){this.model.drawPickNormals(e)}},{key:"delegatePickedEntity",value:function(){return this.parent}},{key:"getEachVertex",value:function(e){this.layer.getEachVertex(this.portionId,e)}},{key:"aabb",get:function(){return this._aabb},set:function(e){this._aabb=e}},{key:"_destroy",value:function(){this.model.scene._renderer.putPickID(this.pickId)}}]),e}(),da=new(function(){function e(){b(this,e),this._uint8Arrays={},this._float32Arrays={}}return P(e,[{key:"_clear",value:function(){this._uint8Arrays={},this._float32Arrays={}}},{key:"getUInt8Array",value:function(e){var t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}},{key:"getFloat32Array",value:function(e){var t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}}]),e}()),va=0;function ha(){return va++,da}var Ia={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},ya=new Float32Array([1,1,1,1]),ma=new Float32Array([0,0,0,1]),wa=$.vec4(),ga=$.vec3(),Ta=$.vec3(),Ea=$.mat4(),ba=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.instancing,a=void 0!==i&&i,s=r.edges,o=void 0!==s&&s;b(this,e),this._scene=t,this._withSAO=n,this._instancing=a,this._edges=o,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}return P(e,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){return[""]}},{key:"_buildFragmentShader",value:function(){return[""]}},{key:"_addMatricesUniformBlockLines",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}},{key:"_addRemapClipPosLines",value:function(e){return e.push("uniform vec2 pickClipPos;"),e.push("vec4 remapClipPos(vec4 clipPos) {"),e.push(" clipPos.xy /= clipPos.w;"),e.push(" clipPos.xy -= pickClipPos;"),e.push(" clipPos.xy *= clipPos.w;"),e.push(" return clipPos;"),e.push("}"),e}},{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"setSectionPlanesStateUniforms",value:function(e){var t=this._scene,n=t.canvas.gl,r=e.model,i=e.layerIndex,a=t._sectionPlanesState.sectionPlanes.length;if(a>0)for(var s=t._sectionPlanesState.sectionPlanes,o=i*a,l=r.renderFlags,u=0;u0&&(this._uReflectionMap="reflectionMap"),n.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.sectionPlanes.length;o3&&void 0!==arguments[3]?arguments[3]:{},i=r.colorUniform,a=void 0!==i&&i,s=r.incrementDrawState,o=void 0!==s&&s,l=Ir.MAX_TEXTURE_IMAGE_UNITS,u=this._scene,c=u.canvas.gl,f=t._state,p=t.model,A=f.textureSet,d=f.origin,v=f.positionsDecodeMatrix,h=u._lightsState,I=u.pointsMaterial,y=p.scene.camera,m=y.viewNormalMatrix,w=y.project,g=e.pickViewMatrix||y.viewMatrix,T=p.position,E=p.rotationMatrix,b=p.rotationMatrixConjugate,D=p.worldNormalMatrix;if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),this._vaoCache.has(t)?c.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(f));var P=0,R=16;this._matricesUniformBlockBufferData.set(b,0);var C=0!==d[0]||0!==d[1]||0!==d[2],_=0!==T[0]||0!==T[1]||0!==T[2];if(C||_){var B=ga;if(C){var O=$.transformPoint3(E,d,Ta);B[0]=O[0],B[1]=O[1],B[2]=O[2]}else B[0]=0,B[1]=0,B[2]=0;B[0]+=T[0],B[1]+=T[1],B[2]+=T[2],this._matricesUniformBlockBufferData.set(ye(g,B,Ea),P+=R)}else this._matricesUniformBlockBufferData.set(g,P+=R);if(this._matricesUniformBlockBufferData.set(e.pickProjMatrix||w.matrix,P+=R),this._matricesUniformBlockBufferData.set(v,P+=R),this._matricesUniformBlockBufferData.set(D,P+=R),this._matricesUniformBlockBufferData.set(m,P+=R),c.bindBuffer(c.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),c.bufferData(c.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,c.DYNAMIC_DRAW),c.bindBufferBase(c.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer),c.uniform1i(this._uRenderPass,n),this.setSectionPlanesStateUniforms(t),u.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var S=2/(Math.log(e.pickZFar+1)/Math.LN2);c.uniform1f(this._uLogDepthBufFC,S)}this._uZFar&&c.uniform1f(this._uZFar,u.camera.project.far)}if(this._uPickInvisible&&c.uniform1i(this._uPickInvisible,e.pickInvisible),this._uPickZNear&&c.uniform1f(this._uPickZNear,e.pickZNear),this._uPickZFar&&c.uniform1f(this._uPickZFar,e.pickZFar),this._uPickClipPos&&c.uniform2fv(this._uPickClipPos,e.pickClipPos),this._uPositionsDecodeMatrix&&c.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,f.positionsDecodeMatrix),this._uUVDecodeMatrix&&c.uniformMatrix3fv(this._uUVDecodeMatrix,!1,f.uvDecodeMatrix),this._uIntensityRange&&I.filterIntensity&&c.uniform2f(this._uIntensityRange,I.minIntensity,I.maxIntensity),this._uPointSize&&c.uniform1f(this._uPointSize,I.pointSize),this._uNearPlaneHeight){var N="ortho"===u.camera.projection?1:c.drawingBufferHeight/(2*Math.tan(.5*u.camera.perspective.fov*Math.PI/180));c.uniform1f(this._uNearPlaneHeight,N)}if(A){var L=A.colorTexture,x=A.metallicRoughnessTexture,M=A.emissiveTexture,F=A.normalsTexture,H=A.occlusionTexture;this._uColorMap&&L&&(this._program.bindTexture(this._uColorMap,L.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uMetallicRoughMap&&x&&(this._program.bindTexture(this._uMetallicRoughMap,x.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uEmissiveMap&&M&&(this._program.bindTexture(this._uEmissiveMap,M.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uNormalMap&&F&&(this._program.bindTexture(this._uNormalMap,F.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uAOMap&&H&&(this._program.bindTexture(this._uAOMap,H.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l)}if(h.reflectionMaps.length>0&&h.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,h.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),h.lightMaps.length>0&&h.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,h.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),this._withSAO){var U=u.sao,G=U.possible;if(G){var k=c.drawingBufferWidth,j=c.drawingBufferHeight;wa[0]=k,wa[1]=j,wa[2]=U.blendCutoff,wa[3]=U.blendFactor,c.uniform4fv(this._uSAOParams,wa),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++}}if(a){var V=this._edges?"edgeColor":"fillColor",Q=this._edges?"edgeAlpha":"fillAlpha";if(n===Ia["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var W=u.xrayMaterial._state,z=W[V],K=W[Q];c.uniform4f(this._uColor,z[0],z[1],z[2],K)}else if(n===Ia["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var Y=u.highlightMaterial._state,X=Y[V],q=Y[Q];c.uniform4f(this._uColor,X[0],X[1],X[2],q)}else if(n===Ia["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var J=u.selectedMaterial._state,Z=J[V],ee=J[Q];c.uniform4f(this._uColor,Z[0],Z[1],Z[2],ee)}else c.uniform4fv(this._uColor,this._edges?ma:ya)}this._draw({state:f,frameCtx:e,incrementDrawState:o}),c.bindVertexArray(null)}}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null,te.memory.programs--}}]),e}(),Da=function(e){I(n,ba);var t=m(n);function n(e,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=i.instancing,s=void 0!==a&&a,o=i.edges,l=void 0!==o&&o;return b(this,n),t.call(this,e,r,{instancing:s,edges:l})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;if(this._edges)t.drawElements(t.LINES,n.edgeIndicesBuf.numItems,n.edgeIndicesBuf.itemType,0);else{var a=r.pickElementsCount||n.indicesBuf.numItems,s=r.pickElementsOffset?r.pickElementsOffset*n.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,a,n.indicesBuf.itemType,s),i&&r.drawElements++}}}]),n}(),Pa=function(e){I(n,Da);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!1,edges:!0})}return P(n)}(),Ra=function(e){I(n,ba);var t=m(n);function n(e,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=i.edges,s=void 0!==a&&a;return b(this,n),t.call(this,e,r,{instancing:!0,edges:s})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;this._edges?t.drawElementsInstanced(t.LINES,n.edgeIndicesBuf.numItems,n.edgeIndicesBuf.itemType,0,n.numInstances):(t.drawElementsInstanced(t.TRIANGLES,n.indicesBuf.numItems,n.indicesBuf.itemType,0,n.numInstances),i&&r.drawElements++)}}]),n}(),Ca=function(e){I(n,Ra);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0,edges:!0})}return P(n)}(),_a=function(e){I(n,ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawArrays(t.POINTS,0,n.positionsBuf.numItems),i&&r.drawArrays++}}]),n}(),Ba=function(e){I(n,ba);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawArraysInstanced(t.POINTS,0,n.positionsBuf.numItems,n.numInstances),i&&r.drawArrays++}}]),n}(),Oa=function(e){I(n,ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawElements(t.LINES,n.indicesBuf.numItems,n.indicesBuf.itemType,0),i&&r.drawElements++}}]),n}(),Sa=function(e){I(n,ba);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawElementsInstanced(t.LINES,n.indicesBuf.numItems,n.indicesBuf.itemType,0,n.numInstances),i&&r.drawElements++}}]),n}(),Na=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t=this._scene,n=t._sectionPlanesState,r=t._lightsState,i=n.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),t.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),t.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(var s=0,o=r.lights.length;s= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),i&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),t.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(var l=0,u=r.lights.length;l0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),n}(),La=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching flat-shading draw vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._lightsState,n=e._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),r){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var a=0,s=n.sectionPlanes.length;a> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var c=0,f=n.sectionPlanes.length;c 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var p=0,A=t.lights.length;p0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}]),n}(),Ma=function(e){I(n,Pa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("uniform int renderPass;"),n.push("uniform vec4 color;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Fa=function(e){I(n,Pa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ha=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry picking vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),this._addRemapClipPosLines(n),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vPickColor; "),r.push("}"),r}}]),n}(),Ua=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),this._addRemapClipPosLines(n),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Ga=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vWorldNormal;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec3 worldNormal = octDecode(normal.xy); "),n.push(" vWorldNormal = worldNormal;"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}}]),n}(),ka=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}]),n}(),ja=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec2 vHighPrecisionZW;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching depth fragment shader"),r.push("precision highp float;"),r.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),r.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),r.push("}"),r}}]),n}(),Va=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n,!0),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),Qa=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry shadow vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),n.push(" int colorFlag = int(flags) & 0xF;"),n.push(" bool visible = (colorFlag > 0);"),n.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push(" if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry shadow fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = encodeFloat( gl_FragCoord.z); "),n.push("}"),n}}]),n}(),Wa=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=e._lightsState,r=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),n.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),r&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),r&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),n.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._sectionPlanesState,r=e._lightsState,i=n.sectionPlanes.length>0,a=n.clippingCaps,s=[];s.push("#version 300 es"),s.push("// Triangles batching quality draw fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform sampler2D uColorMap;"),s.push("uniform sampler2D uMetallicRoughMap;"),s.push("uniform sampler2D uEmissiveMap;"),s.push("uniform sampler2D uNormalMap;"),s.push("uniform sampler2D uAOMap;"),s.push("in vec4 vViewPosition;"),s.push("in vec3 vViewNormal;"),s.push("in vec4 vColor;"),s.push("in vec2 vUV;"),s.push("in vec2 vMetallicRoughness;"),r.lightMaps.length>0&&s.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(s,!0),r.reflectionMaps.length>0&&s.push("uniform samplerCube reflectionMap;"),r.lightMaps.length>0&&s.push("uniform samplerCube lightMap;"),s.push("uniform vec4 lightAmbient;");for(var o=0,l=r.lights.length;o0&&(s.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),s.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),s.push(" return envMapColor;"),s.push("}")),s.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),s.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),s.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),s.push("}"),s.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" return 1.0 / ( gl * gv );"),s.push("}"),s.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" return 0.5 / max( gv + gl, EPSILON );"),s.push("}"),s.push("float D_GGX(const in float alpha, const in float dotNH) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),s.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float alpha = ( roughness * roughness );"),s.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),s.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),s.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),s.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),s.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),s.push(" vec3 F = F_Schlick( specularColor, dotLH );"),s.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),s.push(" float D = D_GGX( alpha, dotNH );"),s.push(" return F * (G * D);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),s.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),s.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),s.push(" vec4 r = roughness * c0 + c1;"),s.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),s.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),s.push(" return specularColor * AB.x + AB.y;"),s.push("}"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&(s.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.lightMaps.length>0&&(s.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),s.push(" irradiance *= PI;"),s.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),r.reflectionMaps.length>0&&(s.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),s.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),s.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),s.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),s.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),s.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),s.push("}")),s.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),s.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),s.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),s.push("}"),s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var p=0,A=n.sectionPlanes.length;p (0.002 * vClipPosition.w)) {"),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" return;"),s.push("}")):(s.push(" if (dist > 0.0) { "),s.push(" discard;"),s.push(" }")),s.push("}")}s.push("IncidentLight light;"),s.push("Material material;"),s.push("Geometry geometry;"),s.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),s.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),s.push("float opacity = float(vColor.a) / 255.0;"),s.push("vec3 baseColor = rgb;"),s.push("float specularF0 = 1.0;"),s.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),s.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),s.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),s.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),s.push("baseColor *= colorTexel.rgb;"),s.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),s.push("metallic *= metalRoughTexel.b;"),s.push("roughness *= metalRoughTexel.g;"),s.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),s.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),s.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),s.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),s.push("geometry.position = vViewPosition.xyz;"),s.push("geometry.viewNormal = -normalize(viewNormal);"),s.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),r.lightMaps.length>0&&s.push("geometry.worldNormal = normalize(vWorldNormal);"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&s.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var d=0,v=r.lights.length;d0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick flat normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("out vec4 vWorldPosition;"),t&&n.push("out float vFlags;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),t&&n.push(" vFlags = flags;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick flat normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}}]),n}(),Ka=function(e){I(n,Da);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching color texture vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._lightsState,r=e._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(var s=0,o=r.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(var f=0,p=r.sectionPlanes.length;f 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var A=0,d=n.lights.length;A0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]})),Ja=$.mat4(),Za=$.mat4();function $a(e,t,n){for(var r=e.length,i=new Uint16Array(r),a=t[0],s=t[1],o=t[2],l=t[3]-a,u=t[4]-s,c=t[5]-o,f=65525,p=f/l,A=f/u,d=f/c,v=function(e){return e>=0?e:0},h=0;h=0?1:-1),s=(1-Math.abs(r))*(i>=0?1:-1),r=a,i=s}return new Int8Array([Math[t](127.5*r+(r<0?-1:0)),Math[n](127.5*i+(i<0?-1:0))])}function ns(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}var rs=$.vec3(),is=$.vec3(),as=$.vec3(),ss=$.vec3(),os=$.mat4(),ls=function(e){I(n,ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin,u=r.position,c=r.rotationMatrix,f=r.rotationMatrixConjugate,p=t.aabb,A=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?s.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(o));var d,v,h=rs;if(h[0]=$.safeInv(p[3]-p[0])*$.MAX_INT,h[1]=$.safeInv(p[4]-p[1])*$.MAX_INT,h[2]=$.safeInv(p[5]-p[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(h[0]),e.snapPickCoordinateScale[1]=$.safeInv(h[1]),e.snapPickCoordinateScale[2]=$.safeInv(h[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var I=is;if(l){var y=as;$.transformPoint3(c,l,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=u[0],I[1]+=u[1],I[2]+=u[2],d=ye(A,I,os),(v=ss)[0]=a.eye[0]-I[0],v[1]=a.eye[1]-I[1],v[2]=a.eye[2]-I[2],e.snapPickOrigin[0]=I[0],e.snapPickOrigin[1]=I[1],e.snapPickOrigin[2]=I[2]}else d=A,v=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),s.uniform3fv(this._uCoordinateScaler,h),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(f,0),this._matricesUniformBlockBufferData.set(d,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(o.positionsDecodeMatrix,m+=16),s.bindBuffer(s.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),s.bufferData(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,s.DYNAMIC_DRAW),s.bindBufferBase(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var w=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,w),this.setSectionPlanesStateUniforms(t),o.indicesBuf.bind(),s.drawElements(s.TRIANGLES,o.indicesBuf.numItems,o.indicesBuf.itemType,0),o.indicesBuf.unbind()}}},{key:"_allocate",value:function(){v(T(n.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),n}(),us=$.vec3(),cs=$.vec3(),fs=$.vec3(),ps=$.vec3(),As=$.mat4(),ds=function(e){I(n,ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin,u=r.position,c=r.rotationMatrix,f=r.rotationMatrixConjugate,p=t.aabb,A=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?s.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(o));var d,v,h=us;if(h[0]=$.safeInv(p[3]-p[0])*$.MAX_INT,h[1]=$.safeInv(p[4]-p[1])*$.MAX_INT,h[2]=$.safeInv(p[5]-p[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(h[0]),e.snapPickCoordinateScale[1]=$.safeInv(h[1]),e.snapPickCoordinateScale[2]=$.safeInv(h[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var I=cs;if(l){var y=fs;$.transformPoint3(c,l,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=u[0],I[1]+=u[1],I[2]+=u[2],d=ye(A,I,As),(v=ps)[0]=a.eye[0]-I[0],v[1]=a.eye[1]-I[1],v[2]=a.eye[2]-I[2],e.snapPickOrigin[0]=I[0],e.snapPickOrigin[1]=I[1],e.snapPickOrigin[2]=I[2]}else d=A,v=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),s.uniform3fv(this._uCoordinateScaler,h),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(f,0),this._matricesUniformBlockBufferData.set(d,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(o.positionsDecodeMatrix,m+=16),s.bindBuffer(s.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),s.bufferData(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,s.DYNAMIC_DRAW),s.bindBufferBase(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var w=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,w),this.setSectionPlanesStateUniforms(t),"edge"===e.snapMode?(o.edgeIndicesBuf.bind(),s.drawElements(s.LINES,o.edgeIndicesBuf.numItems,o.edgeIndicesBuf.itemType,0),o.edgeIndicesBuf.unbind()):s.drawArrays(s.POINTS,0,o.positionsBuf.numItems)}}},{key:"_allocate",value:function(){v(T(n.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0;e.pointsMaterial._state;var n=[];return n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("gl_PointSize = 1.0;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),n}(),vs=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new ls(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new ds(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),hs={};var Is=$.mat4(),ys=$.mat4(),ms=$.vec4([0,0,0,1]),ws=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]),$.OBB3();var gs=$.vec3(),Ts=$.vec3(),Es=$.vec3(),bs=$.vec3(),Ds=$.vec3(),Ps=$.vec3(),Rs=$.vec3(),Cs=function(){function e(t){var n,r,i;b(this,e),console.info("Creating TrianglesBatchingLayer"),this.model=t.model,this.sortId="TrianglesBatchingLayer"+(t.solid?"-solid":"-surface")+(t.autoNormals?"-autonormals":"-normals")+(t.textureSet&&t.textureSet.colorTexture?"-colorTexture":"")+(t.textureSet&&t.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=t.layerIndex,this._batchingRenderers=(n=t.model.scene,r=n.id,(i=Xa[r])||(i=new Ya(n),Xa[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Xa[r],i._destroy()}))),i),this._snapBatchingRenderers=function(e){var t=e.id,n=hs[t];return n||(n=new vs(e),hs[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete hs[t],n._destroy()}))),n}(t.model.scene),this._buffer=new qa(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new ot({origin:$.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:t.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,t.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=$.mat4(t.positionsDecodeMatrix)),t.uvDecodeMatrix?(this._state.uvDecodeMatrix=$.mat3(t.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,t.origin&&this._state.origin.set(t.origin),this.aabb=$.collapseAABB3(),this.solid=!!t.solid}return P(e,[{key:"canCreatePortion",value:function(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(var M=0,F=a.length;M0){var H=Is;h?$.inverseMat4($.transposeMat4(h,ys),H):$.identityMat4(H,H),function(e,t,n,r,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}var s,o,l,u,c,f=new Float32Array([0,0,0,0]),p=new Float32Array([0,0,0,0]);for(c=0;cu&&(o=s,u=l),(l=a(p,ns(s=ts(p,"floor","ceil"))))>u&&(o=s,u=l),(l=a(p,ns(s=ts(p,"ceil","ceil"))))>u&&(o=s,u=l),r[i+c+0]=o[0],r[i+c+1]=o[1],r[i+c+2]=0}(H,i,i.length,w.normals,w.normals.length)}if(l)for(var U=0,G=l.length;U0)for(var J=0,Z=s.length;J0)for(var ee=0,te=o.length;ee0){var r=this._state.positionsDecodeMatrix?new Uint16Array(n.positions):$a(n.positions,this._modelAABB,this._state.positionsDecodeMatrix=$.mat4());if(e.positionsBuf=new lt(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(var i=0,a=this._portions.length;i0){var u=new Int8Array(n.normals);e.normalsBuf=new lt(t,t.ARRAY_BUFFER,u,n.normals.length,3,t.STATIC_DRAW,!0)}if(n.colors.length>0){var c=new Uint8Array(n.colors);e.colorsBuf=new lt(t,t.ARRAY_BUFFER,c,n.colors.length,4,t.DYNAMIC_DRAW,!1)}if(n.uv.length>0)if(e.uvDecodeMatrix){e.uvBuf=new lt(t,t.ARRAY_BUFFER,n.uv,n.uv.length,2,t.STATIC_DRAW,!1)}else{var f=ht.getUVBounds(n.uv),p=ht.compressUVs(n.uv,f.min,f.max),A=p.quantized;e.uvDecodeMatrix=$.mat3(p.decodeMatrix),e.uvBuf=new lt(t,t.ARRAY_BUFFER,A,A.length,2,t.STATIC_DRAW,!1)}if(n.metallicRoughness.length>0){var d=new Uint8Array(n.metallicRoughness);e.metallicRoughnessBuf=new lt(t,t.ARRAY_BUFFER,d,n.metallicRoughness.length,2,t.STATIC_DRAW,!1)}if(n.positions.length>0){var v=n.positions.length/3,h=new Float32Array(v);e.flagsBuf=new lt(t,t.ARRAY_BUFFER,h,h.length,1,t.DYNAMIC_DRAW,!1)}if(n.pickColors.length>0){var I=new Uint8Array(n.pickColors);e.pickColorsBuf=new lt(t,t.ARRAY_BUFFER,I,n.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var y=new Float32Array(n.offsets);e.offsetsBuf=new lt(t,t.ARRAY_BUFFER,y,n.offsets.length,3,t.DYNAMIC_DRAW)}if(n.indices.length>0){var m=new Uint32Array(n.indices);e.indicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,m,n.indices.length,1,t.STATIC_DRAW)}if(n.edgeIndices.length>0){var w=new Uint32Array(n.edgeIndices);e.edgeIndicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,w,n.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}}},{key:"isEmpty",value:function(){return!this._state.indicesBuf}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,n,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=e,r=this._portions[n],i=4*r.vertsBaseIndex,a=4*r.numVerts,s=this._scratchMemory.getUInt8Array(a),o=t[0],l=t[1],u=t[2],c=t[3],f=0;f3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=e,o=this._portions[s],l=o.vertsBaseIndex,u=o.numVerts,c=l,f=u,p=!!(t&Ee),A=!!(t&Ce),d=!!(t&_e),v=!!(t&Be),h=!!(t&Oe),I=!!(t&De),y=!!(t&be);i=!p||y||A||d&&!this.model.scene.highlightMaterial.glowThrough||v&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,a=!p||y?Ia.NOT_RENDERED:v?Ia.SILHOUETTE_SELECTED:d?Ia.SILHOUETTE_HIGHLIGHTED:A?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED;var m=0;m=!p||y?Ia.NOT_RENDERED:v?Ia.EDGES_SELECTED:d?Ia.EDGES_HIGHLIGHTED:A?Ia.EDGES_XRAYED:h?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED;var w=p&&!y&&I?Ia.PICK:Ia.NOT_RENDERED,g=t&Pe?1:0;if(r){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var T=c,E=c+f;TI)&&(I=b,r.set(y),i&&$.triangleNormal(A,d,v,i),h=!0)}}return h&&i&&($.transformVec3(this.model.worldNormalMatrix,i,i),$.normalizeVec3(i)),h}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}]),e}(),_s=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t,n,r=this._scene,i=r._sectionPlanesState,a=r._lightsState,s=i.sectionPlanes.length>0,o=[];for(o.push("#version 300 es"),o.push("// Instancing geometry drawing vertex shader"),o.push("uniform int renderPass;"),o.push("in vec3 position;"),o.push("in vec2 normal;"),o.push("in vec4 color;"),o.push("in float flags;"),r.entityOffsetsEnabled&&o.push("in vec3 offset;"),o.push("in vec4 modelMatrixCol0;"),o.push("in vec4 modelMatrixCol1;"),o.push("in vec4 modelMatrixCol2;"),o.push("in vec4 modelNormalMatrixCol0;"),o.push("in vec4 modelNormalMatrixCol1;"),o.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(o,!0),r.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;")),o.push("uniform vec4 lightAmbient;"),e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"),s&&(o.push("out vec4 vWorldPosition;"),o.push("out float vFlags;")),o.push("out vec4 vColor;"),o.push("void main(void) {"),o.push("int colorFlag = int(flags) & 0xF;"),o.push("if (colorFlag != renderPass) {"),o.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),o.push("} else {"),o.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),o.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),r.entityOffsetsEnabled&&o.push("worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix * worldPosition; "),o.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),o.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),o.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),e=0,t=a.lights.length;e0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),n}(),Bs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry flat-shading drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=n._lightsState,a=r.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),n.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),a){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var o=0,l=r.sectionPlanes.length;o> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var c=0,f=r.sectionPlanes.length;c 0.0) { "),s.push(" discard;"),s.push(" }"),s.push("}")}for(s.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),s.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),s.push("float lambertian = 1.0;"),s.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),s.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),s.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=i.lights.length;e0,n=[];return n.push("#version 300 es"),n.push("// Instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing fill fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ss=function(e){I(n,Ca);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles instancing edges vertex shader"),n.push("uniform int renderPass;"),n.push("uniform vec4 color;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ns=function(e){I(n,Ca);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles instancing edges vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ls=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry picking vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vPickColor; "),r.push("}"),r}}]),n}(),xs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Ms=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec2 normal;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("in vec4 modelNormalMatrixCol0;"),n.push("in vec4 modelNormalMatrixCol1;"),n.push("in vec4 modelNormalMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vWorldNormal;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),n.push(" vWorldNormal = worldNormal;"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}}]),n}(),Fs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// TrianglesInstancingOcclusionRenderer vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesInstancingOcclusionRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}]),n}(),Hs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry depth drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec2 vHighPrecisionZW;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),n.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}]),n}(),Us=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n,!0),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),Gs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry shadow drawing vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("bool visible = (colorFlag > 0);"),n.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push("if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),ks={3e3:"linearToLinear",3001:"sRGBToLinear"},js=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=e._lightsState,r=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),n.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),r&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),r&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),n.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._sectionPlanesState,r=e._lightsState,i=n.sectionPlanes.length>0,a=n.clippingCaps,s=[];s.push("#version 300 es"),s.push("// Instancing geometry quality drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform sampler2D uColorMap;"),s.push("uniform sampler2D uMetallicRoughMap;"),s.push("uniform sampler2D uEmissiveMap;"),s.push("uniform sampler2D uNormalMap;"),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),r.reflectionMaps.length>0&&s.push("uniform samplerCube reflectionMap;"),r.lightMaps.length>0&&s.push("uniform samplerCube lightMap;"),s.push("uniform vec4 lightAmbient;");for(var o=0,l=r.lights.length;o0&&s.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(s,!0),s.push("#define PI 3.14159265359"),s.push("#define RECIPROCAL_PI 0.31830988618"),s.push("#define RECIPROCAL_PI2 0.15915494"),s.push("#define EPSILON 1e-6"),s.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),s.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),s.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),s.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),s.push(" return normalize(surf_norm );"),s.push(" }"),s.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),s.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),s.push(" vec2 st0 = dFdx( uv.st );"),s.push(" vec2 st1 = dFdy( uv.st );"),s.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),s.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),s.push(" vec3 N = normalize( surf_norm );"),s.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),s.push(" mat3 tsn = mat3( S, T, N );"),s.push(" return normalize( tsn * mapN );"),s.push("}"),s.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),s.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),s.push("}"),s.push("struct IncidentLight {"),s.push(" vec3 color;"),s.push(" vec3 direction;"),s.push("};"),s.push("struct ReflectedLight {"),s.push(" vec3 diffuse;"),s.push(" vec3 specular;"),s.push("};"),s.push("struct Geometry {"),s.push(" vec3 position;"),s.push(" vec3 viewNormal;"),s.push(" vec3 worldNormal;"),s.push(" vec3 viewEyeDir;"),s.push("};"),s.push("struct Material {"),s.push(" vec3 diffuseColor;"),s.push(" float specularRoughness;"),s.push(" vec3 specularColor;"),s.push(" float shine;"),s.push("};"),s.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),s.push(" float r = ggxRoughness + 0.0001;"),s.push(" return (2.0 / (r * r) - 2.0);"),s.push("}"),s.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),s.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),s.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),s.push("}"),r.reflectionMaps.length>0&&(s.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),s.push(" vec3 envMapColor = "+ks[r.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),s.push(" return envMapColor;"),s.push("}")),s.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),s.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),s.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),s.push("}"),s.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" return 1.0 / ( gl * gv );"),s.push("}"),s.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" return 0.5 / max( gv + gl, EPSILON );"),s.push("}"),s.push("float D_GGX(const in float alpha, const in float dotNH) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),s.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float alpha = ( roughness * roughness );"),s.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),s.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),s.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),s.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),s.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),s.push(" vec3 F = F_Schlick( specularColor, dotLH );"),s.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),s.push(" float D = D_GGX( alpha, dotNH );"),s.push(" return F * (G * D);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),s.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),s.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),s.push(" vec4 r = roughness * c0 + c1;"),s.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),s.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),s.push(" return specularColor * AB.x + AB.y;"),s.push("}"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&(s.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.lightMaps.length>0&&(s.push(" vec3 irradiance = "+ks[r.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),s.push(" irradiance *= PI;"),s.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),r.reflectionMaps.length>0&&(s.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),s.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),s.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),s.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),s.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),s.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),s.push("}")),s.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),s.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),s.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),s.push("}"),s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var p=0,A=n.sectionPlanes.length;p (0.002 * vClipPosition.w)) {"),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" return;"),s.push("}")):(s.push(" if (dist > 0.0) { "),s.push(" discard;"),s.push(" }")),s.push("}")}s.push("IncidentLight light;"),s.push("Material material;"),s.push("Geometry geometry;"),s.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),s.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),s.push("float opacity = float(vColor.a) / 255.0;"),s.push("vec3 baseColor = rgb;"),s.push("float specularF0 = 1.0;"),s.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),s.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),s.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),s.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),s.push("baseColor *= colorTexel.rgb;"),s.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),s.push("metallic *= metalRoughTexel.b;"),s.push("roughness *= metalRoughTexel.g;"),s.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),s.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),s.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),s.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),s.push("geometry.position = vViewPosition.xyz;"),s.push("geometry.viewNormal = -normalize(viewNormal);"),s.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),r.lightMaps.length>0&&s.push("geometry.worldNormal = normalize(vWorldNormal);"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&s.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var d=0,v=r.lights.length;d0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),this._addRemapClipPosLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&n.push("out float vFlags;"),n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&n.push("vFlags = flags;"),n.push("gl_Position = remapClipPos(clipPos);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}}]),n}(),Qs=function(e){I(n,Ra);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n.gammaOutput,i=n._sectionPlanesState,a=n._lightsState,s=i.sectionPlanes.length>0,o=[];if(o.push("#version 300 es"),o.push("// Instancing geometry drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),n.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),o.push("uniform sampler2D uColorMap;"),this._withSAO&&(o.push("uniform sampler2D uOcclusionTexture;"),o.push("uniform vec4 uSAOParams;"),o.push("const float packUpscale = 256. / 255.;"),o.push("const float unpackDownScale = 255. / 256.;"),o.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),o.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),o.push("float unpackRGBToFloat( const in vec4 v ) {"),o.push(" return dot( v, unPackFactors );"),o.push("}")),o.push("uniform float gammaFactor;"),o.push("vec4 linearToLinear( in vec4 value ) {"),o.push(" return value;"),o.push("}"),o.push("vec4 sRGBToLinear( in vec4 value ) {"),o.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),o.push("}"),o.push("vec4 gammaToLinear( in vec4 value) {"),o.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),o.push("}"),r&&(o.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),o.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),o.push("}")),s){o.push("in vec4 vWorldPosition;"),o.push("in float vFlags;");for(var l=0,u=i.sectionPlanes.length;l> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var f=0,p=i.sectionPlanes.length;f 0.0) { "),o.push(" discard;"),o.push(" }"),o.push("}")}for(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),o.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),o.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),o.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=a.lights.length;e0,n=[];return n.push("#version 300 es"),n.push("// SnapInstancingDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, -layerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),n}(),$s=$.vec3(),eo=$.vec3(),to=$.vec3(),no=$.vec3(),ro=$.mat4(),io=function(e){I(n,ba);var t=m(n);function n(e){return b(this,n),t.call(this,e,!1,{instancing:!0})}return P(n,[{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin,u=r.position,c=r.rotationMatrix,f=r.rotationMatrixConjugate,p=t.aabb,A=e.pickViewMatrix||a.viewMatrix;this._vaoCache.has(t)?s.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(o));var d,v,h=$s;if(h[0]=$.safeInv(p[3]-p[0])*$.MAX_INT,h[1]=$.safeInv(p[4]-p[1])*$.MAX_INT,h[2]=$.safeInv(p[5]-p[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(h[0]),e.snapPickCoordinateScale[1]=$.safeInv(h[1]),e.snapPickCoordinateScale[2]=$.safeInv(h[2]),l||0!==u[0]||0!==u[1]||0!==u[2]){var I=eo;if(l){var y=$.transformPoint3(c,l,to);I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=u[0],I[1]+=u[1],I[2]+=u[2],d=ye(A,I,ro),(v=no)[0]=a.eye[0]-I[0],v[1]=a.eye[1]-I[1],v[2]=a.eye[2]-I[2],e.snapPickOrigin[0]=I[0],e.snapPickOrigin[1]=I[1],e.snapPickOrigin[2]=I[2]}else d=A,v=a.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),s.uniform3fv(this._uCoordinateScaler,h),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible);var m=0;this._matricesUniformBlockBufferData.set(f,0),this._matricesUniformBlockBufferData.set(d,m+=16),this._matricesUniformBlockBufferData.set(a.projMatrix,m+=16),this._matricesUniformBlockBufferData.set(o.positionsDecodeMatrix,m+=16),s.bindBuffer(s.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),s.bufferData(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,s.DYNAMIC_DRAW),s.bindBufferBase(s.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);var w=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,w),this.setSectionPlanesStateUniforms(t),this._aModelMatrixCol0.bindArrayBuffer(o.modelMatrixCol0Buf),this._aModelMatrixCol1.bindArrayBuffer(o.modelMatrixCol1Buf),this._aModelMatrixCol2.bindArrayBuffer(o.modelMatrixCol2Buf),s.vertexAttribDivisor(this._aModelMatrixCol0.location,1),s.vertexAttribDivisor(this._aModelMatrixCol1.location,1),s.vertexAttribDivisor(this._aModelMatrixCol2.location,1),this._aFlags.bindArrayBuffer(o.flagsBuf),s.vertexAttribDivisor(this._aFlags.location,1),"edge"===e.snapMode?(o.edgeIndicesBuf.bind(),s.drawElementsInstanced(s.LINES,o.edgeIndicesBuf.numItems,o.edgeIndicesBuf.itemType,0,o.numInstances),o.edgeIndicesBuf.unbind()):s.drawArraysInstanced(s.POINTS,0,o.positionsBuf.numItems,o.numInstances),s.vertexAttribDivisor(this._aModelMatrixCol0.location,0),s.vertexAttribDivisor(this._aModelMatrixCol1.location,0),s.vertexAttribDivisor(this._aModelMatrixCol2.location,0),s.vertexAttribDivisor(this._aFlags.location,0),this._aOffset&&s.vertexAttribDivisor(this._aOffset.location,0)}}},{key:"_allocate",value:function(){v(T(n.prototype),"_allocate",this).call(this);var e=this._program;this._uLogDepthBufFC=e.getLocation("logDepthBufFC"),this._uCameraEyeRtc=e.getLocation("uCameraEyeRtc"),this.uVectorA=e.getLocation("snapVectorA"),this.uInverseVectorAB=e.getLocation("snapInvVectorAB"),this._uLayerNumber=e.getLocation("layerNumber"),this._uCoordinateScaler=e.getLocation("coordinateScaler")}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// SnapInstancingDepthRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("gl_PointSize = 1.0;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// SnapInstancingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),n}(),ao=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Zs(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new io(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),so={};var oo=new Uint8Array(4),lo=new Float32Array(1),uo=$.vec4([0,0,0,1]),co=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]);var fo=new Float32Array(3),po=$.vec3(),Ao=$.vec3(),vo=$.vec3(),ho=$.vec3(),Io=$.vec3(),yo=$.vec3(),mo=$.vec3(),wo=function(){function e(t){var n,r,i;b(this,e),console.info("Creating TrianglesInstancingLayer"),this.model=t.model,this.sortId="TrianglesInstancingLayer"+(t.solid?"-solid":"-surface")+(t.normals?"-normals":"-autoNormals"),this.layerIndex=t.layerIndex,this._instancingRenderers=(n=t.model.scene,r=n.id,(i=zs[r])||(i=new Ws(n),zs[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete zs[r],i._destroy()}))),i),this._snapInstancingRenderers=function(e){var t=e.id,n=so[t];return n||(n=new ao(e),so[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete so[t],n._destroy()}))),n}(t.model.scene),this._aabb=$.collapseAABB3(),this._state=new ot({numInstances:0,obb:$.OBB3(),origin:$.vec3(),geometry:t.geometry,textureSet:t.textureSet,pbrSupported:!1,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],t.origin&&this._state.origin.set(t.origin),this._finalized=!1,this.aabb=$.collapseAABB3(),this.solid=!!t.solid,this.numIndices=t.geometry.numIndices}return P(e,[{key:"createPortion",value:function(e){var t=e.color,n=e.metallic,r=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,s=e.aabb,o=e.pickColor;if(this._finalized)throw"Already finalized";var l=t[0],u=t[1],c=t[2];if(this._colors.push(l),this._colors.push(u),this._colors.push(c),this._colors.push(i),this._metallicRoughness.push(null!=n?n:0),this._metallicRoughness.push(null!=r?r:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){var f=$.transposeMat4(a,$.mat4()),p=$.inverseMat4(f);this._modelNormalMatrixCol0.push(p[0]),this._modelNormalMatrixCol0.push(p[4]),this._modelNormalMatrixCol0.push(p[8]),this._modelNormalMatrixCol0.push(p[12]),this._modelNormalMatrixCol1.push(p[1]),this._modelNormalMatrixCol1.push(p[5]),this._modelNormalMatrixCol1.push(p[9]),this._modelNormalMatrixCol1.push(p[13]),this._modelNormalMatrixCol2.push(p[2]),this._modelNormalMatrixCol2.push(p[6]),this._modelNormalMatrixCol2.push(p[10]),this._modelNormalMatrixCol2.push(p[14])}this._pickColors.push(o[0]),this._pickColors.push(o[1]),this._pickColors.push(o[2]),this._pickColors.push(o[3]);for(var A=this._state.geometry.positionsCompressed.length,d=this._state.geometry.positionsCompressed,v=this._state.geometry.positionsDecodeMatrix,h=0;h0){e.colorsBuf=new lt(r,r.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,r.DYNAMIC_DRAW,!1),this._colors=[]}if(this._metallicRoughness.length>0){var s=new Uint8Array(this._metallicRoughness);e.metallicRoughnessBuf=new lt(r,r.ARRAY_BUFFER,s,this._metallicRoughness.length,2,r.STATIC_DRAW,!1)}if(a>0){e.flagsBuf=new lt(r,r.ARRAY_BUFFER,new Float32Array(a),a,1,r.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){e.offsetsBuf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,r.DYNAMIC_DRAW,!1),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){e.positionsBuf=new lt(r,r.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,r.STATIC_DRAW,!1),e.positionsDecodeMatrix=$.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){var o=new Uint8Array(t.colorsCompressed);e.colorsBuf=new lt(r,r.ARRAY_BUFFER,o,o.length,4,r.STATIC_DRAW,!1)}if(t.uvCompressed&&t.uvCompressed.length>0){var l=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new lt(r,r.ARRAY_BUFFER,l,l.length,2,r.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new lt(r,r.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,r.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new lt(r,r.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,r.STATIC_DRAW)),this._modelMatrixCol0.length>0){var u=!1;e.modelMatrixCol0Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,r.STATIC_DRAW,u),e.modelMatrixCol1Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,r.STATIC_DRAW,u),e.modelMatrixCol2Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,r.STATIC_DRAW,u),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,r.STATIC_DRAW,u),e.modelNormalMatrixCol1Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,r.STATIC_DRAW,u),e.modelNormalMatrixCol2Buf=new lt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,r.STATIC_DRAW,u),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){e.pickColorsBuf=new lt(r,r.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,r.STATIC_DRAW,!1),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&n&&n.colorTexture&&n.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!n&&!!n.colorTexture,this._state.geometry=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";oo[0]=t[0],oo[1]=t[1],oo[2]=t[2],oo[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(oo,4*e)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Ee),i=!!(t&Ce),a=!!(t&_e),s=!!(t&Be),o=!!(t&Oe),l=!!(t&De),u=!!(t&be),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.SILHOUETTE_SELECTED:a?Ia.SILHOUETTE_HIGHLIGHTED:i?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED)<<4,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.EDGES_SELECTED:a?Ia.EDGES_HIGHLIGHTED:i?Ia.EDGES_XRAYED:o?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED)<<8,c|=(r&&!u&&l?Ia.PICK:Ia.NOT_RENDERED)<<12,c|=(t&Pe?1:0)<<16,lo[0]=c,this._state.flagsBuf&&this._state.flagsBuf.setData(lo,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(fo[0]=t[0],fo[1]=t[1],fo[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(fo,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"getEachVertex",value:function(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var n=this._state,r=n.geometry,i=this._portions[e];if(i)for(var a=r.quantizedPositions,s=n.origin,o=i.offset,l=s[0]+o[0],u=s[1]+o[1],c=s[2]+o[2],f=uo,p=i.matrix,A=this.model.sceneModelMatrix,d=n.positionsDecodeMatrix,v=0,h=a.length;vy)&&(y=P,r.set(m),i&&$.triangleNormal(d,v,h,i),I=!0)}}return I&&i&&($.transformVec3(o.normalMatrix,i,i),$.transformVec3(this.model.worldNormalMatrix,i,i),$.normalizeVec3(i)),I}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}]),e}(),go=function(e){I(n,Oa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines batching color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),To=function(e){I(n,Oa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines batching silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = color;"),r.push("}"),r}}]),n}(),Eo=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new go(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new To(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),bo={};var Do=P((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]})),Po=$.vec4([0,0,0,1]),Ro=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]),$.OBB3();var Co=function(){function e(t){var n,r,i;b(this,e),this.layerIndex=t.layerIndex,this._batchingRenderers=(n=t.model.scene,r=n.id,(i=bo[r])||(i=new Eo(n),bo[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete bo[r],i._destroy()}))),i),this.model=t.model,this._buffer=new Do(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new ot({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:$.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=$.vec3(t.origin)),this.aabb=$.collapseAABB3()}return P(e,[{key:"canCreatePortion",value:function(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){var r=new Uint16Array(n.positions);e.positionsBuf=new lt(t,t.ARRAY_BUFFER,r,n.positions.length,3,t.STATIC_DRAW)}else{var i=$a(new Float32Array(n.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new lt(t,t.ARRAY_BUFFER,i,n.positions.length,3,t.STATIC_DRAW)}if(n.colors.length>0){var a=new Uint8Array(n.colors);e.colorsBuf=new lt(t,t.ARRAY_BUFFER,a,n.colors.length,4,t.DYNAMIC_DRAW,!1)}if(n.colors.length>0){var s=n.colors.length/4,o=new Float32Array(s);e.flagsBuf=new lt(t,t.ARRAY_BUFFER,o,o.length,1,t.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var l=new Float32Array(n.offsets);e.offsetsBuf=new lt(t,t.ARRAY_BUFFER,l,n.offsets.length,3,t.DYNAMIC_DRAW)}if(n.indices.length>0){var u=new Uint32Array(n.indices);e.indicesBuf=new lt(t,t.ELEMENT_ARRAY_BUFFER,u,n.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,n,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=2*e,r=4*this._portions[n],i=4*this._portions[n+1],a=this._scratchMemory.getUInt8Array(i),s=t[0],o=t[1],l=t[2],u=t[3],c=0;c3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=2*e,o=this._portions[s],l=this._portions[s+1],u=o,c=l,f=!!(t&Ee),p=!!(t&Ce),A=!!(t&_e),d=!!(t&Be),v=!!(t&De),h=!!(t&be);i=!f||h||p||A&&!this.model.scene.highlightMaterial.glowThrough||d&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,a=!f||h?Ia.NOT_RENDERED:d?Ia.SILHOUETTE_SELECTED:A?Ia.SILHOUETTE_HIGHLIGHTED:p?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED;var I=f&&!h&&v?Ia.PICK:Ia.NOT_RENDERED,y=t&Pe?1:0;if(r){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var m=u,w=u+c;m0,n=[];return n.push("#version 300 es"),n.push("// Lines instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 lightAmbient;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),Bo=function(e){I(n,Sa);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 color;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines instancing silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = color;"),r.push("}"),r}}]),n}(),Oo=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new _o(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Bo(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),So={};var No=new Uint8Array(4),Lo=new Float32Array(1),xo=$.vec4([0,0,0,1]),Mo=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]);var Fo=new Float32Array(3),Ho=function(){function e(t){var n,r,i;b(this,e),this.model=t.model,this.material=t.material,this.sortId="LinesInstancingLayer",this.layerIndex=t.layerIndex,this._linesInstancingRenderers=(n=t.model.scene,r=n.id,(i=So[r])||(i=new Oo(n),So[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete So[r],i._destroy()}))),i),this._aabb=$.collapseAABB3(),this._state=new ot({obb:$.OBB3(),numInstances:0,origin:null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],t.origin&&(this._state.origin=$.vec3(t.origin)),this._finalized=!1,this.aabb=$.collapseAABB3()}return P(e,[{key:"createPortion",value:function(e){var t=e.color,n=e.opacity,r=e.meshMatrix,i=e.aabb;if(this._finalized)throw"Already finalized";var a=t[0],s=t[1],o=t[2];t[3],this._colors.push(a),this._colors.push(s),this._colors.push(o),this._colors.push(n),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(r[0]),this._modelMatrixCol0.push(r[4]),this._modelMatrixCol0.push(r[8]),this._modelMatrixCol0.push(r[12]),this._modelMatrixCol1.push(r[1]),this._modelMatrixCol1.push(r[5]),this._modelMatrixCol1.push(r[9]),this._modelMatrixCol1.push(r[13]),this._modelMatrixCol2.push(r[2]),this._modelMatrixCol2.push(r[6]),this._modelMatrixCol2.push(r[10]),this._modelMatrixCol2.push(r[14]),$.collapseAABB3(i);for(var l=this._state.obb,u=l.length,c=0;c0){this._state.colorsBuf=new lt(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,!1),this._colors=[]}if(n>0){this._state.flagsBuf=new lt(e,e.ARRAY_BUFFER,new Float32Array(n),n,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){this._state.offsetsBuf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(this._modelMatrixCol0.length>0){var r=!1;this._state.modelMatrixCol0Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,r),this._state.modelMatrixCol1Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,r),this._state.modelMatrixCol2Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,r),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";No[0]=t[0],No[1]=t[1],No[2]=t[2],No[3]=t[3],this._state.colorsBuf.setData(No,4*e,4)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Ee),i=!!(t&Ce),a=!!(t&_e),s=!!(t&Be),o=!!(t&Oe),l=!!(t&De),u=!!(t&be),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.SILHOUETTE_SELECTED:a?Ia.SILHOUETTE_HIGHLIGHTED:i?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED)<<4,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.EDGES_SELECTED:a?Ia.EDGES_HIGHLIGHTED:i?Ia.EDGES_XRAYED:o?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED)<<8,c|=(r&&!u&&l?Ia.PICK:Ia.NOT_RENDERED)<<12,c|=(t&Pe?255:0)<<16,Lo[0]=c,this._state.flagsBuf.setData(Lo,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Fo[0]=t[0],Fo[1]=t[1],Fo[2]=t[2],this._state.offsetsBuf.setData(Fo,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){}},{key:"drawPickDepths",value:function(e,t){}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}]),e}(),Uo=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial,r=[];return r.push("#version 300 es"),r.push("// Points batching color vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("in float flags;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),n.filterIntensity&&r.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),n.filterIntensity&&(r.push("float intensity = float(color.a) / 255.0;"),r.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {")),r.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),n.filterIntensity&&r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),Go=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching silhouette vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),this._addMatricesUniformBlockLines(r),r.push("uniform vec4 color;"),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),r.push("if (silhouetteFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}]),n}(),ko=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching pick mesh vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 pickColor;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),this._addRemapClipPosLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vPickColor;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),r.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = remapClipPos(clipPos);"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("gl_PointSize += 10.0;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching pick mesh vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vPickColor; "),r.push("}"),r}}]),n}(),jo=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batched pick depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),this._addRemapClipPosLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vViewPosition;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vViewPosition = viewPosition;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = remapClipPos(clipPos);"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("gl_PointSize += 10.0;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batched pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Vo=function(e){I(n,_a);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching occlusion vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push(" gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching occlusion fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),r.push("}"),r}}]),n}(),Qo=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Uo(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Go(this._scene)),this._silhouetteRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new ko(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new jo(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Vo(this._scene)),this._occlusionRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}]),e}(),Wo={};var zo=P((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]})),Ko=$.vec4(),Yo=$.vec4(),Xo=$.vec4([0,0,0,1]),qo=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]),$.OBB3();var Jo=function(){function e(t){b(this,e),this.model=t.model,this.sortId="PointsBatchingLayer",this.layerIndex=t.layerIndex,this._pointsBatchingRenderers=function(e){var t=e.id,n=Wo[t];return n||(n=new Qo(e),Wo[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Wo[t],n._destroy()}))),n}(t.model.scene),this._buffer=new zo(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new ot({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:$.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=$.collapseAABB3(),this._portions=[],this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=$.vec3(t.origin)),this.aabb=$.collapseAABB3()}return P(e,[{key:"canCreatePortion",value:function(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}},{key:"createPortion",value:function(e){if(this._finalized)throw"Already finalized";var t,n=e.positions,r=e.positionsCompressed,i=e.color,a=e.colorsCompressed,s=e.colors,o=e.meshMatrix,l=e.worldAABB,u=e.pickColor,c=this._buffer,f=c.positions.length/3;if(this._preCompressedPositionsExpected){if(!r)throw"positionsCompressed expected";for(var p=0,A=r.length;p0)if(this._preCompressedPositionsExpected){var r=new Uint16Array(n.positions);e.positionsBuf=new lt(t,t.ARRAY_BUFFER,r,n.positions.length,3,t.STATIC_DRAW)}else{var i=$a(new Float32Array(n.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new lt(t,t.ARRAY_BUFFER,i,n.positions.length,3,t.STATIC_DRAW)}if(n.colors.length>0){var a=new Uint8Array(n.colors);e.colorsBuf=new lt(t,t.ARRAY_BUFFER,a,n.colors.length,4,t.STATIC_DRAW,!1)}if(n.positions.length>0){var s=n.positions.length/3,o=new Float32Array(s);e.flagsBuf=new lt(t,t.ARRAY_BUFFER,o,o.length,1,t.DYNAMIC_DRAW,!1)}if(n.pickColors.length>0){var l=new Uint8Array(n.pickColors);e.pickColorsBuf=new lt(t,t.ARRAY_BUFFER,l,n.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var u=new Float32Array(n.offsets);e.offsetsBuf=new lt(t,t.ARRAY_BUFFER,u,n.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized"}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=2*e,r=4*this._portions[n],i=4*this._portions[n+1],a=this._scratchMemory.getUInt8Array(i),s=t[0],o=t[1],l=t[2],u=0;u0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing color vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("in float flags;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),n.filterIntensity&&r.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),n.filterIntensity&&(r.push("float intensity = float(color.a) / 255.0;"),r.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {")),r.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),n.filterIntensity&&r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),$o=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing silhouette vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 color;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),r.push("uniform vec4 silhouetteColor;"),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),r.push("if (silhouetteFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),el=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing pick mesh vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 pickColor;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),this._addRemapClipPosLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vPickColor;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),r.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),r.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing pick mesh fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vPickColor; "),r.push("}"),r}}]),n}(),tl=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing pick depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),this._addRemapClipPosLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vViewPosition;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push(" vViewPosition = viewPosition;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),r.push("gl_Position = remapClipPos(clipPos);"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = remapClipPos(clipPos);"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),nl=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing occlusion vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in vec4 color;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing occlusion vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),rl=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),il=function(e){I(n,Ba);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry shadow drawing vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("bool visible = (colorFlag > 0);"),n.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push("if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n.push("gl_PointSize = pointSize;"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),al=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Zo(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new $o(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new rl(this._scene)),this._depthRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new el(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new tl(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new nl(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new il(this._scene)),this._shadowRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}]),e}(),sl={};var ol=new Uint8Array(4),ll=new Float32Array(1),ul=$.vec4([0,0,0,1]),cl=$.vec4([0,0,0,1]);$.vec4([0,0,0,1]);var fl=new Float32Array(3),pl=function(){function e(t){var n,r,i;b(this,e),this.model=t.model,this.material=t.material,this.sortId="PointsInstancingLayer",this.layerIndex=t.layerIndex,this._pointsInstancingRenderers=(n=t.model.scene,r=n.id,(i=sl[r])||(i=new al(n),sl[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete sl[r],i._destroy()}))),i),this._aabb=$.collapseAABB3(),this._state=new ot({obb:$.OBB3(),numInstances:0,origin:t.origin?$.vec3(t.origin):null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=$.collapseAABB3()}return P(e,[{key:"createPortion",value:function(e){var t=e.meshMatrix,n=e.aabb,r=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(r[0]),this._pickColors.push(r[1]),this._pickColors.push(r[2]),this._pickColors.push(r[3]),$.collapseAABB3(n);for(var i=this._state.obb,a=i.length,s=0;s0){n.flagsBuf=new lt(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){n.offsetsBuf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(r.positionsCompressed&&r.positionsCompressed.length>0){n.positionsBuf=new lt(e,e.ARRAY_BUFFER,r.positionsCompressed,r.positionsCompressed.length,3,e.STATIC_DRAW,!1),n.positionsDecodeMatrix=$.mat4(r.positionsDecodeMatrix)}if(r.colorsCompressed&&r.colorsCompressed.length>0){var i=new Uint8Array(r.colorsCompressed);n.colorsBuf=new lt(e,e.ARRAY_BUFFER,i,i.length,4,e.STATIC_DRAW,!1)}if(this._modelMatrixCol0.length>0){var a=!1;n.modelMatrixCol0Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,a),n.modelMatrixCol1Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,a),n.modelMatrixCol2Buf=new lt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,a),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){n.pickColorsBuf=new lt(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,!1),this._pickColors=[]}n.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";ol[0]=t[0],ol[1]=t[1],ol[2]=t[2],this._state.colorsBuf.setData(ol,3*e)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Ee),i=!!(t&Ce),a=!!(t&_e),s=!!(t&Be),o=!!(t&Oe),l=!!(t&De),u=!!(t&be),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.SILHOUETTE_SELECTED:a?Ia.SILHOUETTE_HIGHLIGHTED:i?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED)<<4,c|=(!r||u?Ia.NOT_RENDERED:s?Ia.EDGES_SELECTED:a?Ia.EDGES_HIGHLIGHTED:i?Ia.EDGES_XRAYED:o?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED)<<8,c|=(r&&!u&&l?Ia.PICK:Ia.NOT_RENDERED)<<12,c|=(t&Pe?255:0)<<16,ll[0]=c,this._state.flagsBuf.setData(ll,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(fl[0]=t[0],fl[1]=t[1],fl[2]=t[2],this._state.offsetsBuf.setData(fl,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE)}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Ia.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Ia.PICK)}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}]),e}(),Al=function(){function e(t){b(this,e),this.id=t.id,this.colorTexture=t.colorTexture,this.metallicRoughnessTexture=t.metallicRoughnessTexture,this.normalsTexture=t.normalsTexture,this.emissiveTexture=t.emissiveTexture,this.occlusionTexture=t.occlusionTexture}return P(e,[{key:"destroy",value:function(){}}]),e}(),dl=function(){function e(t){b(this,e),this.id=t.id,this.texture=t.texture}return P(e,[{key:"destroy",value:function(){this.texture&&(this.texture.destroy(),this.texture=null)}}]),e}(),vl={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}},hl=function(){function e(t,n,r){b(this,e),this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=t,this.onProgress=n,this.onError=r}return P(e,[{key:"itemStart",value:function(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}},{key:"itemEnd",value:function(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}},{key:"itemError",value:function(e){void 0!==this.onError&&this.onError(e)}},{key:"resolveURL",value:function(e){return this.urlModifier?this.urlModifier(e):e}},{key:"setURLModifier",value:function(e){return this.urlModifier=e,this}},{key:"addHandler",value:function(e,t){return this.handlers.push(e,t),this}},{key:"removeHandler",value:function(e){var t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}},{key:"getHandler",value:function(e){for(var t=0,n=this.handlers.length;t0&&void 0!==arguments[0]?arguments[0]:4;b(this,e),this.pool=t,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}return P(e,[{key:"_initWorker",value:function(e){if(!this.workers[e]){var t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}},{key:"_getIdleWorker",value:function(){for(var e=0;e0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Tl++}return this._transcoderPending}},{key:"transcode",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,a){var s=r;n._init().then((function(){return n._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:s},e)})).then((function(e){var n=e.data,r=n.mipmaps,s=(n.width,n.height,n.format),o=n.type,l=n.error,u=n.dfdTransferFn,c=n.dfdFlags;if("error"===o)return a(l);t.setCompressedData({mipmaps:r,props:{format:s,minFilter:1===r.length?1006:1008,magFilter:1===r.length?1006:1008,encoding:2===u?3001:3e3,premultiplyAlpha:!!(1&c)}}),i()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),Tl--}}]),e}();El.BasisFormat={ETC1S:0,UASTC_4x4:1},El.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},El.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},El.BasisWorker=function(){var e,t,n,r=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(s){var c,f=s.data;switch(f.type){case"init":e=f.config,c=f.transcoderBinary,t=new Promise((function(e){n={wasmBinary:c,onRuntimeInitialized:e},BASIS(n)})).then((function(){n.initializeBasis(),void 0===n.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((function(){try{for(var t=function(t){var s=new n.KTX2File(new Uint8Array(t));function c(){s.close(),s.delete()}if(!s.isValid())throw c(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var f=s.isUASTC()?a.UASTC_4x4:a.ETC1S,p=s.getWidth(),A=s.getHeight(),d=s.getLevels(),v=s.getHasAlpha(),h=s.getDFDTransferFunc(),I=s.getDFDFlags(),y=function(t,n,s,c){for(var f,p,A=t===a.ETC1S?o:l,d=0;d>t;n.sort(Ol);for(var o=new Int32Array(e.length),l=0,u=n.length;le[i+1]){var s=e[i];e[i]=e[i+1],e[i+1]=s}Nl=new Int32Array(e),t.sort(Ll);for(var o=new Int32Array(e.length),l=0,u=t.length;l0)for(var g=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl,n=e._lightsState;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uRenderPass=r.getLocation("renderPass"),this._uLightAmbient=r.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var i=n.lights,a=0,s=i.length;a0,a=[];a.push("#version 300 es"),a.push("// TrianglesDataTextureColorRenderer vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),t.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("uniform mat4 sceneModelWorldMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),a.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),a.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),a.push("uniform highp sampler2D uTextureModelMatrices;"),a.push("uniform vec3 uCameraEyeRtc;"),a.push("vec3 positions[3];"),t.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("out float isPerspective;")),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("uniform vec4 lightAmbient;");for(var s=0,o=r.lights.length;s> 3) & 4095;"),a.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),a.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),a.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),a.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),a.push("if (int(flags.x) != renderPass) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("} else {"),a.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),a.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),a.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),a.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),a.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),a.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),a.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),a.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),a.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),a.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),a.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),a.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),a.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),a.push("if (color.a == 0u) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("};"),a.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),a.push("vec3 position;"),a.push("position = positions[gl_VertexID % 3];"),a.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),a.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("} else {"),a.push("if (viewNormal.z < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("}"),a.push("}"),a.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),a.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),a.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(var l=0,u=r.lights.length;l0,r=[];if(r.push("#version 300 es"),r.push("// TrianglesDataTextureColorRenderer fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Ql=new Float32Array([1,1,1]),Wl=$.vec3(),zl=$.vec3(),Kl=$.vec3(),Yl=$.vec3(),Xl=$.mat4(),ql=function(){function e(t,n){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=this._scene,i=r.camera,a=t.model,s=r.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=a.position,f=a.rotationMatrix,p=a.rotationMatrixConjugate,A=i.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var d,v;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,o)),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=Wl;if(u){var I=zl;$.transformPoint3(f,u,I),h[0]=I[0],h[1]=I[1],h[2]=I[2]}else h[0]=0,h[1]=0,h[2]=0;h[0]+=c[0],h[1]+=c[1],h[2]+=c[2],d=ye(A,h,Xl),(v=Kl)[0]=i.eye[0]-h[0],v[1]=i.eye[1]-h[1],v[2]=i.eye[2]-h[2]}else d=A,v=i.eye;if(s.uniform3fv(this._uCameraEyeRtc,v),s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),n===Ia.SILHOUETTE_XRAYED){var y=r.xrayMaterial._state,m=y.fillColor,w=y.fillAlpha;s.uniform4f(this._uColor,m[0],m[1],m[2],w)}else if(n===Ia.SILHOUETTE_HIGHLIGHTED){var g=r.highlightMaterial._state,T=g.fillColor,E=g.fillAlpha;s.uniform4f(this._uColor,T[0],T[1],T[2],E)}else if(n===Ia.SILHOUETTE_SELECTED){var b=r.selectedMaterial._state,D=b.fillColor,P=b.fillAlpha;s.uniform4f(this._uColor,D[0],D[1],D[2],P)}else s.uniform4fv(this._uColor,Ql);if(r.logarithmicDepthBufferEnabled){var R=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,R)}var C=r._sectionPlanesState.sectionPlanes.length;if(C>0)for(var _=r._sectionPlanesState.sectionPlanes,B=t.layerIndex*C,O=a.renderFlags,S=0;S0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uColor=n.getLocation("color"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture silhouette vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.y) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = color;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Jl=new Float32Array([0,0,0,1]),Zl=$.vec3(),$l=$.vec3();$.vec3();var eu=$.vec3(),tu=$.mat4(),nu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Zl;if(v){var y=$l;$.transformPoint3(f,u,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],d=ye(A,I,tu)}else d=A;if(s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),n===Ia.EDGES_XRAYED){var m=i.xrayMaterial._state,w=m.edgeColor,g=m.edgeAlpha;s.uniform4f(this._uColor,w[0],w[1],w[2],g)}else if(n===Ia.EDGES_HIGHLIGHTED){var T=i.highlightMaterial._state,E=T.edgeColor,b=T.edgeAlpha;s.uniform4f(this._uColor,E[0],E[1],E[2],b)}else if(n===Ia.EDGES_SELECTED){var D=i.selectedMaterial._state,P=D.edgeColor,R=D.edgeAlpha;s.uniform4f(this._uColor,P[0],P[1],P[2],R)}else s.uniform4fv(this._uColor,Jl);var C=i._sectionPlanesState.sectionPlanes.length;if(C>0)for(var _=i._sectionPlanesState.sectionPlanes,B=t.layerIndex*C,O=r.renderFlags,S=0;S0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),s.drawArrays(s.LINES,0,o.numEdgeIndices8Bits)),o.numEdgeIndices16Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),s.drawArrays(s.LINES,0,o.numEdgeIndices16Bits)),o.numEdgeIndices32Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),s.drawArrays(s.LINES,0,o.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uColor=n.getLocation("color"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.z) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),e.logarithmicDepthBufferEnabled&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),ru=$.vec3(),iu=$.vec3(),au=$.vec3(),su=$.mat4(),ou=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=a.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=ru;if(v){var y=iu;$.transformPoint3(f,u,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],d=ye(A,I,su)}else d=A;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var m=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=r.renderFlags,E=0;E0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),s.drawArrays(s.LINES,0,o.numEdgeIndices8Bits)),o.numEdgeIndices16Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),s.drawArrays(s.LINES,0,o.numEdgeIndices16Bits)),o.numEdgeIndices32Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),s.drawArrays(s.LINES,0,o.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureEdgesColorRenderer"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled,n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.z) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push(" vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vec4 rgb = vec4(color.rgba);"),n.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// TrianglesDataTextureEdgesColorRenderer"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),lu=$.vec3(),uu=$.vec3(),cu=$.vec3(),fu=$.mat4(),pu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate;c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==f[0]||0!==f[1]||0!==f[2],h=0!==p[0]||0!==p[1]||0!==p[2];if(v||h){var I=lu;if(v){var y=$.transformPoint3(A,f,uu);I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=p[0],I[1]+=p[1],I[2]+=p[2],r=ye(o.viewMatrix,I,fu),(i=cu)[0]=o.eye[0]-I[0],i[1]=o.eye[1]-I[1],i[2]=o.eye[2]-I[2]}else r=o.viewMatrix,i=o.eye;if(l.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix),l.uniform3fv(this._uCameraEyeRtc,i),l.uniform1i(this._uRenderPass,n),s.logarithmicDepthBufferEnabled){var m=2/(Math.log(o.project.far+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,m)}var w=s._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=s._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry picking vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("smooth out vec4 vWorldPosition;"),n.push("flat out uvec4 vFlags2;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uvec4 vFlags2;");for(var i=0;i 0.0);"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outPickColor = vPickColor; "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Au=$.vec3(),du=$.vec3(),vu=$.vec3(),hu=$.vec3(),Iu=$.mat4(),yu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate,v=e.pickViewMatrix||o.viewMatrix;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),f||0!==p[0]||0!==p[1]||0!==p[2]){var h=Au;if(f){var I=du;$.transformPoint3(A,f,I),h[0]=I[0],h[1]=I[1],h[2]=I[2]}else h[0]=0,h[1]=0,h[2]=0;h[0]+=p[0],h[1]+=p[1],h[2]+=p[2],r=ye(v,h,Iu),(i=vu)[0]=o.eye[0]-h[0],i[1]=o.eye[1]-h[1],i[2]=o.eye[2]-h[2],e.snapPickOrigin[0]=h[0],e.snapPickOrigin[1]=h[1],e.snapPickOrigin[2]=h[2]}else r=v,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(l.uniform3fv(this._uCameraEyeRtc,i),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniform1f(this._uPickZNear,e.pickZNear),l.uniform1f(this._uPickZFar,e.pickZFar),l.uniformMatrix4fv(this._uWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix),s.logarithmicDepthBufferEnabled){var y=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,y)}var m=s._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=s._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=a.renderFlags,E=0;E0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outPackedDepth = packDepth(zNormalizedDepth); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),mu=$.vec3(),wu=$.vec3(),gu=$.vec3(),Tu=$.vec3(),Eu=$.vec3(),bu=$.mat4(),Du=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate,v=t.aabb,h=e.pickViewMatrix||o.viewMatrix,I=mu;I[0]=$.safeInv(v[3]-v[0])*$.MAX_INT,I[1]=$.safeInv(v[4]-v[1])*$.MAX_INT,I[2]=$.safeInv(v[5]-v[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(I[0]),e.snapPickCoordinateScale[1]=$.safeInv(I[1]),e.snapPickCoordinateScale[2]=$.safeInv(I[2]),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var y=0!==f[0]||0!==f[1]||0!==f[2],m=0!==p[0]||0!==p[1]||0!==p[2];if(y||m){var w=wu;if(y){var g=$.transformPoint3(A,f,gu);w[0]=g[0],w[1]=g[1],w[2]=g[2]}else w[0]=0,w[1]=0,w[2]=0;w[0]+=p[0],w[1]+=p[1],w[2]+=p[2],r=ye(h,w,bu),(i=Tu)[0]=o.eye[0]-w[0],i[1]=o.eye[1]-w[1],i[2]=o.eye[2]-w[2],e.snapPickOrigin[0]=w[0],e.snapPickOrigin[1]=w[1],e.snapPickOrigin[2]=w[2]}else r=h,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,i),l.uniform2fv(this.uVectorA,e.snapVectorA),l.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,I),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var T=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,T);var E=s._sectionPlanesState.sectionPlanes.length;if(E>0)for(var b=s._sectionPlanesState.sectionPlanes,D=t.layerIndex*E,P=a.renderFlags,R=0;R0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),l.drawArrays(S,0,u.numEdgeIndices8Bits)),u.numEdgeIndices16Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),l.drawArrays(S,0,u.numEdgeIndices16Bits)),u.numEdgeIndices32Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),l.drawArrays(S,0,u.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 uSnapVectorA;"),n.push("uniform vec2 uSnapInvVectorAB;"),n.push("vec3 positions[3];"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),n.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vViewPosition;"),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),n.push("vViewPosition = clipPos;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("gl_PointSize = 1.0;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int uLayerNumber;"),n.push("uniform vec3 uCoordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e.sectionPlanes.length;r 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),n.push(" }")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, uLayerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Pu=$.vec3(),Ru=$.vec3(),Cu=$.vec3(),_u=$.vec3(),Bu=$.vec3(),Ou=$.mat4(),Su=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate,v=t.aabb,h=e.pickViewMatrix||o.viewMatrix,I=Pu;I[0]=$.safeInv(v[3]-v[0])*$.MAX_INT,I[1]=$.safeInv(v[4]-v[1])*$.MAX_INT,I[2]=$.safeInv(v[5]-v[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(I[0]),e.snapPickCoordinateScale[1]=$.safeInv(I[1]),e.snapPickCoordinateScale[2]=$.safeInv(I[2]),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var y=0!==f[0]||0!==f[1]||0!==f[2],m=0!==p[0]||0!==p[1]||0!==p[2];if(y||m){var w=Ru;if(y){var g=Cu;$.transformPoint3(A,f,g),w[0]=g[0],w[1]=g[1],w[2]=g[2]}else w[0]=0,w[1]=0,w[2]=0;w[0]+=p[0],w[1]+=p[1],w[2]+=p[2],r=ye(h,w,Ou),(i=_u)[0]=o.eye[0]-w[0],i[1]=o.eye[1]-w[1],i[2]=o.eye[2]-w[2],e.snapPickOrigin[0]=w[0],e.snapPickOrigin[1]=w[1],e.snapPickOrigin[2]=w[2]}else r=h,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,i),l.uniform2fv(this._uVectorA,e.snapVectorA),l.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,I),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var T=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,T);var E=s._sectionPlanesState.sectionPlanes.length;if(E>0)for(var b=s._sectionPlanesState.sectionPlanes,D=t.layerIndex*E,P=a.renderFlags,R=0;R0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureSnapDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 uVectorAB;"),n.push("uniform vec2 uInverseVectorAB;"),n.push("vec3 positions[3];"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),n.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" viewNormal = -viewNormal;"),n.push(" }"),n.push(" } else {"),n.push(" if (viewNormal.z < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" viewNormal = -viewNormal;"),n.push(" }"),n.push(" }"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureSnapDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int uLayerNumber;"),n.push("uniform vec3 uCoordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e.sectionPlanes.length;r 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),n.push(" }")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Nu=$.vec3(),Lu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var c=a.eye,f=[c[0]-u[0],c[1]-u[1],c[2]-u[2]];if(s.uniform3fv(this._uCameraEyeRtc,f),s.uniform1i(this._uRenderPass,n),s.uniform3fv(this._uCameraEyeRtc,f),s.uniform1i(this._uPickInvisible,e.pickInvisible),i.logarithmicDepthBufferEnabled){var p=2/(Math.log(a.project.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,p)}var A=i._sectionPlanesState.sectionPlanes.length;if(A>0)for(var d=i._sectionPlanesState.sectionPlanes,v=t.layerIndex*A,h=r.renderFlags,I=0;I0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick normals vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureCameraMatrices;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec3 vWorldNormal;"),n.push("void main(void) {"),n.push("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));"),n.push("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));"),n.push("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("normal = -normal;"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("normal = -normal;"),n.push("}"),n.push("}"),n.push("}"),n.push("normal = -normal;"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vWorldNormal = normal.xyz;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.w;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),xu=$.vec3(),Mu=$.vec3(),Fu=$.vec3(),Hu=$.vec3(),Uu=$.mat4(),Gu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=e.pickViewMatrix||a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d,v;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=xu;if(u){var I=Mu;$.transformPoint3(f,u,I),h[0]=I[0],h[1]=I[1],h[2]=I[2]}else h[0]=0,h[1]=0,h[2]=0;h[0]+=c[0],h[1]+=c[1],h[2]+=c[2],d=ye(A,h,Uu),(v=Fu)[0]=a.eye[0]-h[0],v[1]=a.eye[1]-h[1],v[2]=a.eye[2]-h[2]}else d=A,v=a.eye;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var y=i._sectionPlanesState.sectionPlanes.length;if(y>0)for(var m=i._sectionPlanesState.sectionPlanes,w=t.layerIndex*y,g=r.renderFlags,T=0;T0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out vec4 vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix; * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" }"),n.push(" } else {"),n.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push(" if (viewNormal.z < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" }"),n.push(" }"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix; * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(var r=0;r 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),ku=$.vec3(),ju=$.vec3(),Vu=$.vec3(),Qu=$.vec3(),Wu=$.mat4(),zu=function(){function e(t){b(this,e),this._scene=t,this._allocate(),this._hash=this._getHash()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=this._scene,i=r.camera,a=t.model,s=r.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=a.position,f=a.rotationMatrix,p=a.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var A,d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,o)),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=ku;if(v){var y=$.transformPoint3(f,u,ju);I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],A=ye(i.viewMatrix,I,Wu),(d=Vu)[0]=i.eye[0]-I[0],d[1]=i.eye[1]-I[1],d[2]=i.eye[2]-I[2]}else A=i.viewMatrix,d=i.eye;if(s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s.uniform3fv(this._uCameraEyeRtc,d),s.uniform1i(this._uRenderPass,n),r.logarithmicDepthBufferEnabled){var m=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,m)}var w=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,r=[];return r.push("#version 300 es"),r.push("// Triangles dataTexture draw vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("precision highp usampler2D;"),r.push("precision highp isampler2D;"),r.push("precision highp sampler2D;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("precision mediump usampler2D;"),r.push("precision mediump isampler2D;"),r.push("precision mediump sampler2D;"),r.push("#endif"),r.push("uniform int renderPass;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("uniform mat4 sceneModelWorldMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),r.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),r.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),r.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),r.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),r.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),r.push("uniform highp sampler2D uTextureModelMatrices;"),r.push("uniform vec3 uCameraEyeRtc;"),r.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("out float isPerspective;")),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out highp vec2 vHighPrecisionZW;"),n&&(r.push("out vec4 vWorldPosition;"),r.push("flat out uint vFlags2;")),r.push("void main(void) {"),r.push("int polygonIndex = gl_VertexID / 3;"),r.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),r.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),r.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),r.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),r.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),r.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),r.push("if (int(flags.x) != renderPass) {"),r.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),r.push(" return;"),r.push("} else {"),r.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),r.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),r.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),r.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),r.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),r.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),r.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),r.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),r.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),r.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),r.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),r.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),r.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),r.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),r.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),r.push("if (color.a == 0u) {"),r.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),r.push(" return;"),r.push("};"),r.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),r.push("vec3 position;"),r.push("position = positions[gl_VertexID % 3];"),r.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),r.push("if (solid != 1u) {"),r.push("if (isPerspectiveMatrix(projMatrix)) {"),r.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),r.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),r.push("position = positions[2 - (gl_VertexID % 3)];"),r.push("viewNormal = -viewNormal;"),r.push("}"),r.push("} else {"),r.push("if (viewNormal.z < 0.0) {"),r.push("position = positions[2 - (gl_VertexID % 3)];"),r.push("viewNormal = -viewNormal;"),r.push("}"),r.push("}"),r.push("}"),r.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),r.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),r.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags2 = flags2.r;")),r.push("gl_Position = clipPos;"),r.push("vHighPrecisionZW = gl_Position.zw;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),r.push("in highp vec2 vHighPrecisionZW;"),r.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),r.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Ku=$.vec3(),Yu=$.vec3(),Xu=$.vec3(),qu=$.vec3(),Ju=$.mat4(),Zu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin,u=r.position,c=r.rotationMatrix,f=r.rotationMatrixConjugate,p=a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var A,d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(t));var v=0!==l[0]||0!==l[1]||0!==l[2],h=0!==u[0]||0!==u[1]||0!==u[2];if(v||h){var I=Ku;if(v){var y=Yu;$.transformPoint3(c,l,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=u[0],I[1]+=u[1],I[2]+=u[2],A=ye(p,I,Ju),(d=Xu)[0]=a.eye[0]-I[0],d[1]=a.eye[1]-I[1],d[2]=a.eye[2]-I[2]}else A=p,d=a.eye;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,f),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),s.uniformMatrix4fv(this._uViewNormalMatrix,!1,a.viewNormalMatrix),s.uniformMatrix4fv(this._uWorldNormalMatrix,!1,r.worldNormalMatrix);var m=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=r.renderFlags,E=0;E0,n=[];return n.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("uniform int renderPass;"),n.push("attribute vec3 position;"),e.entityOffsetsEnabled&&n.push("attribute vec3 offset;"),n.push("attribute vec3 normal;"),n.push("attribute vec4 color;"),n.push("attribute vec4 flags;"),n.push("attribute vec4 flags2;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 worldNormalMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 viewNormalMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("varying float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out vec4 vFlags2;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth?n.push("vFragDepth = 1.0 + clipPos.w;"):(n.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),n.push("clipPos.z *= clipPos.w;")),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in vec4 vFlags2;");for(var i=0;i 0.0);"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&r.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),$u=$.vec3(),ec=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerObjectIdPositionsDecodeMatrix),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},1),this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerVertexIdCoordinates),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},2),this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerObjectIdColorsAndFlags),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},3),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible),s.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix);var u=e.pickViewMatrix||a.viewMatrix,c=l?ye(u,l):u;if(s.uniformMatrix4fv(this._uViewMatrix,!1,c),s.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),i.logarithmicDepthBufferEnabled){var f=2/(Math.log(a.project.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,f)}var p=i._sectionPlanesState.sectionPlanes.length;if(p>0)for(var A=i._sectionPlanesState.sectionPlanes,d=t.layerIndex*p,v=r.renderFlags,h=0;h0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds8Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices8Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds16Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices16Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds32Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices32Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick flat normals vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in uvec3 packedVertexId;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform isampler2D uTexturePerPolygonIdNormals;"),n.push("uniform usampler2D uTexturePerPolygonIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("out vec4 vWorldPosition;"),t&&n.push("out int vFlags2;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_normal_index = polygonIndex & 4095;"),n.push("int v_normal_index = polygonIndex >> 12;"),n.push("int h_packed_object_id_index = ((polygonIndex >> 3) / 2) & 4095;"),n.push("int v_packed_object_id_index = ((polygonIndex >> 3) / 2) >> 12;"),n.push("ivec3 packedObjectId = ivec3(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).rgb);"),n.push("int objectIndex;"),n.push("if (((polygonIndex >> 3) % 2) == 0) {"),n.push(" objectIndex = (packedObjectId.r << 4) + (packedObjectId.g >> 4);"),n.push("} else {"),n.push(" objectIndex = ((packedObjectId.g & 15) << 8) + packedObjectId.b;"),n.push("}"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("int h_index = polygonIndex & 4095;"),n.push("int v_index = polygonIndex >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position1 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("vec3 position2 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("vec3 position3 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(position3 - position1, position2 - position1));"),n.push("int vertexNumber = gl_VertexID % 3;"),n.push("vec3 position;"),n.push("if (vertexNumber == 0) position = position1;"),n.push("else if (vertexNumber == 1) position = position2;"),n.push("else position = position3;"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),t&&n.push(" vFlags2 = flags2.r;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick flat normals fragment shader"),r.push("#extension GL_OES_standard_derivatives : enable"),e.logarithmicDepthBufferEnabled&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in int vFlags2;");for(var i=0;i 0;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),tc=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._vertexDepthRenderer&&!this._vertexDepthRenderer.getValid()&&(this._vertexDepthRenderer.destroy(),this._vertexDepthRenderer=null),this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Vl(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new Vl(this._scene,!0)),this._colorRendererWithSAO}},{key:"colorQualityRendererWithSAO",get:function(){return this._colorQualityRendererWithSAO||(this._colorQualityRendererWithSAO=new TrianglesDataTextureColorQualityRenderer(this._scene,!0)),this._colorQualityRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ql(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new zu(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new Zu(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new nu(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new ou(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new pu(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Lu(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new ec(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new yu(this._scene)),this._pickDepthRenderer}},{key:"vertexDepthRenderer",get:function(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new Du(this._scene)),this._vertexDepthRenderer}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Su(this._scene)),this._snapDepthBufInitRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Gu(this._scene)),this._occlusionRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorQualityRendererWithSAO&&this._colorQualityRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._vertexDepthRenderer&&this._vertexDepthRenderer.destroy(),this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}]),e}(),nc={};var rc=P((function e(){b(this,e),this.positionsCompressed=[],this.metallicRoughness=[],this.indices8Bits=[],this.indices16Bits=[],this.indices32Bits=[],this.edgeIndices8Bits=[],this.edgeIndices16Bits=[],this.edgeIndices32Bits=[],this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]})),ic=function(){function e(){b(this,e),this.texturePerObjectIdColorsAndFlags=null,this.texturePerObjectIdOffsets=null,this.texturePerObjectIdPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}return P(e,[{key:"finalize",value:function(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}},{key:"bindCommonTextures",value:function(e,t,n,r,i,a){this.texturePerObjectIdPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,n,2),this.texturePerObjectIdColorsAndFlags.bindTexture(e,r,3),this.texturePerObjectIdOffsets.bindTexture(e,a,4)}},{key:"bindTriangleIndicesTextures",value:function(e,t,n,r){this.indicesPortionIdsPerBitnessTextures[r].bindTexture(e,t,5),this.indicesPerBitnessTextures[r].bindTexture(e,n,6)}},{key:"bindEdgeIndicesTextures",value:function(e,t,n,r){this.edgeIndicesPortionIdsPerBitnessTextures[r].bindTexture(e,t,5),this.edgeIndicesPerBitnessTextures[r].bindTexture(e,n,6)}}]),e}(),ac=function(){function e(t,n,r,i){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;b(this,e),this._gl=t,this._texture=n,this._textureWidth=r,this._textureHeight=i,this._textureData=a}return P(e,[{key:"bindTexture",value:function(e,t,n){return e.bindTexture(t,this,n)}},{key:"bind",value:function(e){return this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,this._texture),!0}},{key:"unbind",value:function(e){}}]),e}(),sc={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(sc,null,4));var e=0;Object.keys(sc).forEach((function(t){t.startsWith("size")&&(e+=sc[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/sc.totalPolygons).toFixed(2)));var t={};Object.keys(sc).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((sc[n]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var oc=function(){function e(){b(this,e)}return P(e,[{key:"disableBindedTextureFiltering",value:function(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}},{key:"generateTextureForColorsAndFlags",value:function(e,t,n,r,i,a,s){var o=t.length;this.numPortions=o;var l=4096,u=Math.ceil(o/512);if(0===u)throw"texture height===0";var c=new Uint8Array(16384*u);sc.sizeDataColorsAndFlags+=c.byteLength,sc.numberOfTextures++;for(var f=0;f>24&255,r[f]>>16&255,r[f]>>8&255,255&r[f]],32*f+16),c.set([i[f]>>24&255,i[f]>>16&255,i[f]>>8&255,255&i[f]],32*f+20),c.set([a[f]>>24&255,a[f]>>16&255,a[f]>>8&255,255&a[f]],32*f+24),c.set([s[f]?1:0,0,0,0],32*f+28);var p=e.createTexture();return e.bindTexture(e.TEXTURE_2D,p),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,l,u),e.texSubImage2D(e.TEXTURE_2D,0,0,0,l,u,e.RGBA_INTEGER,e.UNSIGNED_BYTE,c,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new ac(e,p,l,u,c)}},{key:"generateTextureForObjectOffsets",value:function(e,t){var n=512,r=Math.ceil(t/n);if(0===r)throw"texture height===0";var i=new Float32Array(1536*r).fill(0);sc.sizeDataTextureOffsets+=i.byteLength,sc.numberOfTextures++;var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RGB,e.FLOAT,i,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new ac(e,a,n,r,i)}},{key:"generateTextureForPositionsDecodeMatrices",value:function(e,t,n){var r=t.length;if(0===r)throw"num decode+entity matrices===0";var i=2048,a=Math.ceil(r/512),s=new Float32Array(8192*a);sc.sizeDataPositionDecodeMatrices+=s.byteLength,sc.numberOfTextures++;for(var o=$.mat4(),l=0;l65536&&sc.cannotCreatePortion.because10BitsObjectId++;var n=this._numPortions+t<=65536,r=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(0):"".concat(e.id,"#").concat(0);if(!this._bucketGeometries[r]){var i=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits),a=0,s=0;e.buckets.forEach((function(e){a+=e.positionsCompressed.length/3,s+=e.indices.length/3})),(this._state.numVertices+a>16777216||i+s>16777216)&&sc.cannotCreatePortion.becauseTextureSize++,n&&(n=this._state.numVertices+a<=16777216&&i+s<=16777216)}return n}},{key:"createPortion",value:function(e){var t=this;if(this._finalized)throw"Already finalized";var n=[],r=e.worldAABB;e.buckets.forEach((function(i,a){var s=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(a):"".concat(e.id,"#").concat(a),o=t._bucketGeometries[s];o||(o=t._createBucketGeometry(e,i),t._bucketGeometries[s]=o);var l=$.collapseAABB3(pc),u=t._createSubPortion(e,o,i,l);$.expandAABB3(r,l),n.push(u)}));var i=this._state.origin;0===i[0]&&0===i[1]&&0===i[2]||(r[0]+=i[0],r[1]+=i[1],r[2]+=i[2],r[3]+=i[0],r[4]+=i[1],r[5]+=i[2]),$.expandAABB3(this.aabb,r);var a=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(n),this.model.numPortions++,a}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var n=8*Math.ceil(t.indices.length/3/8)*3;sc.overheadSizeAlignementIndices+=2*(n-t.indices.length);var r=new Uint32Array(n);r.fill(0),r.set(t.indices),t.indices=r}if(t.edgeIndices){var i=8*Math.ceil(t.edgeIndices.length/2/8)*2;sc.overheadSizeAlignementEdgeIndices+=2*(i-t.edgeIndices.length);var a=new Uint32Array(i);a.fill(0),a.set(t.edgeIndices),t.edgeIndices=a}for(var s,o=t.positionsCompressed,l=t.indices,u=t.edgeIndices,c=this._buffer,f=c.positionsCompressed.length/3,p=o.length/3,A=0,d=o.length;A0){var I,y=3*t.numTriangles;t.numVertices<=256?(I=f.perTriangleNumberPortionId8Bits,p.numIndices8Bits+=y,sc.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(I=f.perTriangleNumberPortionId16Bits,p.numIndices16Bits+=y,sc.totalPolygons16Bits+=t.numTriangles):(I=f.perTriangleNumberPortionId32Bits,p.numIndices32Bits+=y,sc.totalPolygons32Bits+=t.numTriangles),sc.totalPolygons+=t.numTriangles;for(var m=0;m0){var w,g=2*t.numEdges;t.numVertices<=256?(w=f.perEdgeNumberPortionId8Bits,p.numEdgeIndices8Bits+=g,sc.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(w=f.perEdgeNumberPortionId16Bits,p.numEdgeIndices16Bits+=g,sc.totalEdges16Bits+=t.numEdges):(w=f.perEdgeNumberPortionId32Bits,p.numEdgeIndices32Bits+=g,sc.totalEdges32Bits+=t.numEdges),sc.totalEdges+=t.numEdges;for(var T=0;T0&&(n.texturePerEdgeIdPortionIds8Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perEdgeNumberPortionId8Bits)),i.perEdgeNumberPortionId16Bits.length>0&&(n.texturePerEdgeIdPortionIds16Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perEdgeNumberPortionId16Bits)),i.perEdgeNumberPortionId32Bits.length>0&&(n.texturePerEdgeIdPortionIds32Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perEdgeNumberPortionId32Bits)),i.indices8Bits.length>0&&(n.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(r,i.indices8Bits)),i.indices16Bits.length>0&&(n.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(r,i.indices16Bits)),i.indices32Bits.length>0&&(n.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(r,i.indices32Bits)),i.edgeIndices8Bits.length>0&&(n.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(r,i.edgeIndices8Bits)),i.edgeIndices16Bits.length>0&&(n.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(r,i.edgeIndices16Bits)),i.edgeIndices32Bits.length>0&&(n.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(r,i.edgeIndices32Bits)),n.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(function(){e._deferredSetFlagsDirty&&e._uploadDeferredFlags(),e._numUpdatesInFrame=0}))}}},{key:"isEmpty",value:function(){return 0===this._numPortions}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,n,true),this._setFlags2(e,t,true)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags(),this._setDeferredFlags2()}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}},{key:"_beginDeferredFlags",value:function(){this._deferredSetFlagsActive=!0}},{key:"_uploadDeferredFlags",value:function(){if(console.info("_uploadDeferredFlags"),this._deferredSetFlagsActive=!1,this._deferredSetFlagsDirty){this._deferredSetFlagsDirty=!1;var e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdColorsAndFlags._textureWidth,t.texturePerObjectIdColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectIdColorsAndFlags._textureData),e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdOffsets._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdOffsets._textureWidth,t.texturePerObjectIdOffsets._textureHeight,e.RGB,e.FLOAT,t.texturePerObjectIdOffsets._textureData)}}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){for(var n=this._portionToSubPortionsMap[e],r=0,i=n.length;r=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectIdColorsAndFlags._texture),r.texSubImage2D(r.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,r.RGBA_INTEGER,r.UNSIGNED_BYTE,cc)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){for(var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=this._portionToSubPortionsMap[e],a=0,s=i.length;a3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=!!(t&Ee),o=!!(t&Ce),l=!!(t&_e),u=!!(t&Be),c=!!(t&Oe),f=!!(t&De),p=!!(t&be);i=!s||p||o?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,a=!s||p?Ia.NOT_RENDERED:u?Ia.SILHOUETTE_SELECTED:l?Ia.SILHOUETTE_HIGHLIGHTED:o?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED;var A=0;A=!s||p?Ia.NOT_RENDERED:u?Ia.EDGES_SELECTED:l?Ia.EDGES_HIGHLIGHTED:o?Ia.EDGES_XRAYED:c?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED;var d=s&&f?Ia.PICK:Ia.NOT_RENDERED,v=this._dataTextureState,h=this.model.scene.canvas.gl;cc[0]=i,cc[1]=a,cc[2]=A,cc[3]=d,v.texturePerObjectIdColorsAndFlags._textureData.set(cc,32*e+8),this._deferredSetFlagsActive||r?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),h.bindTexture(h.TEXTURE_2D,v.texturePerObjectIdColorsAndFlags._texture),h.texSubImage2D(h.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,h.RGBA_INTEGER,h.UNSIGNED_BYTE,cc))}},{key:"_setDeferredFlags",value:function(){}},{key:"_setFlags2",value:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=this._portionToSubPortionsMap[e],i=0,a=r.length;i2&&void 0!==arguments[2]&&arguments[2];if(!this._finalized)throw"Not finalized";var r=t&Pe?255:0,i=this._dataTextureState,a=this.model.scene.canvas.gl;cc[0]=r,cc[1]=0,cc[2]=1,cc[3]=2,i.texturePerObjectIdColorsAndFlags._textureData.set(cc,32*e+12),this._deferredSetFlagsActive||n?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectIdColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,cc))}},{key:"_setDeferredFlags2",value:function(){}},{key:"setOffset",value:function(e,t){for(var n=this._portionToSubPortionsMap[e],r=0,i=n.length;r=10&&this._beginDeferredFlags(),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectIdOffsets._texture),r.texSubImage2D(r.TEXTURE_2D,0,0,e,1,1,r.RGB,r.FLOAT,fc))}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?this._dataTextureRenderers.colorRendererWithSAO&&this._dataTextureRenderers.colorRendererWithSAO.drawLayer(t,this,Ia.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"_updateBackfaceCull",value:function(e,t){var n=this.model.backfaces||e.sectioned;if(t.backfaces!==n){var r=t.gl;n?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),t.backfaces=n}}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_TRANSPARENT))}},{key:"drawDepth",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.depthRenderer&&this._dataTextureRenderers.depthRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"drawNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.normalsRenderer&&this._dataTextureRenderers.normalsRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_XRAYED))}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_HIGHLIGHTED))}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_SELECTED))}},{key:"drawEdgesColorOpaque",value:function(e,t){this.model.scene.logarithmicDepthBufferEnabled?this.model.scene._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),this.model.scene._loggedWarning=!0):this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Ia.EDGES_COLOR_OPAQUE)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Ia.EDGES_COLOR_TRANSPARENT)}},{key:"drawEdgesHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Ia.EDGES_HIGHLIGHTED)}},{key:"drawEdgesSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Ia.EDGES_SELECTED)}},{key:"drawEdgesXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Ia.EDGES_XRAYED)}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.occlusionRenderer&&this._dataTextureRenderers.occlusionRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"drawShadow",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.shadowRenderer&&this._dataTextureRenderers.shadowRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"setPickMatrices",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickMeshRenderer&&this._dataTextureRenderers.pickMeshRenderer.drawLayer(t,this,Ia.PICK))}},{key:"drawPickDepths",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,Ia.PICK))}},{key:"drawSnapInitDepthBuf",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.snapDepthBufInitRenderer&&this._dataTextureRenderers.snapDepthBufInitRenderer.drawLayer(t,this,Ia.PICK))}},{key:"drawSnapDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.vertexDepthRenderer&&this._dataTextureRenderers.vertexDepthRenderer.drawLayer(t,this,Ia.PICK))}},{key:"drawPickNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickNormalsRenderer&&this._dataTextureRenderers.pickNormalsRenderer.drawLayer(t,this,Ia.PICK))}},{key:"destroy",value:function(){if(!this._destroyed){var e=this._state;e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}}]),e}(),hc=$.vec3();$.mat4();var Ic=$.vec3([1,1,1]),yc=$.vec3([0,0,0]),mc=$.vec3([0,0,0]),wc=$.identityQuaternion(),gc=$.identityMat4(),Tc=new Uint8Array([255,255,255]),Ec=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!0,r._vboBatchingLayerScratchMemory=ha(),r._textureTranscoder=i.textureTranscoder||Dl(r.scene.viewer),r._maxGeometryBatchSize=i.maxGeometryBatchSize,r._aabb=$.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r._meshList=[],r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._meshes={},r._entities={},r._scheduledMeshes={},r.renderFlags=new Xr,r.numGeometries=0,r.numPortions=0,r.numVisibleLayerPortions=0,r.numTransparentLayerPortions=0,r.numXRayedLayerPortions=0,r.numHighlightedLayerPortions=0,r.numSelectedLayerPortions=0,r.numEdgesLayerPortions=0,r.numPickableLayerPortions=0,r.numClippableLayerPortions=0,r.numCulledLayerPortions=0,r.numEntities=0,r._numTriangles=0,r._numLines=0,r._numPoints=0,r._edgeThreshold=i.edgeThreshold||10,r._origin=$.vec3(i.origin||[0,0,0]),r._position=$.vec3(i.position||[0,0,0]),r._rotation=$.vec3(i.rotation||[0,0,0]),r._quaternion=$.vec4(i.quaternion||[0,0,0,1]),r._conjugateQuaternion=$.vec4(i.quaternion||[0,0,0,1]),i.rotation&&$.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=$.vec3(i.scale||[1,1,1]),r._worldRotationMatrix=$.mat4(),r._worldRotationMatrixConjugate=$.mat4(),r._matrix=$.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=$.mat4(),$.inverseMat4(r._matrix,r._worldNormalMatrix),$.transposeMat4(r._worldNormalMatrix),(i.matrix||i.position||i.rotation||i.scale||i.quaternion)&&(r._viewMatrix=$.mat4(),r._viewNormalMatrix=$.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==i.saoEnabled,r._pbrEnabled=!1!==i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r._onCameraViewMatrix=r.scene.camera.on("matrix",(function(){r._viewMatrixDirty=!0})),r.scene.vfc.enabled&&(r._vfcManager=r.scene.vfc.getVFCManager(g(r))),r._createDefaultTextureSet(),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.backfaces=i.backfaces,r}return P(n,[{key:"_createDefaultTextureSet",value:function(){var e=new dl({id:"defaultColorTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new dl({id:"defaultMetalRoughTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new dl({id:"defaultNormalsTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new dl({id:"defaultEmissiveTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new dl({id:"defaultOcclusionTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=n,this._textures.defaultEmissiveTexture=r,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new Al({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||gc),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&($.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0}},{key:"_setLocalAABBDirty",value:function(){for(var e=0,t=this._entityList.length;e0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var n=e.colors,r=new Uint8Array(n.length),i=0,a=n.length;i0){var t=$.collapseAABB3();$.expandAABB3Points3(t,e.positionsCompressed),ht.decompressAABB(t,e.positionsDecodeMatrix),$.AABB3ToOBB3(t,e.obb)}else if(e.positions&&e.positions.length>0){var n=$.collapseAABB3();$.expandAABB3Points3(n,e.positions),$.AABB3ToOBB3(n,e.obb)}}(e.geometry)}e.numPrimitives=this._getNumPrimitives(e),this._vfcManager&&!this._vfcManager.finalized?this._vfcManager.addMesh(e):this._createMesh(e)}else this.error("[createMesh] SceneModel.createMesh() config missing: id")}},{key:"_createMesh",value:function(e){var t=new Aa(this,e.id,e.color,e.opacity);t.pickId=this.scene._renderer.getPickID(t);var n=t.pickId,r=n>>24&255,i=n>>16&255,a=n>>8&255,s=255&n;switch(e.pickColor=new Uint8Array([s,a,i,r]),e.worldAABB=$.collapseAABB3(),e.aabb=e.worldAABB,e.solid="solid"===e.primitive,t.origin=$.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e);break;case 1:t.layer=this._getVBOBatchingLayer(e);break;case 0:t.layer=this._getVBOInstancingLayer(e)}t.portionId=t.layer.createPortion(e),t.aabb=e.worldAABB,t.numPrimitives=e.numPrimitives,$.expandAABB3(this._aabb,t.aabb),this._meshes[e.id]=t,this._meshList.push(t)}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var n=0,r=e.buckets.length;n>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,n=e.origin,r=e.textureSetId||"-",i=e.geometryId,a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(r,".").concat(i),s=this._vboInstancingLayers[a];if(s)return s;for(var o=e.textureSet,l=e.geometry;!s;)switch(l.primitive){case"triangles":case"surface":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesInstancingLayer")),s=new wo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesInstancingLayer")),s=new wo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":console.info("[SceneModel ".concat(this.id,"]: creating LinesInstancingLayer")),s=new Ho({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":console.info("[SceneModel ".concat(this.id,"]: creating PointsInstancingLayer")),s=new pl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0})}return this._vboInstancingLayers[a]=s,this.layerList.push(s),s}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=$.createUUID():this.scene.components[e.id]&&(this.error("Scene already has a Component with this ID: ".concat(e.id," - will assign random ID")),e.id=$.createUUID()),void 0!==e.meshIds){var t=0;if(this._visible&&!1!==e.visible&&(t|=Ee),this._pickable&&!1!==e.pickable&&(t|=De),this._culled&&!1!==e.culled&&(t|=be),this._clippable&&!1!==e.clippable&&(t|=Pe),this._collidable&&!1!==e.collidable&&(t|=Re),this._edges&&!1!==e.edges&&(t|=Oe),this._xrayed&&!1!==e.xrayed&&(t|=Ce),this._highlighted&&!1!==e.highlighted&&(t|=_e),this._selected&&!1!==e.selected&&(t|=Be),e.flags=t,this._vfcManager&&!this._vfcManager.finalized){for(var n=0,r=e.meshIds.length;nt.sortId?1:0}));for(var s=0,o=this.layerList.length;s0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,n=this.layerList.length;t0)for(var a=0;a0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var n=this.scene.selectedMaterial._state;n.fill&&(n.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var r=this.scene.highlightMaterial._state;r.fill&&(r.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"drawColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=Sl(e.indices||[],t),a=xl(e.edgeIndices||[]);function s(e,t){if(e>t){var n=e;e=t,t=n}function r(n,r){return n!==e?e-n:r!==t?t-r:0}for(var i=0,s=(a.length>>1)-1;i<=s;){var o=s+i>>1,l=r(a[2*o],a[2*o+1]);if(l>0)i=o+1;else{if(!(l<0))return o;s=o-1}}return-i-1}var o=new Int32Array(a.length/2);o.fill(0);var l=r.length/3;if(l>8*(1<p.maxNumPositions&&(p=f()),p.bucketNumber>8)return[e];-1===u[h]&&(u[h]=p.numPositions++,p.positionsCompressed.push(r[3*h]),p.positionsCompressed.push(r[3*h+1]),p.positionsCompressed.push(r[3*h+2])),-1===u[I]&&(u[I]=p.numPositions++,p.positionsCompressed.push(r[3*I]),p.positionsCompressed.push(r[3*I+1]),p.positionsCompressed.push(r[3*I+2])),-1===u[y]&&(u[y]=p.numPositions++,p.positionsCompressed.push(r[3*y]),p.positionsCompressed.push(r[3*y+1]),p.positionsCompressed.push(r[3*y+2])),p.indices.push(u[h]),p.indices.push(u[I]),p.indices.push(u[y]);var m=void 0;(m=s(h,I))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(h,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(I,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]]))}var w=t/8*2,g=t/8,T=2*r.length+(i.length+a.length)*w,E=0;return r.length,c.forEach((function(e){E+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),E>T?[e]:(n&&Ml(c,e),c)}({positionsCompressed:r,indices:i,edgeIndices:a},r.length/3>65536?16:8):s=[{positionsCompressed:r,indices:i,edgeIndices:a}];return s}var Dc=function(e){I(n,Ec);var t=m(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n)}(),Pc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({active:!0,pos:$.vec3(),dir:$.vec3(),dist:0}),r.active=i.active,r.pos=i.pos,r.dir=i.dir,r.scene._sectionPlaneCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"SectionPlane"}},{key:"active",get:function(){return this._state.active},set:function(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos)}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir)}},{key:"dist",get:function(){return this._state.dist}},{key:"flipDir",value:function(){var e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}},{key:"destroy",value:function(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Rc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._skyboxMesh=new si(g(r),{geometry:new mt(g(r),{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new fi(g(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new gi(g(r),{src:i.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:i.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),r.size=i.size,r.active=i.active,r}return P(n,[{key:"size",get:function(){return this._size},set:function(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}},{key:"active",get:function(){return this._skyboxMesh.visible},set:function(e){this._skyboxMesh.visible=e}}]),n}(),Cc=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),_c=function(){function e(t,n){b(this,e),this.primLODLevels=t,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=n,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}return P(e,[{key:"initializeLodState",value:function(e){var t=Object.values(e.objects);if(0!==t.length){for(var n={},r={},i=0,a=t.length;i=this.primLODLevels[l]);l++);var u=this.primLODLevels[l]||0;u in n||(n[u]=[]),n[u].push(s),u in r||(r[u]=0),r[u]+=s.numPrimitives}this.entitiesInLOD=n,this.primCountInLOD=r}}}]),e}(),Bc=function(){function e(t,n,r,i){b(this,e),this.id=n.id,this.scene=t,this.sceneModel=n,this.lodState=new _c(r,i),this.lodState.initializeLodState(n)}return P(e,[{key:"_increaseLODLevelIndex",value:function(){var e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;for(var t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[],n=0,r=t.length;n0&&(t.consecutiveFramesWithoutTargetFps=0,n=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,n=this._decreaseLODLevelIndex()),n}},{key:"resetLodCulling",value:function(){var e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}]),e}(),Oc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._scene=e,r._lodLevels=[2e3,600,150,80,20],r._lodManagers={},r._lodManagerList=[],r.enabled=i.enabled,r.targetFPS=i.targetFPS,r._init(),r}return P(n,[{key:"_init",value:function(){var e=this,t=new Array(4),n=0,r=-1,i=Date.now(),a=0,s=0,o=s;this._scene.on("rendering",(function(){if(-1!==r)for(var t=0,n=e._lodManagerList.length;t4){for(var o=0;o<4;o++)s+=t[o];r=4/s*1e3}}))})),this._scene.camera.on("matrix",(function(){o=s})),this._scene.on("tick",(function(){if(s-o>3)for(var t=0,n=e._lodManagerList.length;t=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},n.boxRayIntersects=function(e,t,n,r,i,a,s){var o=(e.minX-t)*i,l=(e.maxX-t)*i,u=(e.minY-n)*a,c=(e.maxY-n)*a,f=(e.minZ-r)*s,p=(e.maxZ-r)*s,A=Math.min(f,p),d=Math.max(f,p),v=Math.min(u,c),h=Math.max(u,c),I=Math.min(o,l),y=Math.max(o,l),m=Math.max(0,I,v,A);return Math.min(y,h,d)>=m?m:1/0};var g=function(e,t,n,i,a){for(var s,o=[t,n];o.length;)(n=o.pop())-(t=o.pop())<=i||(s=t+Math.ceil((n-t)/i/2)*i,r(e,s,t,n,a),o.push(t,s,s,n))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var n=this.data,r=[];if(!e(n,f(n)))return r;for(var i=[];n;){for(var a=0,s=n.children.length;a1){for(d=0,v=(c=c[c.length-1]).length;d=t)break;var i=r+1;if(i0;){var r=n-1>>1;if(A[r].dist<=A[n].dist)break;d(n,r),n=r}},I=o;A.length&&A[0].dist=t;o--){l=e.children[o];v(a,l),s+=I(a)}return s},e.prototype.adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)v(t[r],e)},e.prototype.condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)0===e[t].children.length?t>0?((n=e[t-1].children).splice(n.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,n){var r=[],i=this.chooseSubtree(e,this.data,t,r);for(i.children.push(e),v(i,e);t>=0&&r[t].children.length>this.maxEntries;)this.split(r,t),t--;this.adjustParentBBoxes(e,r,t)},e.pool=[],e}();n.RBush3D=D},{quickselect:2}],2:[function(e,t,n){!function(e,r){"object"===E(n)&&void 0!==t?t.exports=r():e.quickselect=r()}(this,(function(){function e(n,r,i,a,s){for(;a>i;){if(a-i>600){var o=a-i+1,l=r-i+1,u=Math.log(o),c=.5*Math.exp(2*u/3),f=.5*Math.sqrt(u*c*(o-c)/o)*(l-o/2<0?-1:1);e(n,r,Math.max(i,Math.floor(r-l*c/o+f)),Math.min(a,Math.floor(r+(o-l)*c/o+f)),s)}var p=n[r],A=i,d=a;for(t(n,i,r),s(n[a],p)>0&&t(n,i,a);A0;)d--}0===s(n[i],p)?t(n,i,d):t(n,++d,a),d<=r&&(i=d+1),r<=d&&(a=d-1)}}function t(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function n(e,t){return et?1:0}return function(t,r,i,a,s){e(t,r,i||0,a||t.length-1,s||n)}}))},{}]},{},[1])(1)}));var Lc=Sc.exports.RBush3D,xc=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function n(e,t){var n={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function r(){(0==n.dir&&n.pos.x+1>=n.right||1==n.dir&&n.pos.y+1>=n.bottom||2==n.dir&&n.pos.x-1<=n.left-1||3==n.dir&&n.pos.y-1<=n.top-1)&&(n.dir=(n.dir+1)%4,0==n.dir&&n.left++,1==n.dir&&n.top++,2==n.dir&&n.right--,3==n.dir&&n.bottom--),0==n.dir&&n.pos.x++,1==n.dir&&n.pos.y++,2==n.dir&&n.pos.x--,3==n.dir&&n.pos.y--}for(var i=[],a=e*t;i.lengthp&&(c.push(f),f=[],p=o),f.push(d),p-=v}}while(Ap&&(c.push(A),A=[],p=o),A.push(e),p-=n})),A.length&&c.push(A);var d={};return c.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:c,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,r.maxPolygonsPerCluster),{clusters:{total:s.clusters.length},clusteringResult:s});o+=l.clusters.total,console.log("Total clusters: "+o);var u=[];return l.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){u.push(e.id)}))})),l.orderedEntityIds=u,l}; + **/var Bl=null;function Ol(e,t){var n,r,i,a,s,o,l=3*e,u=3*t,c=Math.min(n=Bl[l],r=Bl[l+1],i=Bl[l+2]),f=Math.min(a=Bl[u],s=Bl[u+1],o=Bl[u+2]);if(c!==f)return c-f;var p=Math.max(n,r,i),A=Math.max(a,s,o);return p!==A?p-A:0}function Sl(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r>t;n.sort(Ol);for(var o=new Int32Array(e.length),l=0,u=n.length;le[i+1]){var s=e[i];e[i]=e[i+1],e[i+1]=s}Nl=new Int32Array(e),t.sort(Ll);for(var o=new Int32Array(e.length),l=0,u=t.length;l0)for(var g=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl,n=e._lightsState;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uRenderPass=r.getLocation("renderPass"),this._uLightAmbient=r.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var i=n.lights,a=0,s=i.length;a0,a=[];a.push("#version 300 es"),a.push("// TrianglesDataTextureColorRenderer vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),t.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("uniform mat4 sceneModelWorldMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),a.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),a.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),a.push("uniform highp sampler2D uTextureModelMatrices;"),a.push("uniform vec3 uCameraEyeRtc;"),a.push("vec3 positions[3];"),t.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("out float isPerspective;")),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("uniform vec4 lightAmbient;");for(var s=0,o=r.lights.length;s> 3) & 4095;"),a.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),a.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),a.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),a.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),a.push("if (int(flags.x) != renderPass) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("} else {"),a.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),a.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),a.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),a.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),a.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),a.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),a.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),a.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),a.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),a.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),a.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),a.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),a.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),a.push("if (color.a == 0u) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("};"),a.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),a.push("vec3 position;"),a.push("position = positions[gl_VertexID % 3];"),a.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),a.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("} else {"),a.push("if (viewNormal.z < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("}"),a.push("}"),a.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),a.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),a.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(var l=0,u=r.lights.length;l0,r=[];if(r.push("#version 300 es"),r.push("// TrianglesDataTextureColorRenderer fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Ql=new Float32Array([1,1,1]),Wl=$.vec3(),zl=$.vec3(),Kl=$.vec3(),Yl=$.vec3(),Xl=$.mat4(),ql=function(){function e(t,n){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=this._scene,i=r.camera,a=t.model,s=r.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=a.position,f=a.rotationMatrix,p=a.rotationMatrixConjugate,A=i.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var d,v;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,o)),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=Wl;if(u){var I=zl;$.transformPoint3(f,u,I),h[0]=I[0],h[1]=I[1],h[2]=I[2]}else h[0]=0,h[1]=0,h[2]=0;h[0]+=c[0],h[1]+=c[1],h[2]+=c[2],d=ye(A,h,Xl),(v=Kl)[0]=i.eye[0]-h[0],v[1]=i.eye[1]-h[1],v[2]=i.eye[2]-h[2]}else d=A,v=i.eye;if(s.uniform3fv(this._uCameraEyeRtc,v),s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),n===Ia.SILHOUETTE_XRAYED){var y=r.xrayMaterial._state,m=y.fillColor,w=y.fillAlpha;s.uniform4f(this._uColor,m[0],m[1],m[2],w)}else if(n===Ia.SILHOUETTE_HIGHLIGHTED){var g=r.highlightMaterial._state,T=g.fillColor,E=g.fillAlpha;s.uniform4f(this._uColor,T[0],T[1],T[2],E)}else if(n===Ia.SILHOUETTE_SELECTED){var b=r.selectedMaterial._state,D=b.fillColor,P=b.fillAlpha;s.uniform4f(this._uColor,D[0],D[1],D[2],P)}else s.uniform4fv(this._uColor,Ql);if(r.logarithmicDepthBufferEnabled){var R=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,R)}var C=r._sectionPlanesState.sectionPlanes.length;if(C>0)for(var _=r._sectionPlanesState.sectionPlanes,B=t.layerIndex*C,O=a.renderFlags,S=0;S0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uColor=n.getLocation("color"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture silhouette vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.y) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = color;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Jl=new Float32Array([0,0,0,1]),Zl=$.vec3(),$l=$.vec3();$.vec3();var eu=$.vec3(),tu=$.mat4(),nu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Zl;if(v){var y=$l;$.transformPoint3(f,u,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],d=ye(A,I,tu)}else d=A;if(s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),n===Ia.EDGES_XRAYED){var m=i.xrayMaterial._state,w=m.edgeColor,g=m.edgeAlpha;s.uniform4f(this._uColor,w[0],w[1],w[2],g)}else if(n===Ia.EDGES_HIGHLIGHTED){var T=i.highlightMaterial._state,E=T.edgeColor,b=T.edgeAlpha;s.uniform4f(this._uColor,E[0],E[1],E[2],b)}else if(n===Ia.EDGES_SELECTED){var D=i.selectedMaterial._state,P=D.edgeColor,R=D.edgeAlpha;s.uniform4f(this._uColor,P[0],P[1],P[2],R)}else s.uniform4fv(this._uColor,Jl);var C=i._sectionPlanesState.sectionPlanes.length;if(C>0)for(var _=i._sectionPlanesState.sectionPlanes,B=t.layerIndex*C,O=r.renderFlags,S=0;S0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),s.drawArrays(s.LINES,0,o.numEdgeIndices8Bits)),o.numEdgeIndices16Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),s.drawArrays(s.LINES,0,o.numEdgeIndices16Bits)),o.numEdgeIndices32Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),s.drawArrays(s.LINES,0,o.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uColor=n.getLocation("color"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.z) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),e.logarithmicDepthBufferEnabled&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),ru=$.vec3(),iu=$.vec3(),au=$.vec3(),su=$.mat4(),ou=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=a.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=ru;if(v){var y=iu;$.transformPoint3(f,u,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],d=ye(A,I,su)}else d=A;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var m=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=r.renderFlags,E=0;E0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),s.drawArrays(s.LINES,0,o.numEdgeIndices8Bits)),o.numEdgeIndices16Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),s.drawArrays(s.LINES,0,o.numEdgeIndices16Bits)),o.numEdgeIndices32Bits>0&&(l.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),s.drawArrays(s.LINES,0,o.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureEdgesColorRenderer"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled,n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.z) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push(" vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vec4 rgb = vec4(color.rgba);"),n.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// TrianglesDataTextureEdgesColorRenderer"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),lu=$.vec3(),uu=$.vec3(),cu=$.vec3(),fu=$.mat4(),pu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate;c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==f[0]||0!==f[1]||0!==f[2],h=0!==p[0]||0!==p[1]||0!==p[2];if(v||h){var I=lu;if(v){var y=$.transformPoint3(A,f,uu);I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=p[0],I[1]+=p[1],I[2]+=p[2],r=ye(o.viewMatrix,I,fu),(i=cu)[0]=o.eye[0]-I[0],i[1]=o.eye[1]-I[1],i[2]=o.eye[2]-I[2]}else r=o.viewMatrix,i=o.eye;if(l.uniform2fv(this._uPickClipPos,e.pickClipPos),l.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix),l.uniform3fv(this._uCameraEyeRtc,i),l.uniform1i(this._uRenderPass,n),s.logarithmicDepthBufferEnabled){var m=2/(Math.log(o.project.far+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,m)}var w=s._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=s._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPickClipPos=n.getLocation("pickClipPos"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry picking vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("uniform vec2 pickClipPos;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy -= pickClipPos;"),n.push(" clipPos.xy *= clipPos.w;"),n.push(" return clipPos;"),n.push("}"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("smooth out vec4 vWorldPosition;"),n.push("flat out uvec4 vFlags2;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uvec4 vFlags2;");for(var i=0;i 0.0);"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outPickColor = vPickColor; "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Au=$.vec3(),du=$.vec3(),vu=$.vec3(),hu=$.vec3(),Iu=$.mat4(),yu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate,v=e.pickViewMatrix||o.viewMatrix;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),f||0!==p[0]||0!==p[1]||0!==p[2]){var h=Au;if(f){var I=du;$.transformPoint3(A,f,I),h[0]=I[0],h[1]=I[1],h[2]=I[2]}else h[0]=0,h[1]=0,h[2]=0;h[0]+=p[0],h[1]+=p[1],h[2]+=p[2],r=ye(v,h,Iu),(i=vu)[0]=o.eye[0]-h[0],i[1]=o.eye[1]-h[1],i[2]=o.eye[2]-h[2],e.snapPickOrigin[0]=h[0],e.snapPickOrigin[1]=h[1],e.snapPickOrigin[2]=h[2]}else r=v,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(l.uniform3fv(this._uCameraEyeRtc,i),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniform2fv(this._uPickClipPos,e.pickClipPos),l.uniform1f(this._uPickZNear,e.pickZNear),l.uniform1f(this._uPickZFar,e.pickZFar),l.uniformMatrix4fv(this._uWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix),s.logarithmicDepthBufferEnabled){var y=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,y)}var m=s._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=s._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=a.renderFlags,E=0;E0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPickClipPos=n.getLocation("pickClipPos"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("uniform vec2 pickClipPos;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy -= pickClipPos;"),n.push(" clipPos.xy *= clipPos.w;"),n.push(" return clipPos;"),n.push("}"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outPackedDepth = packDepth(zNormalizedDepth); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),mu=$.vec3(),wu=$.vec3(),gu=$.vec3(),Tu=$.vec3(),Eu=$.vec3(),bu=$.mat4(),Du=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate,v=t.aabb,h=e.pickViewMatrix||o.viewMatrix,I=mu;I[0]=$.safeInv(v[3]-v[0])*$.MAX_INT,I[1]=$.safeInv(v[4]-v[1])*$.MAX_INT,I[2]=$.safeInv(v[5]-v[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(I[0]),e.snapPickCoordinateScale[1]=$.safeInv(I[1]),e.snapPickCoordinateScale[2]=$.safeInv(I[2]),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var y=0!==f[0]||0!==f[1]||0!==f[2],m=0!==p[0]||0!==p[1]||0!==p[2];if(y||m){var w=wu;if(y){var g=$.transformPoint3(A,f,gu);w[0]=g[0],w[1]=g[1],w[2]=g[2]}else w[0]=0,w[1]=0,w[2]=0;w[0]+=p[0],w[1]+=p[1],w[2]+=p[2],r=ye(h,w,bu),(i=Tu)[0]=o.eye[0]-w[0],i[1]=o.eye[1]-w[1],i[2]=o.eye[2]-w[2],e.snapPickOrigin[0]=w[0],e.snapPickOrigin[1]=w[1],e.snapPickOrigin[2]=w[2]}else r=h,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,i),l.uniform2fv(this.uVectorA,e.snapVectorA),l.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,I),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var T=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,T);var E=s._sectionPlanesState.sectionPlanes.length;if(E>0)for(var b=s._sectionPlanesState.sectionPlanes,D=t.layerIndex*E,P=a.renderFlags,R=0;R0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),l.drawArrays(S,0,u.numEdgeIndices8Bits)),u.numEdgeIndices16Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),l.drawArrays(S,0,u.numEdgeIndices16Bits)),u.numEdgeIndices32Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),l.drawArrays(S,0,u.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 uSnapVectorA;"),n.push("uniform vec2 uSnapInvVectorAB;"),n.push("vec3 positions[3];"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),n.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vViewPosition;"),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),n.push("vViewPosition = clipPos;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("gl_PointSize = 1.0;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int uLayerNumber;"),n.push("uniform vec3 uCoordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e.sectionPlanes.length;r 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),n.push(" }")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, uLayerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Pu=$.vec3(),Ru=$.vec3(),Cu=$.vec3(),_u=$.vec3(),Bu=$.vec3(),Ou=$.mat4(),Su=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate,v=t.aabb,h=e.pickViewMatrix||o.viewMatrix,I=Pu;I[0]=$.safeInv(v[3]-v[0])*$.MAX_INT,I[1]=$.safeInv(v[4]-v[1])*$.MAX_INT,I[2]=$.safeInv(v[5]-v[2])*$.MAX_INT,e.snapPickCoordinateScale[0]=$.safeInv(I[0]),e.snapPickCoordinateScale[1]=$.safeInv(I[1]),e.snapPickCoordinateScale[2]=$.safeInv(I[2]),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var y=0!==f[0]||0!==f[1]||0!==f[2],m=0!==p[0]||0!==p[1]||0!==p[2];if(y||m){var w=Ru;if(y){var g=Cu;$.transformPoint3(A,f,g),w[0]=g[0],w[1]=g[1],w[2]=g[2]}else w[0]=0,w[1]=0,w[2]=0;w[0]+=p[0],w[1]+=p[1],w[2]+=p[2],r=ye(h,w,Ou),(i=_u)[0]=o.eye[0]-w[0],i[1]=o.eye[1]-w[1],i[2]=o.eye[2]-w[2],e.snapPickOrigin[0]=w[0],e.snapPickOrigin[1]=w[1],e.snapPickOrigin[2]=w[2]}else r=h,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,i),l.uniform2fv(this._uVectorA,e.snapVectorA),l.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,I),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var T=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,T);var E=s._sectionPlanesState.sectionPlanes.length;if(E>0)for(var b=s._sectionPlanesState.sectionPlanes,D=t.layerIndex*E,P=a.renderFlags,R=0;R0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),l.drawArrays(l.TRIANGLES,0,u.numIndices8Bits)),u.numIndices16Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),l.drawArrays(l.TRIANGLES,0,u.numIndices16Bits)),u.numIndices32Bits>0&&(c.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),l.drawArrays(l.TRIANGLES,0,u.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureSnapDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 uVectorAB;"),n.push("uniform vec2 uInverseVectorAB;"),n.push("vec3 positions[3];"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),n.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" viewNormal = -viewNormal;"),n.push(" }"),n.push(" } else {"),n.push(" if (viewNormal.z < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" viewNormal = -viewNormal;"),n.push(" }"),n.push(" }"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureSnapDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int uLayerNumber;"),n.push("uniform vec3 uCoordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e.sectionPlanes.length;r 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),n.push(" }")}return n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Nu=$.vec3(),Lu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var c=a.eye,f=[c[0]-u[0],c[1]-u[1],c[2]-u[2]];if(s.uniform3fv(this._uCameraEyeRtc,f),s.uniform1i(this._uRenderPass,n),s.uniform3fv(this._uCameraEyeRtc,f),s.uniform1i(this._uPickInvisible,e.pickInvisible),s.uniform2fv(this._uPickClipPos,e.pickClipPos),i.logarithmicDepthBufferEnabled){var p=2/(Math.log(a.project.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,p)}var A=i._sectionPlanesState.sectionPlanes.length;if(A>0)for(var d=i._sectionPlanesState.sectionPlanes,v=t.layerIndex*A,h=r.renderFlags,I=0;I0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPickClipPos=n.getLocation("pickClipPos"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick normals vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureCameraMatrices;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("uniform vec2 pickClipPos;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy -= pickClipPos;"),n.push(" clipPos.xy *= clipPos.w;"),n.push(" return clipPos;"),n.push("}"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec3 vWorldNormal;"),n.push("void main(void) {"),n.push("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));"),n.push("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));"),n.push("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("normal = -normal;"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("normal = -normal;"),n.push("}"),n.push("}"),n.push("}"),n.push("normal = -normal;"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vWorldNormal = normal.xyz;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.w;")),n.push("gl_Position = remapClipPos(clipPos);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outNormal = ivec4(vWorldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),xu=$.vec3(),Mu=$.vec3(),Fu=$.vec3(),Hu=$.vec3(),Uu=$.mat4(),Gu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=e.pickViewMatrix||a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d,v;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=xu;if(u){var I=Mu;$.transformPoint3(f,u,I),h[0]=I[0],h[1]=I[1],h[2]=I[2]}else h[0]=0,h[1]=0,h[2]=0;h[0]+=c[0],h[1]+=c[1],h[2]+=c[2],d=ye(A,h,Uu),(v=Fu)[0]=a.eye[0]-h[0],v[1]=a.eye[1]-h[1],v[2]=a.eye[2]-h[2]}else d=A,v=a.eye;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var y=i._sectionPlanesState.sectionPlanes.length;if(y>0)for(var m=i._sectionPlanesState.sectionPlanes,w=t.layerIndex*y,g=r.renderFlags,T=0;T0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out vec4 vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix; * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" }"),n.push(" } else {"),n.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push(" if (viewNormal.z < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" }"),n.push(" }"),n.push("}"),n.push("vec4 worldPosition = sceneModelWorldMatrix; * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(var r=0;r 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),ku=$.vec3(),ju=$.vec3(),Vu=$.vec3(),Qu=$.vec3(),Wu=$.mat4(),zu=function(){function e(t){b(this,e),this._scene=t,this._allocate(),this._hash=this._getHash()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=this._scene,i=r.camera,a=t.model,s=r.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=a.position,f=a.rotationMatrix,p=a.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var A,d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,o)),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=ku;if(v){var y=$.transformPoint3(f,u,ju);I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],A=ye(i.viewMatrix,I,Wu),(d=Vu)[0]=i.eye[0]-I[0],d[1]=i.eye[1]-I[1],d[2]=i.eye[2]-I[2]}else A=i.viewMatrix,d=i.eye;if(s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s.uniform3fv(this._uCameraEyeRtc,d),s.uniform1i(this._uRenderPass,n),r.logarithmicDepthBufferEnabled){var m=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,m)}var w=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,8),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,16),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(l.bindTriangleIndicesTextures(this._program,this._uTexturePerPolygonIdPortionIds,this._uTexturePerPolygonIdIndices,32),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,r=[];return r.push("#version 300 es"),r.push("// Triangles dataTexture draw vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("precision highp usampler2D;"),r.push("precision highp isampler2D;"),r.push("precision highp sampler2D;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("precision mediump usampler2D;"),r.push("precision mediump isampler2D;"),r.push("precision mediump sampler2D;"),r.push("#endif"),r.push("uniform int renderPass;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("uniform mat4 sceneModelWorldMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),r.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),r.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),r.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),r.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),r.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),r.push("uniform highp sampler2D uTextureModelMatrices;"),r.push("uniform vec3 uCameraEyeRtc;"),r.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("out float isPerspective;")),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out highp vec2 vHighPrecisionZW;"),n&&(r.push("out vec4 vWorldPosition;"),r.push("flat out uint vFlags2;")),r.push("void main(void) {"),r.push("int polygonIndex = gl_VertexID / 3;"),r.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),r.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),r.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),r.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),r.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),r.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),r.push("if (int(flags.x) != renderPass) {"),r.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),r.push(" return;"),r.push("} else {"),r.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),r.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),r.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),r.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),r.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),r.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),r.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),r.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),r.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),r.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),r.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),r.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),r.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),r.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),r.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),r.push("if (color.a == 0u) {"),r.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),r.push(" return;"),r.push("};"),r.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),r.push("vec3 position;"),r.push("position = positions[gl_VertexID % 3];"),r.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),r.push("if (solid != 1u) {"),r.push("if (isPerspectiveMatrix(projMatrix)) {"),r.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelWorldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),r.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),r.push("position = positions[2 - (gl_VertexID % 3)];"),r.push("viewNormal = -viewNormal;"),r.push("}"),r.push("} else {"),r.push("if (viewNormal.z < 0.0) {"),r.push("position = positions[2 - (gl_VertexID % 3)];"),r.push("viewNormal = -viewNormal;"),r.push("}"),r.push("}"),r.push("}"),r.push("vec4 worldPosition = sceneModelWorldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),r.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),r.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags2 = flags2.r;")),r.push("gl_Position = clipPos;"),r.push("vHighPrecisionZW = gl_Position.zw;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),r.push("in highp vec2 vHighPrecisionZW;"),r.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),r.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Ku=$.vec3(),Yu=$.vec3(),Xu=$.vec3(),qu=$.vec3(),Ju=$.mat4(),Zu=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin,u=r.position,c=r.rotationMatrix,f=r.rotationMatrixConjugate,p=a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var A,d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(t));var v=0!==l[0]||0!==l[1]||0!==l[2],h=0!==u[0]||0!==u[1]||0!==u[2];if(v||h){var I=Ku;if(v){var y=Yu;$.transformPoint3(c,l,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=u[0],I[1]+=u[1],I[2]+=u[2],A=ye(p,I,Ju),(d=Xu)[0]=a.eye[0]-I[0],d[1]=a.eye[1]-I[1],d[2]=a.eye[2]-I[2]}else A=p,d=a.eye;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,f),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),s.uniformMatrix4fv(this._uViewNormalMatrix,!1,a.viewNormalMatrix),s.uniformMatrix4fv(this._uWorldNormalMatrix,!1,r.worldNormalMatrix);var m=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=r.renderFlags,E=0;E0,n=[];return n.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("uniform int renderPass;"),n.push("attribute vec3 position;"),e.entityOffsetsEnabled&&n.push("attribute vec3 offset;"),n.push("attribute vec3 normal;"),n.push("attribute vec4 color;"),n.push("attribute vec4 flags;"),n.push("attribute vec4 flags2;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 worldNormalMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 viewNormalMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("varying float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out vec4 vFlags2;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth?n.push("vFragDepth = 1.0 + clipPos.w;"):(n.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),n.push("clipPos.z *= clipPos.w;")),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in vec4 vFlags2;");for(var i=0;i 0.0);"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&Ir.SUPPORTED_EXTENSIONS.EXT_frag_depth&&r.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),$u=$.vec3(),ec=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerObjectIdPositionsDecodeMatrix),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},1),this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerVertexIdCoordinates),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},2),this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerObjectIdColorsAndFlags),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},3),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible),s.uniform2fv(this._uPickClipPos,e.pickClipPos),s.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix);var u=e.pickViewMatrix||a.viewMatrix,c=l?ye(u,l):u;if(s.uniformMatrix4fv(this._uViewMatrix,!1,c),s.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),i.logarithmicDepthBufferEnabled){var f=2/(Math.log(a.project.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,f)}var p=i._sectionPlanesState.sectionPlanes.length;if(p>0)for(var A=i._sectionPlanesState.sectionPlanes,d=t.layerIndex*p,v=r.renderFlags,h=0;h0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds8Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices8Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds16Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices16Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds32Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices32Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new hr(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPickClipPos=n.getLocation("pickClipPos"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick flat normals vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in uvec3 packedVertexId;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform isampler2D uTexturePerPolygonIdNormals;"),n.push("uniform usampler2D uTexturePerPolygonIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("uniform vec2 pickClipPos;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy -= pickClipPos;"),n.push(" clipPos.xy *= clipPos.w;"),n.push(" return clipPos;"),n.push("}"),n.push("out vec4 vWorldPosition;"),t&&n.push("out int vFlags2;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_normal_index = polygonIndex & 4095;"),n.push("int v_normal_index = polygonIndex >> 12;"),n.push("int h_packed_object_id_index = ((polygonIndex >> 3) / 2) & 4095;"),n.push("int v_packed_object_id_index = ((polygonIndex >> 3) / 2) >> 12;"),n.push("ivec3 packedObjectId = ivec3(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).rgb);"),n.push("int objectIndex;"),n.push("if (((polygonIndex >> 3) % 2) == 0) {"),n.push(" objectIndex = (packedObjectId.r << 4) + (packedObjectId.g >> 4);"),n.push("} else {"),n.push(" objectIndex = ((packedObjectId.g & 15) << 8) + packedObjectId.b;"),n.push("}"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("int h_index = polygonIndex & 4095;"),n.push("int v_index = polygonIndex >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position1 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("vec3 position2 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("vec3 position3 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(position3 - position1, position2 - position1));"),n.push("int vertexNumber = gl_VertexID % 3;"),n.push("vec3 position;"),n.push("if (vertexNumber == 0) position = position1;"),n.push("else if (vertexNumber == 1) position = position2;"),n.push("else position = position3;"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),t&&n.push(" vFlags2 = flags2.r;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = remapClipPos(clipPos);"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick flat normals fragment shader"),r.push("#extension GL_OES_standard_derivatives : enable"),e.logarithmicDepthBufferEnabled&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in int vFlags2;");for(var i=0;i 0;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outNormal = ivec4(worldNormal * float(".concat($.MAX_INT,"), 1.0);")),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),tc=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._vertexDepthRenderer&&!this._vertexDepthRenderer.getValid()&&(this._vertexDepthRenderer.destroy(),this._vertexDepthRenderer=null),this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Vl(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new Vl(this._scene,!0)),this._colorRendererWithSAO}},{key:"colorQualityRendererWithSAO",get:function(){return this._colorQualityRendererWithSAO||(this._colorQualityRendererWithSAO=new TrianglesDataTextureColorQualityRenderer(this._scene,!0)),this._colorQualityRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ql(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new zu(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new Zu(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new nu(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new ou(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new pu(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Lu(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new ec(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new yu(this._scene)),this._pickDepthRenderer}},{key:"vertexDepthRenderer",get:function(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new Du(this._scene)),this._vertexDepthRenderer}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Su(this._scene)),this._snapDepthBufInitRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Gu(this._scene)),this._occlusionRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._colorRendererWithSAO&&this._colorRendererWithSAO.destroy(),this._flatColorRenderer&&this._flatColorRenderer.destroy(),this._flatColorRendererWithSAO&&this._flatColorRendererWithSAO.destroy(),this._colorQualityRendererWithSAO&&this._colorQualityRendererWithSAO.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._normalsRenderer&&this._normalsRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._edgesRenderer&&this._edgesRenderer.destroy(),this._edgesColorRenderer&&this._edgesColorRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._vertexDepthRenderer&&this._vertexDepthRenderer.destroy(),this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._pickNormalsRenderer&&this._pickNormalsRenderer.destroy(),this._pickNormalsFlatRenderer&&this._pickNormalsFlatRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}]),e}(),nc={};var rc=P((function e(){b(this,e),this.positionsCompressed=[],this.metallicRoughness=[],this.indices8Bits=[],this.indices16Bits=[],this.indices32Bits=[],this.edgeIndices8Bits=[],this.edgeIndices16Bits=[],this.edgeIndices32Bits=[],this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]})),ic=function(){function e(){b(this,e),this.texturePerObjectIdColorsAndFlags=null,this.texturePerObjectIdOffsets=null,this.texturePerObjectIdPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}return P(e,[{key:"finalize",value:function(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}},{key:"bindCommonTextures",value:function(e,t,n,r,i,a){this.texturePerObjectIdPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,n,2),this.texturePerObjectIdColorsAndFlags.bindTexture(e,r,3),this.texturePerObjectIdOffsets.bindTexture(e,a,4)}},{key:"bindTriangleIndicesTextures",value:function(e,t,n,r){this.indicesPortionIdsPerBitnessTextures[r].bindTexture(e,t,5),this.indicesPerBitnessTextures[r].bindTexture(e,n,6)}},{key:"bindEdgeIndicesTextures",value:function(e,t,n,r){this.edgeIndicesPortionIdsPerBitnessTextures[r].bindTexture(e,t,5),this.edgeIndicesPerBitnessTextures[r].bindTexture(e,n,6)}}]),e}(),ac=function(){function e(t,n,r,i){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;b(this,e),this._gl=t,this._texture=n,this._textureWidth=r,this._textureHeight=i,this._textureData=a}return P(e,[{key:"bindTexture",value:function(e,t,n){return e.bindTexture(t,this,n)}},{key:"bind",value:function(e){return this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,this._texture),!0}},{key:"unbind",value:function(e){}}]),e}(),sc={sizeDataColorsAndFlags:0,sizeDataPositionDecodeMatrices:0,sizeDataTextureOffsets:0,sizeDataTexturePositions:0,sizeDataTextureIndices:0,sizeDataTextureEdgeIndices:0,sizeDataTexturePortionIds:0,numberOfGeometries:0,numberOfPortions:0,numberOfLayers:0,numberOfTextures:0,totalPolygons:0,totalPolygons8Bits:0,totalPolygons16Bits:0,totalPolygons32Bits:0,totalEdges:0,totalEdges8Bits:0,totalEdges16Bits:0,totalEdges32Bits:0,cannotCreatePortion:{because10BitsObjectId:0,becauseTextureSize:0},overheadSizeAlignementIndices:0,overheadSizeAlignementEdgeIndices:0};window.printDataTextureRamStats=function(){console.log(JSON.stringify(sc,null,4));var e=0;Object.keys(sc).forEach((function(t){t.startsWith("size")&&(e+=sc[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/sc.totalPolygons).toFixed(2)));var t={};Object.keys(sc).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((sc[n]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var oc=function(){function e(){b(this,e)}return P(e,[{key:"disableBindedTextureFiltering",value:function(e){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}},{key:"generateTextureForColorsAndFlags",value:function(e,t,n,r,i,a,s){var o=t.length;this.numPortions=o;var l=4096,u=Math.ceil(o/512);if(0===u)throw"texture height===0";var c=new Uint8Array(16384*u);sc.sizeDataColorsAndFlags+=c.byteLength,sc.numberOfTextures++;for(var f=0;f>24&255,r[f]>>16&255,r[f]>>8&255,255&r[f]],32*f+16),c.set([i[f]>>24&255,i[f]>>16&255,i[f]>>8&255,255&i[f]],32*f+20),c.set([a[f]>>24&255,a[f]>>16&255,a[f]>>8&255,255&a[f]],32*f+24),c.set([s[f]?1:0,0,0,0],32*f+28);var p=e.createTexture();return e.bindTexture(e.TEXTURE_2D,p),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8UI,l,u),e.texSubImage2D(e.TEXTURE_2D,0,0,0,l,u,e.RGBA_INTEGER,e.UNSIGNED_BYTE,c,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new ac(e,p,l,u,c)}},{key:"generateTextureForObjectOffsets",value:function(e,t){var n=512,r=Math.ceil(t/n);if(0===r)throw"texture height===0";var i=new Float32Array(1536*r).fill(0);sc.sizeDataTextureOffsets+=i.byteLength,sc.numberOfTextures++;var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32F,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RGB,e.FLOAT,i,0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),new ac(e,a,n,r,i)}},{key:"generateTextureForPositionsDecodeMatrices",value:function(e,t,n){var r=t.length;if(0===r)throw"num decode+entity matrices===0";var i=2048,a=Math.ceil(r/512),s=new Float32Array(8192*a);sc.sizeDataPositionDecodeMatrices+=s.byteLength,sc.numberOfTextures++;for(var o=$.mat4(),l=0;l65536&&sc.cannotCreatePortion.because10BitsObjectId++;var n=this._numPortions+t<=65536,r=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(0):"".concat(e.id,"#").concat(0);if(!this._bucketGeometries[r]){var i=Math.max(this._state.numIndices8Bits,this._state.numIndices16Bits,this._state.numIndices32Bits),a=0,s=0;e.buckets.forEach((function(e){a+=e.positionsCompressed.length/3,s+=e.indices.length/3})),(this._state.numVertices+a>16777216||i+s>16777216)&&sc.cannotCreatePortion.becauseTextureSize++,n&&(n=this._state.numVertices+a<=16777216&&i+s<=16777216)}return n}},{key:"createPortion",value:function(e){var t=this;if(this._finalized)throw"Already finalized";var n=[],r=e.worldAABB;e.buckets.forEach((function(i,a){var s=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(a):"".concat(e.id,"#").concat(a),o=t._bucketGeometries[s];o||(o=t._createBucketGeometry(e,i),t._bucketGeometries[s]=o);var l=$.collapseAABB3(pc),u=t._createSubPortion(e,o,i,l);$.expandAABB3(r,l),n.push(u)}));var i=this._state.origin;0===i[0]&&0===i[1]&&0===i[2]||(r[0]+=i[0],r[1]+=i[1],r[2]+=i[2],r[3]+=i[0],r[4]+=i[1],r[5]+=i[2]),$.expandAABB3(this.aabb,r);var a=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(n),this.model.numPortions++,a}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var n=8*Math.ceil(t.indices.length/3/8)*3;sc.overheadSizeAlignementIndices+=2*(n-t.indices.length);var r=new Uint32Array(n);r.fill(0),r.set(t.indices),t.indices=r}if(t.edgeIndices){var i=8*Math.ceil(t.edgeIndices.length/2/8)*2;sc.overheadSizeAlignementEdgeIndices+=2*(i-t.edgeIndices.length);var a=new Uint32Array(i);a.fill(0),a.set(t.edgeIndices),t.edgeIndices=a}for(var s,o=t.positionsCompressed,l=t.indices,u=t.edgeIndices,c=this._buffer,f=c.positionsCompressed.length/3,p=o.length/3,A=0,d=o.length;A0){var I,y=3*t.numTriangles;t.numVertices<=256?(I=f.perTriangleNumberPortionId8Bits,p.numIndices8Bits+=y,sc.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(I=f.perTriangleNumberPortionId16Bits,p.numIndices16Bits+=y,sc.totalPolygons16Bits+=t.numTriangles):(I=f.perTriangleNumberPortionId32Bits,p.numIndices32Bits+=y,sc.totalPolygons32Bits+=t.numTriangles),sc.totalPolygons+=t.numTriangles;for(var m=0;m0){var w,g=2*t.numEdges;t.numVertices<=256?(w=f.perEdgeNumberPortionId8Bits,p.numEdgeIndices8Bits+=g,sc.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(w=f.perEdgeNumberPortionId16Bits,p.numEdgeIndices16Bits+=g,sc.totalEdges16Bits+=t.numEdges):(w=f.perEdgeNumberPortionId32Bits,p.numEdgeIndices32Bits+=g,sc.totalEdges32Bits+=t.numEdges),sc.totalEdges+=t.numEdges;for(var T=0;T0&&(n.texturePerEdgeIdPortionIds8Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perEdgeNumberPortionId8Bits)),i.perEdgeNumberPortionId16Bits.length>0&&(n.texturePerEdgeIdPortionIds16Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perEdgeNumberPortionId16Bits)),i.perEdgeNumberPortionId32Bits.length>0&&(n.texturePerEdgeIdPortionIds32Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perEdgeNumberPortionId32Bits)),i.indices8Bits.length>0&&(n.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(r,i.indices8Bits)),i.indices16Bits.length>0&&(n.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(r,i.indices16Bits)),i.indices32Bits.length>0&&(n.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(r,i.indices32Bits)),i.edgeIndices8Bits.length>0&&(n.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(r,i.edgeIndices8Bits)),i.edgeIndices16Bits.length>0&&(n.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(r,i.edgeIndices16Bits)),i.edgeIndices32Bits.length>0&&(n.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(r,i.edgeIndices32Bits)),n.finalize(),this._buffer=null,this._bucketGeometries={},this._finalized=!0,this._deferredSetFlagsDirty=!1,this._onSceneRendering=this.model.scene.on("rendering",(function(){e._deferredSetFlagsDirty&&e._uploadDeferredFlags(),e._numUpdatesInFrame=0}))}}},{key:"isEmpty",value:function(){return 0===this._numPortions}},{key:"initFlags",value:function(e,t,n){t&Ee&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&_e&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ce&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&Be&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&Pe&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Oe&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&De&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&be&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,n,true),this._setFlags2(e,t,true)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags(),this._setDeferredFlags2()}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&_e?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,n)}},{key:"setXRayed",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ce?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Be?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Oe?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){if(!this._finalized)throw"Not finalized";t&Pe?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}},{key:"_beginDeferredFlags",value:function(){this._deferredSetFlagsActive=!0}},{key:"_uploadDeferredFlags",value:function(){if(console.info("_uploadDeferredFlags"),this._deferredSetFlagsActive=!1,this._deferredSetFlagsDirty){this._deferredSetFlagsDirty=!1;var e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdColorsAndFlags._textureWidth,t.texturePerObjectIdColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectIdColorsAndFlags._textureData),e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdOffsets._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdOffsets._textureWidth,t.texturePerObjectIdOffsets._textureHeight,e.RGB,e.FLOAT,t.texturePerObjectIdOffsets._textureData)}}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numCulledLayerPortions+=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions-=this._portionToSubPortionsMap[e].length,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&De?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){for(var n=this._portionToSubPortionsMap[e],r=0,i=n.length;r=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectIdColorsAndFlags._texture),r.texSubImage2D(r.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,r.RGBA_INTEGER,r.UNSIGNED_BYTE,cc)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){for(var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=this._portionToSubPortionsMap[e],a=0,s=i.length;a3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=!!(t&Ee),o=!!(t&Ce),l=!!(t&_e),u=!!(t&Be),c=!!(t&Oe),f=!!(t&De),p=!!(t&be);i=!s||p||o?Ia.NOT_RENDERED:n?Ia.COLOR_TRANSPARENT:Ia.COLOR_OPAQUE,a=!s||p?Ia.NOT_RENDERED:u?Ia.SILHOUETTE_SELECTED:l?Ia.SILHOUETTE_HIGHLIGHTED:o?Ia.SILHOUETTE_XRAYED:Ia.NOT_RENDERED;var A=0;A=!s||p?Ia.NOT_RENDERED:u?Ia.EDGES_SELECTED:l?Ia.EDGES_HIGHLIGHTED:o?Ia.EDGES_XRAYED:c?n?Ia.EDGES_COLOR_TRANSPARENT:Ia.EDGES_COLOR_OPAQUE:Ia.NOT_RENDERED;var d=s&&f?Ia.PICK:Ia.NOT_RENDERED,v=this._dataTextureState,h=this.model.scene.canvas.gl;cc[0]=i,cc[1]=a,cc[2]=A,cc[3]=d,v.texturePerObjectIdColorsAndFlags._textureData.set(cc,32*e+8),this._deferredSetFlagsActive||r?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),h.bindTexture(h.TEXTURE_2D,v.texturePerObjectIdColorsAndFlags._texture),h.texSubImage2D(h.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,h.RGBA_INTEGER,h.UNSIGNED_BYTE,cc))}},{key:"_setDeferredFlags",value:function(){}},{key:"_setFlags2",value:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=this._portionToSubPortionsMap[e],i=0,a=r.length;i2&&void 0!==arguments[2]&&arguments[2];if(!this._finalized)throw"Not finalized";var r=t&Pe?255:0,i=this._dataTextureState,a=this.model.scene.canvas.gl;cc[0]=r,cc[1]=0,cc[2]=1,cc[3]=2,i.texturePerObjectIdColorsAndFlags._textureData.set(cc,32*e+12),this._deferredSetFlagsActive||n?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectIdColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,cc))}},{key:"_setDeferredFlags2",value:function(){}},{key:"setOffset",value:function(e,t){for(var n=this._portionToSubPortionsMap[e],r=0,i=n.length;r=10&&this._beginDeferredFlags(),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectIdOffsets._texture),r.texSubImage2D(r.TEXTURE_2D,0,0,e,1,1,r.RGB,r.FLOAT,fc))}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),t.withSAO&&this.model.saoEnabled?this._dataTextureRenderers.colorRendererWithSAO&&this._dataTextureRenderers.colorRendererWithSAO.drawLayer(t,this,Ia.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"_updateBackfaceCull",value:function(e,t){var n=this.model.backfaces||e.sectioned;if(t.backfaces!==n){var r=t.gl;n?r.disable(r.CULL_FACE):r.enable(r.CULL_FACE),t.backfaces=n}}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Ia.COLOR_TRANSPARENT))}},{key:"drawDepth",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.depthRenderer&&this._dataTextureRenderers.depthRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"drawNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.normalsRenderer&&this._dataTextureRenderers.normalsRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_XRAYED))}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_HIGHLIGHTED))}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.silhouetteRenderer&&this._dataTextureRenderers.silhouetteRenderer.drawLayer(t,this,Ia.SILHOUETTE_SELECTED))}},{key:"drawEdgesColorOpaque",value:function(e,t){this.model.scene.logarithmicDepthBufferEnabled?this.model.scene._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),this.model.scene._loggedWarning=!0):this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Ia.EDGES_COLOR_OPAQUE)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numEdgesLayerPortions&&0!==this._numTransparentLayerPortions&&this._dataTextureRenderers.edgesColorRenderer&&this._dataTextureRenderers.edgesColorRenderer.drawLayer(t,this,Ia.EDGES_COLOR_TRANSPARENT)}},{key:"drawEdgesHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Ia.EDGES_HIGHLIGHTED)}},{key:"drawEdgesSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Ia.EDGES_SELECTED)}},{key:"drawEdgesXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._dataTextureRenderers.edgesRenderer&&this._dataTextureRenderers.edgesRenderer.drawLayer(t,this,Ia.EDGES_XRAYED)}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.occlusionRenderer&&this._dataTextureRenderers.occlusionRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"drawShadow",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.shadowRenderer&&this._dataTextureRenderers.shadowRenderer.drawLayer(t,this,Ia.COLOR_OPAQUE))}},{key:"setPickMatrices",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickMeshRenderer&&this._dataTextureRenderers.pickMeshRenderer.drawLayer(t,this,Ia.PICK))}},{key:"drawPickDepths",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,Ia.PICK))}},{key:"drawSnapInitDepthBuf",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.snapDepthBufInitRenderer&&this._dataTextureRenderers.snapDepthBufInitRenderer.drawLayer(t,this,Ia.PICK))}},{key:"drawSnapDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.vertexDepthRenderer&&this._dataTextureRenderers.vertexDepthRenderer.drawLayer(t,this,Ia.PICK))}},{key:"drawPickNormals",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickNormalsRenderer&&this._dataTextureRenderers.pickNormalsRenderer.drawLayer(t,this,Ia.PICK))}},{key:"destroy",value:function(){if(!this._destroyed){var e=this._state;e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),this.model.scene.off(this._onSceneRendering),e.destroy(),this._destroyed=!0}}}]),e}(),hc=$.vec3();$.mat4();var Ic=$.vec3([1,1,1]),yc=$.vec3([0,0,0]),mc=$.vec3([0,0,0]),wc=$.identityQuaternion(),gc=$.identityMat4(),Tc=new Uint8Array([255,255,255]),Ec=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!0,r._vboBatchingLayerScratchMemory=ha(),r._textureTranscoder=i.textureTranscoder||Dl(r.scene.viewer),r._maxGeometryBatchSize=i.maxGeometryBatchSize,r._aabb=$.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r._meshList=[],r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._meshes={},r._entities={},r._scheduledMeshes={},r.renderFlags=new Xr,r.numGeometries=0,r.numPortions=0,r.numVisibleLayerPortions=0,r.numTransparentLayerPortions=0,r.numXRayedLayerPortions=0,r.numHighlightedLayerPortions=0,r.numSelectedLayerPortions=0,r.numEdgesLayerPortions=0,r.numPickableLayerPortions=0,r.numClippableLayerPortions=0,r.numCulledLayerPortions=0,r.numEntities=0,r._numTriangles=0,r._numLines=0,r._numPoints=0,r._edgeThreshold=i.edgeThreshold||10,r._origin=$.vec3(i.origin||[0,0,0]),r._position=$.vec3(i.position||[0,0,0]),r._rotation=$.vec3(i.rotation||[0,0,0]),r._quaternion=$.vec4(i.quaternion||[0,0,0,1]),r._conjugateQuaternion=$.vec4(i.quaternion||[0,0,0,1]),i.rotation&&$.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=$.vec3(i.scale||[1,1,1]),r._worldRotationMatrix=$.mat4(),r._worldRotationMatrixConjugate=$.mat4(),r._matrix=$.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=$.mat4(),$.inverseMat4(r._matrix,r._worldNormalMatrix),$.transposeMat4(r._worldNormalMatrix),(i.matrix||i.position||i.rotation||i.scale||i.quaternion)&&(r._viewMatrix=$.mat4(),r._viewNormalMatrix=$.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==i.saoEnabled,r._pbrEnabled=!1!==i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r._onCameraViewMatrix=r.scene.camera.on("matrix",(function(){r._viewMatrixDirty=!0})),r.scene.vfc.enabled&&(r._vfcManager=r.scene.vfc.getVFCManager(g(r))),r._createDefaultTextureSet(),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.backfaces=i.backfaces,r}return P(n,[{key:"_createDefaultTextureSet",value:function(){var e=new dl({id:"defaultColorTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new dl({id:"defaultMetalRoughTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new dl({id:"defaultNormalsTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new dl({id:"defaultEmissiveTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new dl({id:"defaultOcclusionTexture",texture:new vi({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})});this._textures.defaultColorTexture=e,this._textures.defaultMetalRoughTexture=t,this._textures.defaultNormalsTexture=n,this._textures.defaultEmissiveTexture=r,this._textures.defaultOcclusionTexture=i,this._textureSets.defaultTextureSet=new Al({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),$.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),$.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||gc),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&($.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),$.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),$.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),$.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0}},{key:"_setLocalAABBDirty",value:function(){for(var e=0,t=this._entityList.length;e0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var n=e.colors,r=new Uint8Array(n.length),i=0,a=n.length;i0){var t=$.collapseAABB3();$.expandAABB3Points3(t,e.positionsCompressed),ht.decompressAABB(t,e.positionsDecodeMatrix),$.AABB3ToOBB3(t,e.obb)}else if(e.positions&&e.positions.length>0){var n=$.collapseAABB3();$.expandAABB3Points3(n,e.positions),$.AABB3ToOBB3(n,e.obb)}}(e.geometry)}e.numPrimitives=this._getNumPrimitives(e),this._vfcManager&&!this._vfcManager.finalized?this._vfcManager.addMesh(e):this._createMesh(e)}else this.error("[createMesh] SceneModel.createMesh() config missing: id")}},{key:"_createMesh",value:function(e){var t=new Aa(this,e.id,e.color,e.opacity);t.pickId=this.scene._renderer.getPickID(t);var n=t.pickId,r=n>>24&255,i=n>>16&255,a=n>>8&255,s=255&n;switch(e.pickColor=new Uint8Array([s,a,i,r]),e.worldAABB=$.collapseAABB3(),e.aabb=e.worldAABB,e.solid="solid"===e.primitive,t.origin=$.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e);break;case 1:t.layer=this._getVBOBatchingLayer(e);break;case 0:t.layer=this._getVBOInstancingLayer(e)}t.portionId=t.layer.createPortion(e),t.aabb=e.worldAABB,t.numPrimitives=e.numPrimitives,$.expandAABB3(this._aabb,t.aabb),this._meshes[e.id]=t,this._meshList.push(t)}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var n=0,r=e.buckets.length;n>>0).toString(16)}},{key:"_getVBOInstancingLayer",value:function(e){var t=this,n=e.origin,r=e.textureSetId||"-",i=e.geometryId,a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(r,".").concat(i),s=this._vboInstancingLayers[a];if(s)return s;for(var o=e.textureSet,l=e.geometry;!s;)switch(l.primitive){case"triangles":case"surface":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesInstancingLayer")),s=new wo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesInstancingLayer")),s=new wo({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":console.info("[SceneModel ".concat(this.id,"]: creating LinesInstancingLayer")),s=new Ho({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":console.info("[SceneModel ".concat(this.id,"]: creating PointsInstancingLayer")),s=new pl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0})}return this._vboInstancingLayers[a]=s,this.layerList.push(s),s}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=$.createUUID():this.scene.components[e.id]&&(this.error("Scene already has a Component with this ID: ".concat(e.id," - will assign random ID")),e.id=$.createUUID()),void 0!==e.meshIds){var t=0;if(this._visible&&!1!==e.visible&&(t|=Ee),this._pickable&&!1!==e.pickable&&(t|=De),this._culled&&!1!==e.culled&&(t|=be),this._clippable&&!1!==e.clippable&&(t|=Pe),this._collidable&&!1!==e.collidable&&(t|=Re),this._edges&&!1!==e.edges&&(t|=Oe),this._xrayed&&!1!==e.xrayed&&(t|=Ce),this._highlighted&&!1!==e.highlighted&&(t|=_e),this._selected&&!1!==e.selected&&(t|=Be),e.flags=t,this._vfcManager&&!this._vfcManager.finalized){for(var n=0,r=e.meshIds.length;nt.sortId?1:0}));for(var s=0,o=this.layerList.length;s0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,n=this.layerList.length;t0)for(var a=0;a0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var n=this.scene.selectedMaterial._state;n.fill&&(n.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var r=this.scene.highlightMaterial._state;r.fill&&(r.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"drawColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=Sl(e.indices||[],t),a=xl(e.edgeIndices||[]);function s(e,t){if(e>t){var n=e;e=t,t=n}function r(n,r){return n!==e?e-n:r!==t?t-r:0}for(var i=0,s=(a.length>>1)-1;i<=s;){var o=s+i>>1,l=r(a[2*o],a[2*o+1]);if(l>0)i=o+1;else{if(!(l<0))return o;s=o-1}}return-i-1}var o=new Int32Array(a.length/2);o.fill(0);var l=r.length/3;if(l>8*(1<p.maxNumPositions&&(p=f()),p.bucketNumber>8)return[e];-1===u[h]&&(u[h]=p.numPositions++,p.positionsCompressed.push(r[3*h]),p.positionsCompressed.push(r[3*h+1]),p.positionsCompressed.push(r[3*h+2])),-1===u[I]&&(u[I]=p.numPositions++,p.positionsCompressed.push(r[3*I]),p.positionsCompressed.push(r[3*I+1]),p.positionsCompressed.push(r[3*I+2])),-1===u[y]&&(u[y]=p.numPositions++,p.positionsCompressed.push(r[3*y]),p.positionsCompressed.push(r[3*y+1]),p.positionsCompressed.push(r[3*y+2])),p.indices.push(u[h]),p.indices.push(u[I]),p.indices.push(u[y]);var m=void 0;(m=s(h,I))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(h,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]])),(m=s(I,y))>=0&&0===o[m]&&(o[m]=1,p.edgeIndices.push(u[a[2*m]]),p.edgeIndices.push(u[a[2*m+1]]))}var w=t/8*2,g=t/8,T=2*r.length+(i.length+a.length)*w,E=0;return r.length,c.forEach((function(e){E+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),E>T?[e]:(n&&Ml(c,e),c)}({positionsCompressed:r,indices:i,edgeIndices:a},r.length/3>65536?16:8):s=[{positionsCompressed:r,indices:i,edgeIndices:a}];return s}var Dc=function(e){I(n,Ec);var t=m(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n)}(),Pc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({active:!0,pos:$.vec3(),dir:$.vec3(),dist:0}),r.active=i.active,r.pos=i.pos,r.dir=i.dir,r.scene._sectionPlaneCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"SectionPlane"}},{key:"active",get:function(){return this._state.active},set:function(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active)}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos)}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[0,0,-1]),this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir)}},{key:"dist",get:function(){return this._state.dist}},{key:"flipDir",value:function(){var e=this._state.dir;e[0]*=-1,e[1]*=-1,e[2]*=-1,this._state.dist=-$.dotVec3(this._state.pos,this._state.dir),this.fire("dir",this._state.dir),this.glRedraw()}},{key:"destroy",value:function(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Rc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._skyboxMesh=new si(g(r),{geometry:new mt(g(r),{primitive:"triangles",positions:[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],uv:[.5,.6666,.25,.6666,.25,.3333,.5,.3333,.5,.6666,.5,.3333,.75,.3333,.75,.6666,.5,.6666,.5,1,.25,1,.25,.6666,.25,.6666,0,.6666,0,.3333,.25,.3333,.25,0,.5,0,.5,.3333,.25,.3333,.75,.3333,1,.3333,1,.6666,.75,.6666],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]}),background:!0,scale:[2e3,2e3,2e3],rotation:[0,-90,0],material:new fi(g(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new gi(g(r),{src:i.src,flipY:!0,wrapS:"clampToEdge",wrapT:"clampToEdge",encoding:i.encoding||"sRGB"}),backfaces:!0}),visible:!1,pickable:!1,clippable:!1,collidable:!1}),r.size=i.size,r.active=i.active,r}return P(n,[{key:"size",get:function(){return this._size},set:function(e){this._size=e||1e3,this._skyboxMesh.scale=[this._size,this._size,this._size]}},{key:"active",get:function(){return this._skyboxMesh.visible},set:function(e){this._skyboxMesh.visible=e}}]),n}(),Cc=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),_c=function(){function e(t,n){b(this,e),this.primLODLevels=t,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=n,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}return P(e,[{key:"initializeLodState",value:function(e){var t=Object.values(e.objects);if(0!==t.length){for(var n={},r={},i=0,a=t.length;i=this.primLODLevels[l]);l++);var u=this.primLODLevels[l]||0;u in n||(n[u]=[]),n[u].push(s),u in r||(r[u]=0),r[u]+=s.numPrimitives}this.entitiesInLOD=n,this.primCountInLOD=r}}}]),e}(),Bc=function(){function e(t,n,r,i){b(this,e),this.id=n.id,this.scene=t,this.sceneModel=n,this.lodState=new _c(r,i),this.lodState.initializeLodState(n)}return P(e,[{key:"_increaseLODLevelIndex",value:function(){var e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;for(var t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[],n=0,r=t.length;n0&&(t.consecutiveFramesWithoutTargetFps=0,n=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,n=this._decreaseLODLevelIndex()),n}},{key:"resetLodCulling",value:function(){var e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}]),e}(),Oc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._scene=e,r._lodLevels=[2e3,600,150,80,20],r._lodManagers={},r._lodManagerList=[],r.enabled=i.enabled,r.targetFPS=i.targetFPS,r._init(),r}return P(n,[{key:"_init",value:function(){var e=this,t=new Array(4),n=0,r=-1,i=Date.now(),a=0,s=0,o=s;this._scene.on("rendering",(function(){if(-1!==r)for(var t=0,n=e._lodManagerList.length;t4){for(var o=0;o<4;o++)s+=t[o];r=4/s*1e3}}))})),this._scene.camera.on("matrix",(function(){o=s})),this._scene.on("tick",(function(){if(s-o>3)for(var t=0,n=e._lodManagerList.length;t=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},n.boxRayIntersects=function(e,t,n,r,i,a,s){var o=(e.minX-t)*i,l=(e.maxX-t)*i,u=(e.minY-n)*a,c=(e.maxY-n)*a,f=(e.minZ-r)*s,p=(e.maxZ-r)*s,A=Math.min(f,p),d=Math.max(f,p),v=Math.min(u,c),h=Math.max(u,c),I=Math.min(o,l),y=Math.max(o,l),m=Math.max(0,I,v,A);return Math.min(y,h,d)>=m?m:1/0};var g=function(e,t,n,i,a){for(var s,o=[t,n];o.length;)(n=o.pop())-(t=o.pop())<=i||(s=t+Math.ceil((n-t)/i/2)*i,r(e,s,t,n,a),o.push(t,s,s,n))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var n=this.data,r=[];if(!e(n,f(n)))return r;for(var i=[];n;){for(var a=0,s=n.children.length;a1){for(d=0,v=(c=c[c.length-1]).length;d=t)break;var i=r+1;if(i0;){var r=n-1>>1;if(A[r].dist<=A[n].dist)break;d(n,r),n=r}},I=o;A.length&&A[0].dist=t;o--){l=e.children[o];v(a,l),s+=I(a)}return s},e.prototype.adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)v(t[r],e)},e.prototype.condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)0===e[t].children.length?t>0?((n=e[t-1].children).splice(n.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,n){var r=[],i=this.chooseSubtree(e,this.data,t,r);for(i.children.push(e),v(i,e);t>=0&&r[t].children.length>this.maxEntries;)this.split(r,t),t--;this.adjustParentBBoxes(e,r,t)},e.pool=[],e}();n.RBush3D=D},{quickselect:2}],2:[function(e,t,n){!function(e,r){"object"===E(n)&&void 0!==t?t.exports=r():e.quickselect=r()}(this,(function(){function e(n,r,i,a,s){for(;a>i;){if(a-i>600){var o=a-i+1,l=r-i+1,u=Math.log(o),c=.5*Math.exp(2*u/3),f=.5*Math.sqrt(u*c*(o-c)/o)*(l-o/2<0?-1:1);e(n,r,Math.max(i,Math.floor(r-l*c/o+f)),Math.min(a,Math.floor(r+(o-l)*c/o+f)),s)}var p=n[r],A=i,d=a;for(t(n,i,r),s(n[a],p)>0&&t(n,i,a);A0;)d--}0===s(n[i],p)?t(n,i,d):t(n,++d,a),d<=r&&(i=d+1),r<=d&&(a=d-1)}}function t(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function n(e,t){return et?1:0}return function(t,r,i,a,s){e(t,r,i||0,a||t.length-1,s||n)}}))},{}]},{},[1])(1)}));var Lc=Sc.exports.RBush3D,xc=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function n(e,t){var n={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function r(){(0==n.dir&&n.pos.x+1>=n.right||1==n.dir&&n.pos.y+1>=n.bottom||2==n.dir&&n.pos.x-1<=n.left-1||3==n.dir&&n.pos.y-1<=n.top-1)&&(n.dir=(n.dir+1)%4,0==n.dir&&n.left++,1==n.dir&&n.top++,2==n.dir&&n.right--,3==n.dir&&n.bottom--),0==n.dir&&n.pos.x++,1==n.dir&&n.pos.y++,2==n.dir&&n.pos.x--,3==n.dir&&n.pos.y--}for(var i=[],a=e*t;i.lengthp&&(c.push(f),f=[],p=o),f.push(d),p-=v}}while(Ap&&(c.push(A),A=[],p=o),A.push(e),p-=n})),A.length&&c.push(A);var d={};return c.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:c,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,r.maxPolygonsPerCluster),{clusters:{total:s.clusters.length},clusteringResult:s});o+=l.clusters.total,console.log("Total clusters: "+o);var u=[];return l.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){u.push(e.id)}))})),l.orderedEntityIds=u,l}; /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT @@ -23,7 +23,7 @@ var e,t=l().mark(qT),n=l().mark(JT),r=l().mark(lP);function i(e){return function * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT */ -function Mc(e,t){t.length;for(var n=e.length,r=[],i=[],a=function(n){var a=e[n];if(function(e){for(var n=0,r=e.meshIds.length;n0){o=function(e){for(var t=[],n=0,r=e.length;nthis._frustumProps.CAM_FACTOR_1?(n|=l<0?64:128,n&=-17):n&=-33;var u=Qc($.dotVec3(s,this._frustumProps.up),o);Math.abs(u)>this._frustumProps.CAM_FACTOR_2?(n|=u<0?1024:2048,n&=-257):n&=-513}return 4&n&&8&n&&(n|=4096),64&n&&128&n&&(n|=8192),1024&n&&2048&n&&(n|=16384),e._check=n,n}}]),e}(),zc=function(){function e(t,n){b(this,e),this.sceneModel=n,this.entities=[],this.meshes=[],this.finalized=!1}return P(e,[{key:"addEntity",value:function(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}},{key:"addMesh",value:function(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}},{key:"finalize",value:function(e){var t=this;if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new Wc,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(function(){return t.applyViewFrustumCulling.call(t)}))}},{key:"applyViewFrustumCulling",value:function(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}},{key:"destroy",value:function(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}]),e}(),Kc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._scene=e,r._vfcManagers={},r._vfcManagerList=[],r.enabled=i.enabled,r._init(),r}return P(n,[{key:"_init",value:function(){var e=this;this._scene.on("rendering",(function(){for(var t=0,n=e._vfcManagerList.length;t1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._canvas=i.canvas,r._element=null,r._isCustom=!1,i.elementId&&(r._element=document.getElementById(i.elementId),r._element?r._adjustPosition():r.error("Can't find given Spinner HTML element: '"+i.elementId+"' - will automatically create default element")),r._element||r._createDefaultSpinner(),r.processes=0,r}return P(n,[{key:"type",get:function(){return"Spinner"}},{key:"_createDefaultSpinner",value:function(){this._injectDefaultCSS();var e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}},{key:"_injectDefaultCSS",value:function(){var e="xeokit-spinner-css";if(!document.getElementById(e)){var t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}}},{key:"_adjustPosition",value:function(){if(!this._isCustom){var e=this._canvas,t=this._element,n=t.style;n.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",n.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}}},{key:"processes",get:function(){return this._processes},set:function(e){if(e=e||0,this._processes!==e&&!(e<0)){var t=this._processes;this._processes=e;var n=this._element;n&&(n.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}}},{key:"_destroy",value:function(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);var e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}]),n}(),Xc=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],qc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._backgroundColor=$.vec3([i.backgroundColor?i.backgroundColor[0]:1,i.backgroundColor?i.backgroundColor[1]:1,i.backgroundColor?i.backgroundColor[2]:1]),r._backgroundColorFromAmbientLight=!!i.backgroundColorFromAmbientLight,r.canvas=i.canvas,r.gl=null,r.webgl2=!1,r.transparent=!!i.transparent,r.contextAttr=i.contextAttr||{},r.contextAttr.alpha=r.transparent,r.contextAttr.preserveDrawingBuffer=!!r.contextAttr.preserveDrawingBuffer,r.contextAttr.stencil=!1,r.contextAttr.premultipliedAlpha=!!r.contextAttr.premultipliedAlpha,r.contextAttr.antialias=!1!==r.contextAttr.antialias,r.resolutionScale=i.resolutionScale,r.canvas.width=Math.round(r.canvas.clientWidth*r._resolutionScale),r.canvas.height=Math.round(r.canvas.clientHeight*r._resolutionScale),r.boundary=[r.canvas.offsetLeft,r.canvas.offsetTop,r.canvas.clientWidth,r.canvas.clientHeight],r._initWebGL(i);var a=g(r);r.canvas.addEventListener("webglcontextlost",r._webglcontextlostListener=function(e){console.time("webglcontextrestored"),a.scene._webglContextLost(),a.fire("webglcontextlost"),e.preventDefault()},!1),r.canvas.addEventListener("webglcontextrestored",r._webglcontextrestoredListener=function(e){a._initWebGL(),a.gl&&(a.scene._webglContextRestored(a.gl),a.fire("webglcontextrestored",a.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);var s=!0,o=new ResizeObserver((function(e){var t,n=f(e);try{for(n.s();!(t=n.n()).done;){t.value.contentBoxSize&&(s=!0)}}catch(e){n.e(e)}finally{n.f()}}));return o.observe(r.canvas),r._tick=r.scene.on("tick",(function(){s&&(s=!1,a.canvas.width=Math.round(a.canvas.clientWidth*a._resolutionScale),a.canvas.height=Math.round(a.canvas.clientHeight*a._resolutionScale),a.boundary[0]=a.canvas.offsetLeft,a.boundary[1]=a.canvas.offsetTop,a.boundary[2]=a.canvas.clientWidth,a.boundary[3]=a.canvas.clientHeight,a.fire("boundary",a.boundary))})),r._spinner=new Yc(r.scene,{canvas:r.canvas,elementId:i.spinnerElementId}),r}return P(n,[{key:"type",get:function(){return"Canvas"}},{key:"backgroundColorFromAmbientLight",get:function(){return this._backgroundColorFromAmbientLight},set:function(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}},{key:"resolutionScale",get:function(){return this._resolutionScale},set:function(e){if((e=e||1)!==this._resolutionScale){this._resolutionScale=e;var t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}}},{key:"spinner",get:function(){return this._spinner}},{key:"_createCanvas",value:function(){var e="xeokit-canvas-"+$.createUUID(),t=document.getElementsByTagName("body")[0],n=document.createElement("div"),r=n.style;r.height="100%",r.width="100%",r.padding="0",r.margin="0",r.background="rgba(0,0,0,0);",r.float="left",r.left="0",r.top="0",r.position="absolute",r.opacity="1.0",r["z-index"]="-10000",n.innerHTML+='',t.appendChild(n),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,n=0;e;)t+=e.offsetLeft-e.scrollLeft,n+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:n}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e-t)o._setVisible(!1);else{var l=o.canvasPos,u=l[0],c=l[1];u+10<0||c+10<0||u-10>r||c-10>i?o._setVisible(!1):!o.entity||o.entity.visible?o.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=o,this.pixels[a++]=u,this.pixels[a++]=c):o._setVisible(!0):o._setVisible(!1)}}}},{key:"_updateActiveSectionPlanes",value:function(){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n0,n=[];return n.push("#version 300 es"),n.push("// OcclusionTester vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("vec4 worldPosition = vec4(position, 1.0); "),n.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&n.push(" vWorldPosition = worldPosition;"),n.push(" vec4 clipPos = projMatrix * viewPosition;"),n.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?n.push("vFragDepth = 1.0 + clipPos.w;"):n.push("clipPos.z += -0.001;"),n.push(" gl_Position = clipPos;"),n.push("}"),n}},{key:"_buildFragmentShaderSource",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// OcclusionTester fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;");for(var i=0;i 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),r.push("}"),r}},{key:"_buildProgram",value:function(){this._program&&this._program.destroy();var e=this._scene,t=e.canvas.gl,n=e._sectionPlanesState;if(this._program=new hr(t,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=n.sectionPlanes.length;i0)for(var p=r.sectionPlanes,A=0;A= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var r=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new lt(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),this._uvBuf=new lt(n,n.ARRAY_BUFFER,r,r.length,2,n.STATIC_DRAW),this._indicesBuf=new lt(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}}},{key:"destroy",value:function(){this._program&&(this._program.destroy(),this._program=null)}}]),e}(),sf=new Float32Array(pf(17,[0,1])),of=new Float32Array(pf(17,[1,0])),lf=new Float32Array(function(e,t){for(var n=[],r=0;r<=e;r++)n.push(ff(r,t));return n}(17,4)),uf=new Float32Array(2),cf=function(){function e(t){b(this,e),this._scene=t,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}return P(e,[{key:"init",value:function(){var e=this._scene.canvas.gl;if(this._program=new hr(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS ".concat(16,"\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var t=new Float32Array([1,1,0,1,0,0,1,0]),n=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),r=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new lt(e,e.ARRAY_BUFFER,n,n.length,3,e.STATIC_DRAW),this._uvBuf=new lt(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new lt(e,e.ELEMENT_ARRAY_BUFFER,r,r.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}},{key:"render",value:function(e,t,n){var r=this;if(!this._programError){this._getInverseProjectMat||(this._getInverseProjectMat=function(){var e=!0;r._scene.camera.on("projMatrix",(function(){e=!0}));var t=$.mat4();return function(){return e&&$.inverseMat4(s.camera.projMatrix,t),t}}());var i=this._scene.canvas.gl,a=this._program,s=this._scene,o=i.drawingBufferWidth,l=i.drawingBufferHeight,u=s.camera.project._state,c=u.near,f=u.far;i.viewport(0,0,o,l),i.clearColor(0,0,0,1),i.enable(i.DEPTH_TEST),i.disable(i.BLEND),i.frontFace(i.CCW),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),a.bind(),uf[0]=o,uf[1]=l,i.uniform2fv(this._uViewport,uf),i.uniform1f(this._uCameraNear,c),i.uniform1f(this._uCameraFar,f),i.uniform1f(this._uDepthCutoff,.01),0===n?i.uniform2fv(this._uSampleOffsets,of):i.uniform2fv(this._uSampleOffsets,sf),i.uniform1fv(this._uSampleWeights,lf);var p=e.getDepthTexture(),A=t.getTexture();a.bindTexture(this._uDepthTexture,p,0),a.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),i.drawElements(i.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}}},{key:"destroy",value:function(){this._program.destroy()}}]),e}();function ff(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function pf(e,t){for(var n=[],r=0;r<=e;r++)n.push(t[0]*r),n.push(t[1]*r);return n}var Af=function(){function e(t){b(this,e),this.scene=t,this._renderBuffersBasic={},this._renderBuffersScaled={}}return P(e,[{key:"getRenderBuffer",value:function(e,t){var n=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled,r=n[e];return r||(r=new Vi(this.scene.canvas.canvas,this.scene.canvas.gl,t),n[e]=r),r}},{key:"destroy",value:function(){for(var e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(var t in this._renderBuffersScaled)this._renderBuffersScaled[t].destroy()}}]),e}(),df=function(e,t){t=t||{};var n=new Jc(e),r=e.canvas.canvas,i=e.canvas.gl,a=!!t.transparent,s=t.alphaDepthMask,o=new G({}),l={},u={},c=!0,f=!0,p=!0,A=!0,d=!0,v=!0,h=!0,I=!0,y=new Af(e),m=!1,w=new af(e),g=new cf(e);function T(){c&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e],n=t.drawableMap,r=t.drawableListPreCull,i=0;for(var a in n)n.hasOwnProperty(a)&&(r[i++]=n[a]);r.length=i}}(),c=!1,f=!0),f&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),f=!1,p=!0),p&&function(){for(var e in l)if(l.hasOwnProperty(e)){for(var t=l[e],n=t.drawableListPreCull,r=t.drawableList,i=0,a=0,s=n.length;a0)for(n.withSAO=!0,O=0;O0)for(O=0;O0)for(O=0;O0)for(O=0;O0||Q>0||U>0||G>0){if(i.enable(i.CULL_FACE),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):(i.blendEquation(i.FUNC_ADD),i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,s||i.depthMask(!1),(U>0||G>0)&&i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),G>0)for(O=0;O0)for(O=0;O0)for(O=0;O0)for(O=0;O0||z>0){if(n.lastProgramId=null,e.highlightMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),z>0)for(O=0;O0)for(O=0;O0||Y>0||W>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),i.enable(i.CULL_FACE),Y>0)for(O=0;O0)for(O=0;O0||q>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),q>0)for(O=0;O0)for(O=0;O0||Z>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),i.enable(i.CULL_FACE),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),Z>0)for(O=0;O0)for(O=0;O1&&void 0!==arguments[1]?arguments[1]:o;v.reset(),T();var h=null,I=null;if(v.pickSurface=A.pickSurface,A.canvasPos)c[0]=A.canvasPos[0],c[1]=A.canvasPos[1],h=e.camera.viewMatrix,I=e.camera.projMatrix,v.canvasPos=A.canvasPos;else{var m=$.frustumMat4(-1,1,-1,1,.01,e.camera.project.far,n);A.matrix?(h=A.matrix,I=m):(f.set(A.origin||[0,0,0]),p.set(A.direction||[0,0,1]),d=$.addVec3(f,p,t),a[0]=Math.random(),a[1]=Math.random(),a[2]=Math.random(),$.normalizeVec3(a),$.cross3Vec3(p,a,s),h=$.lookAtMat4v(f,d,s,i),I=m,v.origin=f,v.direction=p),c[0]=.5*r.clientWidth,c[1]=.5*r.clientHeight}for(var w in l)if(l.hasOwnProperty(w))for(var g=l[w].drawableList,E=0,R=g.length;E1&&void 0!==arguments[1]?arguments[1]:30,a=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],s=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!a&&!s)return this.pick({canvasPos:t,pickSurface:!0});n.reset(),n.backfaces=!0,n.frontface=!0,n.pickZNear=e.camera.project.near,n.pickZFar=e.camera.project.far;var o=y.getRenderBuffer("uniquePickColors-aabs",{depthTexture:!0,size:[2*r+1,2*r+1]});n.snapVectorA=[_(t[0],i.drawingBufferWidth),B(t[1],i.drawingBufferHeight)],n.snapInvVectorAB=[i.drawingBufferWidth/(2*r),i.drawingBufferHeight/(2*r)],o.bind(i.RGBA32I),i.viewport(0,0,o.size[0],o.size[1]),i.enable(i.DEPTH_TEST),i.frontFace(i.CCW),i.disable(i.CULL_FACE),i.depthMask(!0),i.disable(i.BLEND),i.depthFunc(i.LESS),i.clear(i.DEPTH_BUFFER_BIT),i.clearBufferiv(i.COLOR,0,new Int32Array([0,0,0,0]));var u=e.camera.viewMatrix,c=e.camera.projMatrix;for(var f in l)if(l.hasOwnProperty(f))for(var p=l[f].drawableList,A=0,d=p.length;A0){var L=Math.floor(N/4),x=o.size[0],M=L%x-Math.floor(x/2),F=Math.floor(L/x)-Math.floor(x/2),H=Math.sqrt(Math.pow(M,2)+Math.pow(F,2));S.push({x:M,y:F,dist:H,isVertex:a&&s?m[N+3]>I.length/2:a,result:[m[N+0],m[N+1],m[N+2],m[N+3]]})}var U=null,G=null;if(S.length>0){S.sort((function(e,t){return e.isVertex!==t.isVertex?e.isVertex?-1:1:e.dist-t.dist})),G=S[0].isVertex?"vertex":"edge";var k=I[(S=S[0].result)[3]],j=k.origin,V=k.coordinateScale;U=[S[0]*V[0]+j[0],S[1]*V[1]+j[1],S[2]*V[2]+j[2]]}if(null===w&&null==U)return null;var Q=null;return null!==U&&(Q=e.camera.projectWorldPos(U)),{snapType:G,snappedToVertex:"vertex"===G,snappedToEdge:"edge"===G,worldPos:w,snappedWorldPos:U,snappedCanvasPos:Q}},this.addMarker=function(t){this._occlusionTester=this._occlusionTester||new nf(e,y),this._occlusionTester.addMarker(t),e.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){for(var e in T(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,i.viewport(0,0,i.drawingBufferWidth,i.drawingBufferHeight),i.clearColor(0,0,0,0),i.enable(i.DEPTH_TEST),i.disable(i.CULL_FACE),i.disable(i.BLEND),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),l)if(l.hasOwnProperty(e))for(var t=l[e].drawableList,r=0,a=t.length;r0&&void 0!==arguments[0]?arguments[0]:{},t=y.getRenderBuffer("snapshot");e.width&&e.height&&t.setSize([e.width,e.height]),t.bind(),t.clear(),m=!0},this.renderSnapshot=function(){m&&(y.getRenderBuffer("snapshot").clear(),this.render({force:!0,opaqueOnly:!1}),p=!0)},this.readSnapshot=function(e){return y.getRenderBuffer("snapshot").readImage(e)},this.readSnapshotAsCanvas=function(){return y.getRenderBuffer("snapshot").readImageAsCanvas()},this.endSnapshot=function(){m&&(y.getRenderBuffer("snapshot").unbind(),m=!1)},this.destroy=function(){l={},u={},y.destroy(),w.destroy(),g.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}},vf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).KEY_BACKSPACE=8,r.KEY_TAB=9,r.KEY_ENTER=13,r.KEY_SHIFT=16,r.KEY_CTRL=17,r.KEY_ALT=18,r.KEY_PAUSE_BREAK=19,r.KEY_CAPS_LOCK=20,r.KEY_ESCAPE=27,r.KEY_PAGE_UP=33,r.KEY_PAGE_DOWN=34,r.KEY_END=35,r.KEY_HOME=36,r.KEY_LEFT_ARROW=37,r.KEY_UP_ARROW=38,r.KEY_RIGHT_ARROW=39,r.KEY_DOWN_ARROW=40,r.KEY_INSERT=45,r.KEY_DELETE=46,r.KEY_NUM_0=48,r.KEY_NUM_1=49,r.KEY_NUM_2=50,r.KEY_NUM_3=51,r.KEY_NUM_4=52,r.KEY_NUM_5=53,r.KEY_NUM_6=54,r.KEY_NUM_7=55,r.KEY_NUM_8=56,r.KEY_NUM_9=57,r.KEY_A=65,r.KEY_B=66,r.KEY_C=67,r.KEY_D=68,r.KEY_E=69,r.KEY_F=70,r.KEY_G=71,r.KEY_H=72,r.KEY_I=73,r.KEY_J=74,r.KEY_K=75,r.KEY_L=76,r.KEY_M=77,r.KEY_N=78,r.KEY_O=79,r.KEY_P=80,r.KEY_Q=81,r.KEY_R=82,r.KEY_S=83,r.KEY_T=84,r.KEY_U=85,r.KEY_V=86,r.KEY_W=87,r.KEY_X=88,r.KEY_Y=89,r.KEY_Z=90,r.KEY_LEFT_WINDOW=91,r.KEY_RIGHT_WINDOW=92,r.KEY_SELECT_KEY=93,r.KEY_NUMPAD_0=96,r.KEY_NUMPAD_1=97,r.KEY_NUMPAD_2=98,r.KEY_NUMPAD_3=99,r.KEY_NUMPAD_4=100,r.KEY_NUMPAD_5=101,r.KEY_NUMPAD_6=102,r.KEY_NUMPAD_7=103,r.KEY_NUMPAD_8=104,r.KEY_NUMPAD_9=105,r.KEY_MULTIPLY=106,r.KEY_ADD=107,r.KEY_SUBTRACT=109,r.KEY_DECIMAL_POINT=110,r.KEY_DIVIDE=111,r.KEY_F1=112,r.KEY_F2=113,r.KEY_F3=114,r.KEY_F4=115,r.KEY_F5=116,r.KEY_F6=117,r.KEY_F7=118,r.KEY_F8=119,r.KEY_F9=120,r.KEY_F10=121,r.KEY_F11=122,r.KEY_F12=123,r.KEY_NUM_LOCK=144,r.KEY_SCROLL_LOCK=145,r.KEY_SEMI_COLON=186,r.KEY_EQUAL_SIGN=187,r.KEY_COMMA=188,r.KEY_DASH=189,r.KEY_PERIOD=190,r.KEY_FORWARD_SLASH=191,r.KEY_GRAVE_ACCENT=192,r.KEY_OPEN_BRACKET=219,r.KEY_BACK_SLASH=220,r.KEY_CLOSE_BRACKET=221,r.KEY_SINGLE_QUOTE=222,r.KEY_SPACE=32,r.element=i.element,r.altDown=!1,r.ctrlDown=!1,r.mouseDownLeft=!1,r.mouseDownMiddle=!1,r.mouseDownRight=!1,r.keyDown=[],r.enabled=!0,r.keyboardEnabled=!0,r.mouseover=!1,r.mouseCanvasPos=$.vec2(),r._keyboardEventsElement=i.keyboardEventsElement||document,r._bindEvents(),r}return P(n,[{key:"_bindEvents",value:function(){var e=this;if(!this._eventsBound){this._keyboardEventsElement.addEventListener("keydown",this._keyDownListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!0:t.keyCode===e.KEY_ALT?e.altDown=!0:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!0),e.keyDown[t.keyCode]=!0,e.fire("keydown",t.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!1:t.keyCode===e.KEY_ALT?e.altDown=!1:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!1),e.keyDown[t.keyCode]=!1,e.fire("keyup",t.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=function(t){e.enabled&&(e.mouseover=!0,e._getMouseCanvasPos(t),e.fire("mouseenter",e.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=function(t){e.enabled&&(e.mouseover=!1,e._getMouseCanvasPos(t),e.fire("mouseleave",e.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!0;break;case 2:e.mouseDownMiddle=!0;break;case 3:e.mouseDownRight=!0}e._getMouseCanvasPos(t),e.element.focus(),e.fire("mousedown",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!1;break;case 2:e.mouseDownMiddle=!1;break;case 3:e.mouseDownRight=!1}e.fire("mouseup",e.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("click",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("dblclick",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=function(t){e.enabled&&(e._getMouseCanvasPos(t),e.fire("mousemove",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=function(t,n){if(e.enabled){var r=Math.max(-1,Math.min(1,40*-t.deltaY));e.fire("mousewheel",r,!0)}},{passive:!0});var t,n;this.on("mousedown",(function(e){t=e[0],n=e[1]})),this.on("mouseup",(function(r){t>=r[0]-2&&t<=r[0]+2&&n>=r[1]-2&&n<=r[1]+2&&e.fire("mouseclicked",r,!0)})),this._eventsBound=!0}}},{key:"_unbindEvents",value:function(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}},{key:"_getMouseCanvasPos",value:function(e){if(e){for(var t=e.target,n=0,r=0;t.offsetParent;)n+=t.offsetLeft,r+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-n,this.mouseCanvasPos[1]=e.pageY-r}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}},{key:"setEnabled",value:function(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}},{key:"getEnabled",value:function(){return this.enabled}},{key:"setKeyboardEnabled",value:function(e){this.keyboardEnabled=e}},{key:"getKeyboardEnabled",value:function(){return this.keyboardEnabled}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._unbindEvents()}}]),n}(),hf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({boundary:[0,0,100,100]}),r.boundary=i.boundary,r.autoBoundary=i.autoBoundary,r}return P(n,[{key:"type",get:function(){return"Viewport"}},{key:"boundary",get:function(){return this._state.boundary},set:function(e){if(!this._autoBoundary){if(!e){var t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}},{key:"autoBoundary",get:function(){return this._autoBoundary},set:function(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){var t=e[2],n=e[3];this._state.boundary=[0,0,t,n],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),If=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new ot({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:2e3}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r._fov=60,r._canvasResized=r.scene.canvas.on("boundary",r._needUpdate,g(r)),r.fov=i.fov,r.fovAxis=i.fovAxis,r.near=i.near,r.far=i.far,r}return P(n,[{key:"type",get:function(){return"Perspective"}},{key:"_update",value:function(){var e=this.scene.canvas.boundary,t=e[2]/e[3],n=this._fovAxis,r=this._fov;("x"===n||"min"===n&&t<1||"max"===n&&t>1)&&(r/=t),r=Math.min(r,120),$.perspectiveMat4(r*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}},{key:"fov",get:function(){return this._fov},set:function(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}},{key:"fovAxis",get:function(){return this._fovAxis},set:function(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,$.mulMat4v4(this.inverseMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}]),n}(),yf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new ot({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:2e3}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.scale=i.scale,r.near=i.near,r.far=i.far,r._onCanvasBoundary=r.scene.canvas.on("boundary",r._needUpdate,g(r)),r}return P(n,[{key:"type",get:function(){return"Ortho"}},{key:"_update",value:function(){var e,t,n,r,i=this.scene,a=.5*this._scale,s=i.canvas.boundary,o=s[2],l=s[3],u=o/l;o>l?(e=-a,t=a,n=a/u,r=-a/u):(e=-a*u,t=a*u,n=a,r=-a),$.orthoMat4c(e,t,r,n,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,$.mulMat4v4(this.inverseMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}]),n}(),mf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new ot({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:1e4}),r._left=-1,r._right=1,r._bottom=-1,r._top=1,r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.left=i.left,r.right=i.right,r.bottom=i.bottom,r.top=i.top,r.near=i.near,r.far=i.far,r}return P(n,[{key:"type",get:function(){return"Frustum"}},{key:"_update",value:function(){$.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"left",get:function(){return this._left},set:function(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}},{key:"right",get:function(){return this._right},set:function(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}},{key:"top",get:function(){return this._top},set:function(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}},{key:"bottom",get:function(){return this._bottom},set:function(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}},{key:"near",get:function(){return this._state.near},set:function(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}},{key:"far",get:function(){return this._state.far},set:function(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,$.mulMat4v4(this.inverseMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),wf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new ot({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4()}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!1,r.matrix=i.matrix,r}return P(n,[{key:"type",get:function(){return"CustomProjection"}},{key:"matrix",get:function(){return this._state.matrix},set:function(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,$.mulMat4v4(this.inverseMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),gf=$.vec3(),Tf=$.vec3(),Ef=$.vec3(),bf=$.vec3(),Df=$.vec3(),Pf=$.vec3(),Rf=$.vec4(),Cf=$.vec4(),_f=$.vec4(),Bf=$.mat4(),Of=$.mat4(),Sf=$.vec3(),Nf=$.vec3(),Lf=$.vec3(),xf=$.vec3(),Mf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({deviceMatrix:$.mat4(),hasDeviceMatrix:!1,matrix:$.mat4(),normalMatrix:$.mat4(),inverseMatrix:$.mat4()}),r._perspective=new If(g(r)),r._ortho=new yf(g(r)),r._frustum=new mf(g(r)),r._customProjection=new wf(g(r)),r._project=r._perspective,r._eye=$.vec3([0,0,10]),r._look=$.vec3([0,0,0]),r._up=$.vec3([0,1,0]),r._worldUp=$.vec3([0,1,0]),r._worldRight=$.vec3([1,0,0]),r._worldForward=$.vec3([0,0,-1]),r.deviceMatrix=i.deviceMatrix,r.eye=i.eye,r.look=i.look,r.up=i.up,r.worldAxis=i.worldAxis,r.gimbalLock=i.gimbalLock,r.constrainPitch=i.constrainPitch,r.projection=i.projection,r._perspective.on("matrix",(function(){"perspective"===r._projectionType&&r.fire("projMatrix",r._perspective.matrix)})),r._ortho.on("matrix",(function(){"ortho"===r._projectionType&&r.fire("projMatrix",r._ortho.matrix)})),r._frustum.on("matrix",(function(){"frustum"===r._projectionType&&r.fire("projMatrix",r._frustum.matrix)})),r._customProjection.on("matrix",(function(){"customProjection"===r._projectionType&&r.fire("projMatrix",r._customProjection.matrix)})),r}return P(n,[{key:"type",get:function(){return"Camera"}},{key:"_update",value:function(){var e,t=this._state;"ortho"===this.projection?($.subVec3(this._eye,this._look,Sf),$.normalizeVec3(Sf,Nf),$.mulVec3Scalar(Nf,1e3,Lf),$.addVec3(this._look,Lf,xf),e=xf):e=this._eye,t.hasDeviceMatrix?($.lookAtMat4v(e,this._look,this._up,Of),$.mulMat4(t.deviceMatrix,Of,t.matrix)):$.lookAtMat4v(e,this._look,this._up,t.matrix),$.inverseMat4(this._state.matrix,this._state.inverseMatrix),$.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}},{key:"orbitYaw",value:function(e){var t=$.subVec3(this._eye,this._look,gf);$.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Bf),t=$.transformPoint3(Bf,t,Tf),this.eye=$.addVec3(this._look,t,Ef),this.up=$.transformPoint3(Bf,this._up,bf)}},{key:"orbitPitch",value:function(e){if(!(this._constrainPitch&&(e=$.dotVec3(this._up,this._worldUp)/$.DEGTORAD)<1)){var t=$.subVec3(this._eye,this._look,gf),n=$.cross3Vec3($.normalizeVec3(t,Tf),$.normalizeVec3(this._up,Ef));$.rotationMat4v(.0174532925*e,n,Bf),t=$.transformPoint3(Bf,t,bf),this.up=$.transformPoint3(Bf,this._up,Df),this.eye=$.addVec3(t,this._look,Pf)}}},{key:"yaw",value:function(e){var t=$.subVec3(this._look,this._eye,gf);$.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Bf),t=$.transformPoint3(Bf,t,Tf),this.look=$.addVec3(t,this._eye,Ef),this._gimbalLock&&(this.up=$.transformPoint3(Bf,this._up,bf))}},{key:"pitch",value:function(e){if(!(this._constrainPitch&&(e=$.dotVec3(this._up,this._worldUp)/$.DEGTORAD)<1)){var t=$.subVec3(this._look,this._eye,gf),n=$.cross3Vec3($.normalizeVec3(t,Tf),$.normalizeVec3(this._up,Ef));$.rotationMat4v(.0174532925*e,n,Bf),this.up=$.transformPoint3(Bf,this._up,Pf),t=$.transformPoint3(Bf,t,bf),this.look=$.addVec3(t,this._eye,Df)}}},{key:"pan",value:function(e){var t,n=$.subVec3(this._eye,this._look,gf),r=[0,0,0];if(0!==e[0]){var i=$.cross3Vec3($.normalizeVec3(n,[]),$.normalizeVec3(this._up,Tf));t=$.mulVec3Scalar(i,e[0]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]}0!==e[1]&&(t=$.mulVec3Scalar($.normalizeVec3(this._up,Ef),e[1]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),0!==e[2]&&(t=$.mulVec3Scalar($.normalizeVec3(n,bf),e[2]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),this.eye=$.addVec3(this._eye,r,Df),this.look=$.addVec3(this._look,r,Pf)}},{key:"zoom",value:function(e){var t=$.subVec3(this._eye,this._look,gf),n=Math.abs($.lenVec3(t,Tf)),r=Math.abs(n+e);if(!(r<.5)){var i=$.normalizeVec3(t,Ef);this.eye=$.addVec3(this._look,$.mulVec3Scalar(i,r),bf)}}},{key:"eye",get:function(){return this._eye},set:function(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}},{key:"look",get:function(){return this._look},set:function(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}},{key:"up",get:function(){return this._up},set:function(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}},{key:"deviceMatrix",get:function(){return this._state.deviceMatrix},set:function(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}},{key:"worldAxis",get:function(){return this._worldAxis},set:function(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=$.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}},{key:"worldUp",get:function(){return this._worldUp}},{key:"xUp",get:function(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}},{key:"yUp",get:function(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}},{key:"zUp",get:function(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}},{key:"worldRight",get:function(){return this._worldRight}},{key:"worldForward",get:function(){return this._worldForward}},{key:"gimbalLock",get:function(){return this._gimbalLock},set:function(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}},{key:"constrainPitch",set:function(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}},{key:"eyeLookDist",get:function(){return $.lenVec3($.subVec3(this._look,this._eye,gf))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"viewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"normalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"viewNormalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"inverseViewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}},{key:"projMatrix",get:function(){return this[this.projection].matrix}},{key:"perspective",get:function(){return this._perspective}},{key:"ortho",get:function(){return this._ortho}},{key:"frustum",get:function(){return this._frustum}},{key:"customProjection",get:function(){return this._customProjection}},{key:"projection",get:function(){return this._projectionType},set:function(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}},{key:"project",get:function(){return this._project}},{key:"projectWorldPos",value:function(e){var t=Rf,n=Cf,r=_f;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,$.mulMat4v4(this.viewMatrix,t,n),$.mulMat4v4(this.projMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1;var i=this.scene.canvas.canvas,a=i.offsetWidth/2,s=i.offsetHeight/2;return[r[0]*a+a,r[1]*s+s]}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ff={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}},Hf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._units="meters",r._scale=1,r._origin=$.vec3([0,0,0]),r.units=i.units,r.scale=i.scale,r.origin=i.origin,r}return P(n,[{key:"unitsInfo",get:function(){return Ff}},{key:"units",get:function(){return this._units},set:function(e){e||(e="meters"),Ff[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}},{key:"scale",get:function(){return this._scale},set:function(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}},{key:"origin",get:function(){return this._origin},set:function(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}},{key:"worldToRealPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec3(3);t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}},{key:"realToWorldPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec3(3);return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}]),n}(),Uf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._supported=Ir.SUPPORTED_EXTENSIONS.OES_standard_derivatives,r.enabled=i.enabled,r.kernelRadius=i.kernelRadius,r.intensity=i.intensity,r.bias=i.bias,r.scale=i.scale,r.minResolution=i.minResolution,r.numSamples=i.numSamples,r.blur=i.blur,r.blendCutoff=i.blendCutoff,r.blendFactor=i.blendFactor,r}return P(n,[{key:"supported",get:function(){return this._supported}},{key:"enabled",get:function(){return this._enabled},set:function(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}},{key:"possible",get:function(){if(!this._supported)return!1;if(!this._enabled)return!1;var e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}},{key:"active",get:function(){return this._active}},{key:"kernelRadius",get:function(){return this._kernelRadius},set:function(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}},{key:"intensity",get:function(){return this._intensity},set:function(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}},{key:"bias",get:function(){return this._bias},set:function(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}},{key:"minResolution",get:function(){return this._minResolution},set:function(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}},{key:"numSamples",get:function(){return this._numSamples},set:function(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}},{key:"blur",get:function(){return this._blur},set:function(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}},{key:"blendCutoff",get:function(){return this._blendCutoff},set:function(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}},{key:"blendFactor",get:function(){return this._blendFactor},set:function(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Gf={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}},kf=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),i.preset?(r.preset=i.preset,void 0!==i.pointSize&&(r.pointSize=i.pointSize),void 0!==i.roundPoints&&(r.roundPoints=i.roundPoints),void 0!==i.perspectivePoints&&(r.perspectivePoints=i.perspectivePoints),void 0!==i.minPerspectivePointSize&&(r.minPerspectivePointSize=i.minPerspectivePointSize),void 0!==i.maxPerspectivePointSize&&(r.maxPerspectivePointSize=i.minPerspectivePointSize)):(r._preset="default",r.pointSize=i.pointSize,r.roundPoints=i.roundPoints,r.perspectivePoints=i.perspectivePoints,r.minPerspectivePointSize=i.minPerspectivePointSize,r.maxPerspectivePointSize=i.maxPerspectivePointSize),r.filterIntensity=i.filterIntensity,r.minIntensity=i.minIntensity,r.maxIntensity=i.maxIntensity,r}return P(n,[{key:"type",get:function(){return"PointsMaterial"}},{key:"presets",get:function(){return Gf}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||2,this.glRedraw()}},{key:"roundPoints",get:function(){return this._state.roundPoints},set:function(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"perspectivePoints",get:function(){return this._state.perspectivePoints},set:function(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minPerspectivePointSize",get:function(){return this._state.minPerspectivePointSize},set:function(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}},{key:"maxPerspectivePointSize",get:function(){return this._state.maxPerspectivePointSize},set:function(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}},{key:"filterIntensity",get:function(){return this._state.filterIntensity},set:function(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minIntensity",get:function(){return this._state.minIntensity},set:function(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}},{key:"maxIntensity",get:function(){return this._state.maxIntensity},set:function(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Gf[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Gf).join(", "))}}},{key:"hash",get:function(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),jf={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}},Vf=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"LinesMaterial",lineWidth:null}),i.preset?(r.preset=i.preset,void 0!==i.lineWidth&&(r.lineWidth=i.lineWidth)):(r._preset="default",r.lineWidth=i.lineWidth),r}return P(n,[{key:"type",get:function(){return"LinesMaterial"}},{key:"presets",get:function(){return jf}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=jf[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(jf).join(", "))}}},{key:"hash",get:function(){return[""+this.lineWidth].join(";")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function Qf(e,t){for(var n,r,i={},a=0,s=t.length;a1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),r=t.call(this,null,i);var a=i.canvasElement||document.getElementById(i.canvasId);if(!(a instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";var s=!!i.transparent,o=!!i.alphaDepthMask;return r._aabbDirty=!0,r.viewer=e,r.occlusionTestCountdown=0,r.loading=0,r.startTime=(new Date).getTime(),r.models={},r.objects={},r._numObjects=0,r.visibleObjects={},r._numVisibleObjects=0,r.xrayedObjects={},r._numXRayedObjects=0,r.highlightedObjects={},r._numHighlightedObjects=0,r.selectedObjects={},r._numSelectedObjects=0,r.colorizedObjects={},r._numColorizedObjects=0,r.opacityObjects={},r._numOpacityObjects=0,r.offsetObjects={},r._numOffsetObjects=0,r._modelIds=null,r._objectIds=null,r._visibleObjectIds=null,r._xrayedObjectIds=null,r._highlightedObjectIds=null,r._selectedObjectIds=null,r._colorizedObjectIds=null,r._opacityObjectIds=null,r._offsetObjectIds=null,r._collidables={},r._compilables={},r._needRecompile=!1,r.types={},r.components={},r.sectionPlanes={},r.lights={},r.lightMaps={},r.reflectionMaps={},r.bitmaps={},r.lineSets={},r.realWorldOffset=i.realWorldOffset||new Float64Array([0,0,0]),r.canvas=new qc(g(r),{dontClear:!0,canvas:a,spinnerElementId:i.spinnerElementId,transparent:s,webgl2:!1!==i.webgl2,contextAttr:i.contextAttr||{},backgroundColor:i.backgroundColor,backgroundColorFromAmbientLight:i.backgroundColorFromAmbientLight,premultipliedAlpha:i.premultipliedAlpha}),r.canvas.on("boundary",(function(){r.glRedraw()})),r.canvas.on("webglContextFailed",(function(){alert("xeokit failed to find WebGL!")})),r._renderer=new df(g(r),{transparent:s,alphaDepthMask:o}),r._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;var e=null;this.getHash=function(){if(e)return e;var t=this.sectionPlanes;if(0===t.length)return this.hash=";";for(var n=[],r=0,i=t.length;r0&&t.push("/lm"),this.reflectionMaps.length>0&&t.push("/rm"),t.push(";"),n=t.join("")},this.addLight=function(e){this.lights.push(e),r=null,n=null},this.removeLight=function(e){for(var t=0,i=this.lights.length;t1&&void 0!==arguments[1])||arguments[1];e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}},{key:"_objectXRayedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}},{key:"_objectHighlightedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}},{key:"_objectSelectedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}},{key:"_objectColorizeUpdated",value:function(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}},{key:"_objectOpacityUpdated",value:function(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}},{key:"_objectOffsetUpdated",value:function(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}},{key:"_webglContextLost",value:function(){for(var e in this.canvas.spinner.processes++,this.components)if(this.components.hasOwnProperty(e)){var t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}},{key:"_webglContextRestored",value:function(){var e=this.canvas.gl;for(var t in this.components)if(this.components.hasOwnProperty(t)){var n=this.components[t];n._webglContextRestored&&n._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}},{key:"capabilities",get:function(){return this._renderer.capabilities}},{key:"entityOffsetsEnabled",get:function(){return this._entityOffsetsEnabled}},{key:"pickSurfacePrecisionEnabled",get:function(){return!1}},{key:"logarithmicDepthBufferEnabled",get:function(){return this._logarithmicDepthBufferEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled},set:function(e){this._pbrEnabled=!!e,this.glRedraw()}},{key:"dtxEnabled",get:function(){return this._dtxEnabled},set:function(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled},set:function(e){this._colorTextureEnabled=!!e,this.glRedraw()}},{key:"doOcclusionTest",value:function(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}},{key:"render",value:function(e){e&&de.runTasks();var t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;var n,r,i=this._passes,a=this._clearEachPass;for(n=0;na&&(a=e[3]),e[4]>s&&(s=e[4]),e[5]>o&&(o=e[5]),u=!0}u||(n=-100,r=-100,i=-100,a=100,s=100,o=100),this._aabb[0]=n,this._aabb[1]=r,this._aabb[2]=i,this._aabb[3]=a,this._aabb[4]=s,this._aabb[5]=o,this._aabbDirty=!1}return this._aabb}},{key:"_setAABBDirty",value:function(){this._aabbDirty=!0,this.fire("boundary")}},{key:"pick",value:function(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");var n=e.includeEntities||e.include;n&&(e.includeEntityIds=Qf(this,n));var r=e.excludeEntities||e.exclude;return r&&(e.excludeEntityIds=Qf(this,r)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}},{key:"snapPick",value:function(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge)}},{key:"clear",value:function(){var e;for(var t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}},{key:"clearLights",value:function(){for(var e=Object.keys(this.lights),t=0,n=e.length;ts&&(s=t[3]),t[4]>o&&(o=t[4]),t[5]>l&&(l=t[5]),n=!0}})),n){var u=$.AABB3();return u[0]=r,u[1]=i,u[2]=a,u[3]=s,u[4]=o,u[5]=l,u}return this.aabb}},{key:"setObjectsVisible",value:function(e,t){return this.withObjects(e,(function(e){var n=e.visible!==t;return e.visible=t,n}))}},{key:"setObjectsCollidable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.collidable!==t;return e.collidable=t,n}))}},{key:"setObjectsCulled",value:function(e,t){return this.withObjects(e,(function(e){var n=e.culled!==t;return e.culled=t,n}))}},{key:"setObjectsSelected",value:function(e,t){return this.withObjects(e,(function(e){var n=e.selected!==t;return e.selected=t,n}))}},{key:"setObjectsHighlighted",value:function(e,t){return this.withObjects(e,(function(e){var n=e.highlighted!==t;return e.highlighted=t,n}))}},{key:"setObjectsXRayed",value:function(e,t){return this.withObjects(e,(function(e){var n=e.xrayed!==t;return e.xrayed=t,n}))}},{key:"setObjectsEdges",value:function(e,t){return this.withObjects(e,(function(e){var n=e.edges!==t;return e.edges=t,n}))}},{key:"setObjectsColorized",value:function(e,t){return this.withObjects(e,(function(e){e.colorize=t}))}},{key:"setObjectsOpacity",value:function(e,t){return this.withObjects(e,(function(e){var n=e.opacity!==t;return e.opacity=t,n}))}},{key:"setObjectsPickable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.pickable!==t;return e.pickable=t,n}))}},{key:"setObjectsOffset",value:function(e,t){this.withObjects(e,(function(e){e.offset=t}))}},{key:"withObjects",value:function(e,t){se.isString(e)&&(e=[e]);for(var n=!1,r=0,i=e.length;r0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new fi(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}},{key:"disablePivotSphere",value:function(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}},{key:"startPivot",value:function(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;var e=this._scene.camera,t=$.lookAtMat4v(e.eye,e.look,e.worldUp);$.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var n=this.getPivotPos();this._cameraOffset[2]+=$.distVec3(e.eye,n),t=$.inverseMat4(t);var r=$.transformVec3(t,this._cameraOffset),i=$.vec3();if($.subVec3(e.eye,n,i),$.addVec3(i,r),e.zUp){var a=i[1];i[1]=i[2],i[2]=a}this._radius=$.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=$.normalizeVec3($.subVec3(e.look,e.eye,tp)),n=$.cross3Vec3(t,e.worldUp,np);return $.sqLenVec3(n)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,n=Math.abs($.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a),l=ip;t.project.unproject(e,o,ap,sp,l);var u=$.normalizeVec3($.subVec3(l,t.eye,tp)),c=$.addVec3(t.eye,$.mulVec3Scalar(u,n,np),rp);this.setPivotPos(c)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var n=this._scene.camera,r=-e,i=-t;1===n.worldUp[2]&&(r=-r),this._azimuth+=.01*-r,this._polar+=.01*i,this._polar=$.clamp(this._polar,.001,Math.PI-.001);var a=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===n.worldUp[2]){var s=a[1];a[1]=a[2],a[2]=s}var o=$.lenVec3($.subVec3(n.look,n.eye,$.vec3())),l=this.getPivotPos();$.addVec3(a,l);var u=$.lookAtMat4v(a,l,n.worldUp);u=$.inverseMat4(u);var c=$.transformVec3(u,this._cameraOffset);u[12]-=c[0],u[13]-=c[1],u[14]-=c[2];var f=[u[8],u[9],u[10]];n.eye=[u[12],u[13],u[14]],$.subVec3(n.eye,$.mulVec3Scalar(f,o),n.look),n.up=[u[4],u[5],u[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),lp=function(){function e(t,n){b(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=n,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=$.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._needFireEvents=!1}return P(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1,this._needFireEvents=!1;var e=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var t=this._scene.snapPick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});t&&t.snappedWorldPos?(this.snapPickResult=t,this.snappedOrPicked=!0,this._needFireEvents=!0):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var n=this.pickResult.canvasPos;if(n[0]===this.pickCursorPos[0]&&n[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents=e,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var r=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents=!0):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents=!0)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!0)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}},{key:"fireEvents",value:function(){if(this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,cursorPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new Zc;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.snappedWorldPos,e.cursorPos=this.pickCursorPos,e.canvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=!1}}},{key:"destroy",value:function(){}}]),e}(),up=$.vec2(),cp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o,l,u=n.pickController,c=0,f=0,p=0,A=0,d=!1,v=$.vec3(),h=!0,I=this._scene.canvas.canvas,y=[];function m(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];I.style.cursor="move",w(),e&&g()}function w(){c=i.pointerCanvasPos[0],f=i.pointerCanvasPos[1],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1]}function g(){u.pickCursorPos=i.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(d=!0,v.set(u.pickResult.worldPos)):d=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!1}}),I.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:y[t.input.KEY_SHIFT]||r.planView?(s=!0,m()):(s=!0,m(!1));break;case 2:o=!0,m();break;case 3:l=!0,r.panRightClick&&m()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(){if(r.active&&r.pointerEnabled&&(s||o||l)){var e=t.canvas.boundary,n=e[2],u=e[3],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1];if(y[t.input.KEY_SHIFT]||r.planView||!r.panRightClick&&o||r.panRightClick&&l){var h=p-c,I=A-f,m=t.camera;if("perspective"===m.projection){var w=Math.abs(d?$.lenVec3($.subVec3(v,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);a.panDeltaX+=1.5*h*w/u,a.panDeltaY+=1.5*I*w/u}else a.panDeltaX+=.5*m.ortho.scale*(h/u),a.panDeltaY+=.5*m.ortho.scale*(I/u)}else!s||o||l||r.planView||(r.firstPerson?(a.rotateDeltaY-=(p-c)/n*r.dragRotationRate/2,a.rotateDeltaX+=(A-f)/u*(r.dragRotationRate/4)):(a.rotateDeltaY-=(p-c)/n*(1.5*r.dragRotationRate),a.rotateDeltaX+=(A-f)/u*(1.5*r.dragRotationRate)));c=p,f=A}}),I.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&i.mouseover&&(h=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:s=!1,o=!1,l=!1}}),I.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var n=e.target,r=0,i=0,a=0,s=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,a+=n.scrollLeft,s+=n.scrollTop,n=n.offsetParent;t[0]=e.pageX+a-r,t[1]=e.pageY+s-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,up);var t=up[0],i=up[1];Math.abs(t-p)<3&&Math.abs(i-A)<3&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:up,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var T=1/60,E=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==E?t-E:0;E=t,n>.05&&(n=.05),n0?n.cameraFlight.flyTo(hp,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(hp),n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot())}}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),yp=function(){function e(t,n,r,i,a){var s=this;b(this,e),this._scene=t;var o=n.pickController,l=n.pivotController,u=n.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var c=!1,f=!1,p=this._scene.canvas.canvas,A=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e&&e.entity?e.entity.aabb:t.aabb;if(r){var a=t.camera;$.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})};p.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverOut"),l=u.hasSubs("hoverOff"),p=u.hasSubs("hoverSurface"),A=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=p,o.scheduleSnapOrPick=A,o.update(),o.pickResult){if(o.pickResult.entity){var d=o.pickResult.entity.id;s._lastPickedEntityId!==d&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=d)}u.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&u.fire("hoverSurface",o.pickResult,!0)}else void 0!==s._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),s._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)}}),p.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(c=!0),3===e.which&&(f=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===e.which))){var n=o.pickResult;n&&n.worldPos?(l.setPivotPos(n.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(i.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(c=!1),3===e.which&&(f=!1),l.getPivoting()&&l.endPivot()}),p.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var a=u.hasSubs("picked"),c=u.hasSubs("pickedNothing"),f=u.hasSubs("pickedSurface"),p=u.hasSubs("doublePicked"),d=u.hasSubs("doublePickedSurface"),v=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||p||d||v))return(a||c||f)&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=f,o.update(),o.pickResult?(u.fire("picked",o.pickResult,!0),o.pickedSurface&&u.fire("pickedSurface",o.pickResult,!0)):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(s._clicks=0);if(s._clicks++,1===s._clicks){o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo,o.schedulePickSurface=f,o.update();var h=o.pickResult,I=o.pickedSurface;s._timeout=setTimeout((function(){h?(u.fire("picked",h,!0),I&&(u.fire("pickedSurface",h,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(h.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),s._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==s._timeout&&(window.clearTimeout(s._timeout),s._timeout=null),o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo||p||d,o.schedulePickSurface=o.schedulePickEntity&&d,o.update(),o.pickResult){if(u.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&u.fire("doublePickedSurface",o.pickResult,!0),r.doublePickFlyTo&&(A(o.pickResult),!r.firstPerson&&r.followPointer)){var y=o.pickResult.entity.aabb,m=$.getAABB3Center(y);n.pivotController.setPivotPos(m),n.pivotController.startPivot()&&n.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),r.doublePickFlyTo&&(A(),!r.firstPerson&&r.followPointer)){var w=t.aabb,g=$.getAABB3Center(w);n.pivotController.setPivotPos(g),n.pivotController.startPivot()&&n.pivotController.showPivot()}s._clicks=0}}},!1)}return P(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),mp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.input,o=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=s.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=s.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover&&(o[e]=!0,e===s.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=s.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(o[e]=!1,e===s.KEY_SHIFT&&(l.style.cursor=null),n.pivotController.getPivoting()&&n.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var l=n.cameraControl,c=e.deltaTime/1e3;if(!r.planView){var f=l._isKeyDownForAction(l.ROTATE_Y_POS,o),p=l._isKeyDownForAction(l.ROTATE_Y_NEG,o),A=l._isKeyDownForAction(l.ROTATE_X_POS,o),d=l._isKeyDownForAction(l.ROTATE_X_NEG,o),v=c*r.keyboardRotationRate;(f||p||A||d)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),f?a.rotateDeltaY+=v:p&&(a.rotateDeltaY-=v),A?a.rotateDeltaX+=v:d&&(a.rotateDeltaX-=v),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!o[s.KEY_CTRL]&&!o[s.KEY_ALT]){var h=l._isKeyDownForAction(l.DOLLY_BACKWARDS,o),I=l._isKeyDownForAction(l.DOLLY_FORWARDS,o);if(h||I){var y=c*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),I?a.dollyDelta-=y:h&&(a.dollyDelta+=y),u&&(i.followPointerDirty=!0,u=!1)}}var m=l._isKeyDownForAction(l.PAN_FORWARDS,o),w=l._isKeyDownForAction(l.PAN_BACKWARDS,o),g=l._isKeyDownForAction(l.PAN_LEFT,o),T=l._isKeyDownForAction(l.PAN_RIGHT,o),E=l._isKeyDownForAction(l.PAN_UP,o),b=l._isKeyDownForAction(l.PAN_DOWN,o),D=(o[s.KEY_ALT]?.3:1)*c*r.keyboardPanRate;(m||w||g||T||E||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:E&&(a.panDeltaY+=-D),T?a.panDeltaX+=-D:g&&(a.panDeltaX+=D),w?a.panDeltaZ+=D:m&&(a.panDeltaZ+=-D))}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),wp=$.vec3(),gp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.camera,o=n.pickController,l=n.pivotController,u=n.panController,c=1,f=1,p=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(a.dollyDelta)<.001&&(a.dollyDelta=0),Math.abs(a.rotateDeltaX)<.001&&(a.rotateDeltaX=0),Math.abs(a.rotateDeltaY)<.001&&(a.rotateDeltaY=0),0===a.rotateDeltaX&&0===a.rotateDeltaY||(a.dollyDelta=0),r.followPointer&&--c<=0&&(c=1,0!==a.dollyDelta)){if(0===a.rotateDeltaY&&0===a.rotateDeltaX&&r.followPointer&&i.followPointerDirty&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.pickResult&&o.pickResult.worldPos?p=o.pickResult.worldPos:(f=1,p=null),i.followPointerDirty=!1),p){var n=Math.abs($.lenVec3($.subVec3(p,t.camera.eye,wp)));f=n/r.dollyProximityThreshold}fr.longTapRadius||Math.abs(I)>r.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),r.planView){var y=t.camera;if("perspective"===y.projection){var m=Math.abs(t.camera.eyeLookDist)*Math.tan(y.perspective.fov/2*Math.PI/180);a.panDeltaX+=h*m/l*r.touchPanRate,a.panDeltaY+=I*m/l*r.touchPanRate}else a.panDeltaX+=.5*y.ortho.scale*(h/l)*r.touchPanRate,a.panDeltaY+=.5*y.ortho.scale*(I/l)*r.touchPanRate}else a.rotateDeltaY-=h/o*(1*r.dragRotationRate),a.rotateDeltaX+=I/l*(1.5*r.dragRotationRate)}else if(2===d){var w=A[0],g=A[1];bp(w,u),bp(g,c);var T=$.geometricMeanVec2(p[0],p[1]),E=$.geometricMeanVec2(u,c),b=$.vec2();$.subVec2(T,E,b);var D=b[0],P=b[1],R=t.camera,C=$.distVec2([w.pageX,w.pageY],[g.pageX,g.pageY]),_=($.distVec2(p[0],p[1])-C)*r.touchDollyRate;if(a.dollyDelta=_,Math.abs(_)<1)if("perspective"===R.projection){var B=s.pickResult?s.pickResult.worldPos:t.center,O=Math.abs($.lenVec3($.subVec3(B,t.camera.eye,[])))*Math.tan(R.perspective.fov/2*Math.PI/180);a.panDeltaX-=D*O/l*r.touchPanRate,a.panDeltaY-=P*O/l*r.touchPanRate}else a.panDeltaX-=.5*R.ortho.scale*(D/l)*r.touchPanRate,a.panDeltaY-=.5*R.ortho.scale*(P/l)*r.touchPanRate;i.pointerCanvasPos=E}for(var S=0;S-1&&t-f<150&&(p>-1&&f-p<325?(Pp(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("doublePicked",o.pickResult),o.pickedSurface&&l.fire("doublePickedSurface",o.pickResult),r.doublePickFlyTo&&d(o.pickResult)):(l.fire("doublePickedNothing"),r.doublePickFlyTo&&d()),p=-1):$.distVec2(u[0],c)<4&&(Pp(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("picked",o.pickResult),o.pickedSurface&&l.fire("pickedSurface",o.pickResult)):l.fire("pickedNothing"),p=t),f=-1),u.length=n.length;for(var A=0,v=n.length;A1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).PAN_LEFT=0,r.PAN_RIGHT=1,r.PAN_UP=2,r.PAN_DOWN=3,r.PAN_FORWARDS=4,r.PAN_BACKWARDS=5,r.ROTATE_X_POS=6,r.ROTATE_X_NEG=7,r.ROTATE_Y_POS=8,r.ROTATE_Y_NEG=9,r.DOLLY_FORWARDS=10,r.DOLLY_BACKWARDS=11,r.AXIS_VIEW_RIGHT=12,r.AXIS_VIEW_BACK=13,r.AXIS_VIEW_LEFT=14,r.AXIS_VIEW_FRONT=15,r.AXIS_VIEW_TOP=16,r.AXIS_VIEW_BOTTOM=17,r._keyMap={},r.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},r._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},r._states={pointerCanvasPos:$.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:$.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var a=r.scene;return r._controllers={cameraControl:g(r),pickController:new lp(g(r),r._configs),pivotController:new op(a,r._configs),panController:new ep(a),cameraFlight:new rt(g(r),{duration:.5})},r._handlers=[new Tp(r.scene,r._controllers,r._configs,r._states,r._updates),new Dp(r.scene,r._controllers,r._configs,r._states,r._updates),new cp(r.scene,r._controllers,r._configs,r._states,r._updates),new Ip(r.scene,r._controllers,r._configs,r._states,r._updates),new yp(r.scene,r._controllers,r._configs,r._states,r._updates),new Rp(r.scene,r._controllers,r._configs,r._states,r._updates),new mp(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new gp(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=i.navMode,i.planView&&(r.planView=i.planView),r.constrainVertical=i.constrainVertical,i.keyboardLayout?r.keyboardLayout=i.keyboardLayout:r.keyMap=i.keyMap,r.doublePickFlyTo=i.doublePickFlyTo,r.panRightClick=i.panRightClick,r.active=i.active,r.followPointer=i.followPointer,r.rotationInertia=i.rotationInertia,r.keyboardPanRate=i.keyboardPanRate,r.touchPanRate=i.touchPanRate,r.keyboardRotationRate=i.keyboardRotationRate,r.dragRotationRate=i.dragRotationRate,r.touchDollyRate=i.touchDollyRate,r.dollyInertia=i.dollyInertia,r.dollyProximityThreshold=i.dollyProximityThreshold,r.dollyMinSpeed=i.dollyMinSpeed,r.panInertia=i.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=i.keyboardDollyRate,r.mouseWheelDollyRate=i.mouseWheelDollyRate,r}return P(n,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",se.isString(e)){var t=this.scene.input,n={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":n[this.PAN_LEFT]=[t.KEY_A],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_Z],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":n[this.PAN_LEFT]=[t.KEY_Q],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_W],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=n}else{var r=e;this._keyMap=r}}},{key:"_isKeyDownForAction",value:function(e,t){var n=this._keyMap[e];if(!n)return!1;t||(t=this.scene.input.keyDown);for(var r=0,i=n.length;r0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),v(T(n.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var n=this.metaScene;if(e.propertySets)for(var r=0,i=e.propertySets.length;r0?Lp(t):null,s=n&&n.length>0?Lp(n):null;return function e(t){if(t){var n=!0;(s&&s[t.type]||a&&!a[t.type])&&(n=!1),n&&r.push(t.id);var i=t.children;if(i)for(var o=0,l=i.length;o0){o=function(e){for(var t=[],n=0,r=e.length;nthis._frustumProps.CAM_FACTOR_1?(n|=l<0?64:128,n&=-17):n&=-33;var u=Qc($.dotVec3(s,this._frustumProps.up),o);Math.abs(u)>this._frustumProps.CAM_FACTOR_2?(n|=u<0?1024:2048,n&=-257):n&=-513}return 4&n&&8&n&&(n|=4096),64&n&&128&n&&(n|=8192),1024&n&&2048&n&&(n|=16384),e._check=n,n}}]),e}(),zc=function(){function e(t,n){b(this,e),this.sceneModel=n,this.entities=[],this.meshes=[],this.finalized=!1}return P(e,[{key:"addEntity",value:function(e){if(this.finalized)throw"Already finalized";this.entities.push(e)}},{key:"addMesh",value:function(e){if(this.finalized)throw"Already finalized";this.meshes.push(e)}},{key:"finalize",value:function(e){var t=this;if(this.finalized)throw"Already finalized";this.finalized=!0,this.VFCState=new Wc,this.VFCState.initializeVFCState(this.entities,this.meshes),this.VFCState.finalize(this.sceneModel,e),this._onSceneRendering=this.sceneModel.scene.on("rendering",(function(){return t.applyViewFrustumCulling.call(t)}))}},{key:"applyViewFrustumCulling",value:function(){this.finalized&&this.VFCState.applyViewFrustumCulling(this.sceneModel)}},{key:"destroy",value:function(){this.finalized&&this.sceneModel.off(this._onSceneRendering)}}]),e}(),Kc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._scene=e,r._vfcManagers={},r._vfcManagerList=[],r.enabled=i.enabled,r._init(),r}return P(n,[{key:"_init",value:function(){var e=this;this._scene.on("rendering",(function(){for(var t=0,n=e._vfcManagerList.length;t1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._canvas=i.canvas,r._element=null,r._isCustom=!1,i.elementId&&(r._element=document.getElementById(i.elementId),r._element?r._adjustPosition():r.error("Can't find given Spinner HTML element: '"+i.elementId+"' - will automatically create default element")),r._element||r._createDefaultSpinner(),r.processes=0,r}return P(n,[{key:"type",get:function(){return"Spinner"}},{key:"_createDefaultSpinner",value:function(){this._injectDefaultCSS();var e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}},{key:"_injectDefaultCSS",value:function(){var e="xeokit-spinner-css";if(!document.getElementById(e)){var t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}}},{key:"_adjustPosition",value:function(){if(!this._isCustom){var e=this._canvas,t=this._element,n=t.style;n.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",n.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}}},{key:"processes",get:function(){return this._processes},set:function(e){if(e=e||0,this._processes!==e&&!(e<0)){var t=this._processes;this._processes=e;var n=this._element;n&&(n.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}}},{key:"_destroy",value:function(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);var e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}]),n}(),Xc=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],qc=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._backgroundColor=$.vec3([i.backgroundColor?i.backgroundColor[0]:1,i.backgroundColor?i.backgroundColor[1]:1,i.backgroundColor?i.backgroundColor[2]:1]),r._backgroundColorFromAmbientLight=!!i.backgroundColorFromAmbientLight,r.canvas=i.canvas,r.gl=null,r.webgl2=!1,r.transparent=!!i.transparent,r.contextAttr=i.contextAttr||{},r.contextAttr.alpha=r.transparent,r.contextAttr.preserveDrawingBuffer=!!r.contextAttr.preserveDrawingBuffer,r.contextAttr.stencil=!1,r.contextAttr.premultipliedAlpha=!!r.contextAttr.premultipliedAlpha,r.contextAttr.antialias=!1!==r.contextAttr.antialias,r.resolutionScale=i.resolutionScale,r.canvas.width=Math.round(r.canvas.clientWidth*r._resolutionScale),r.canvas.height=Math.round(r.canvas.clientHeight*r._resolutionScale),r.boundary=[r.canvas.offsetLeft,r.canvas.offsetTop,r.canvas.clientWidth,r.canvas.clientHeight],r._initWebGL(i);var a=g(r);r.canvas.addEventListener("webglcontextlost",r._webglcontextlostListener=function(e){console.time("webglcontextrestored"),a.scene._webglContextLost(),a.fire("webglcontextlost"),e.preventDefault()},!1),r.canvas.addEventListener("webglcontextrestored",r._webglcontextrestoredListener=function(e){a._initWebGL(),a.gl&&(a.scene._webglContextRestored(a.gl),a.fire("webglcontextrestored",a.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);var s=!0,o=new ResizeObserver((function(e){var t,n=f(e);try{for(n.s();!(t=n.n()).done;){t.value.contentBoxSize&&(s=!0)}}catch(e){n.e(e)}finally{n.f()}}));return o.observe(r.canvas),r._tick=r.scene.on("tick",(function(){s&&(s=!1,a.canvas.width=Math.round(a.canvas.clientWidth*a._resolutionScale),a.canvas.height=Math.round(a.canvas.clientHeight*a._resolutionScale),a.boundary[0]=a.canvas.offsetLeft,a.boundary[1]=a.canvas.offsetTop,a.boundary[2]=a.canvas.clientWidth,a.boundary[3]=a.canvas.clientHeight,a.fire("boundary",a.boundary))})),r._spinner=new Yc(r.scene,{canvas:r.canvas,elementId:i.spinnerElementId}),r}return P(n,[{key:"type",get:function(){return"Canvas"}},{key:"backgroundColorFromAmbientLight",get:function(){return this._backgroundColorFromAmbientLight},set:function(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}},{key:"resolutionScale",get:function(){return this._resolutionScale},set:function(e){if((e=e||1)!==this._resolutionScale){this._resolutionScale=e;var t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}}},{key:"spinner",get:function(){return this._spinner}},{key:"_createCanvas",value:function(){var e="xeokit-canvas-"+$.createUUID(),t=document.getElementsByTagName("body")[0],n=document.createElement("div"),r=n.style;r.height="100%",r.width="100%",r.padding="0",r.margin="0",r.background="rgba(0,0,0,0);",r.float="left",r.left="0",r.top="0",r.position="absolute",r.opacity="1.0",r["z-index"]="-10000",n.innerHTML+='',t.appendChild(n),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,n=0;e;)t+=e.offsetLeft-e.scrollLeft,n+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:n}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e-t)o._setVisible(!1);else{var l=o.canvasPos,u=l[0],c=l[1];u+10<0||c+10<0||u-10>r||c-10>i?o._setVisible(!1):!o.entity||o.entity.visible?o.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=o,this.pixels[a++]=u,this.pixels[a++]=c):o._setVisible(!0):o._setVisible(!1)}}}},{key:"_updateActiveSectionPlanes",value:function(){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n0,n=[];return n.push("#version 300 es"),n.push("// OcclusionTester vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("vec4 worldPosition = vec4(position, 1.0); "),n.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&n.push(" vWorldPosition = worldPosition;"),n.push(" vec4 clipPos = projMatrix * viewPosition;"),n.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?n.push("vFragDepth = 1.0 + clipPos.w;"):n.push("clipPos.z += -0.001;"),n.push(" gl_Position = clipPos;"),n.push("}"),n}},{key:"_buildFragmentShaderSource",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// OcclusionTester fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;");for(var i=0;i 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),r.push("}"),r}},{key:"_buildProgram",value:function(){this._program&&this._program.destroy();var e=this._scene,t=e.canvas.gl,n=e._sectionPlanesState;if(this._program=new hr(t,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=n.sectionPlanes.length;i0)for(var p=r.sectionPlanes,A=0;A= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var r=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new lt(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),this._uvBuf=new lt(n,n.ARRAY_BUFFER,r,r.length,2,n.STATIC_DRAW),this._indicesBuf=new lt(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}}},{key:"destroy",value:function(){this._program&&(this._program.destroy(),this._program=null)}}]),e}(),sf=new Float32Array(pf(17,[0,1])),of=new Float32Array(pf(17,[1,0])),lf=new Float32Array(function(e,t){for(var n=[],r=0;r<=e;r++)n.push(ff(r,t));return n}(17,4)),uf=new Float32Array(2),cf=function(){function e(t){b(this,e),this._scene=t,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}return P(e,[{key:"init",value:function(){var e=this._scene.canvas.gl;if(this._program=new hr(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS ".concat(16,"\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var t=new Float32Array([1,1,0,1,0,0,1,0]),n=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),r=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new lt(e,e.ARRAY_BUFFER,n,n.length,3,e.STATIC_DRAW),this._uvBuf=new lt(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new lt(e,e.ELEMENT_ARRAY_BUFFER,r,r.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}},{key:"render",value:function(e,t,n){var r=this;if(!this._programError){this._getInverseProjectMat||(this._getInverseProjectMat=function(){var e=!0;r._scene.camera.on("projMatrix",(function(){e=!0}));var t=$.mat4();return function(){return e&&$.inverseMat4(s.camera.projMatrix,t),t}}());var i=this._scene.canvas.gl,a=this._program,s=this._scene,o=i.drawingBufferWidth,l=i.drawingBufferHeight,u=s.camera.project._state,c=u.near,f=u.far;i.viewport(0,0,o,l),i.clearColor(0,0,0,1),i.enable(i.DEPTH_TEST),i.disable(i.BLEND),i.frontFace(i.CCW),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),a.bind(),uf[0]=o,uf[1]=l,i.uniform2fv(this._uViewport,uf),i.uniform1f(this._uCameraNear,c),i.uniform1f(this._uCameraFar,f),i.uniform1f(this._uDepthCutoff,.01),0===n?i.uniform2fv(this._uSampleOffsets,of):i.uniform2fv(this._uSampleOffsets,sf),i.uniform1fv(this._uSampleWeights,lf);var p=e.getDepthTexture(),A=t.getTexture();a.bindTexture(this._uDepthTexture,p,0),a.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),i.drawElements(i.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}}},{key:"destroy",value:function(){this._program.destroy()}}]),e}();function ff(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function pf(e,t){for(var n=[],r=0;r<=e;r++)n.push(t[0]*r),n.push(t[1]*r);return n}var Af=function(){function e(t){b(this,e),this.scene=t,this._renderBuffersBasic={},this._renderBuffersScaled={}}return P(e,[{key:"getRenderBuffer",value:function(e,t){var n=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled,r=n[e];return r||(r=new Vi(this.scene.canvas.canvas,this.scene.canvas.gl,t),n[e]=r),r}},{key:"destroy",value:function(){for(var e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(var t in this._renderBuffersScaled)this._renderBuffersScaled[t].destroy()}}]),e}(),df=function(e,t){t=t||{};var n=new Jc(e),r=e.canvas.canvas,i=e.canvas.gl,a=!!t.transparent,s=t.alphaDepthMask,o=new G({}),l={},u={},c=!0,f=!0,p=!0,A=!0,d=!0,v=!0,h=!0,I=!0,y=new Af(e),m=!1,w=new af(e),g=new cf(e);function T(){c&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e],n=t.drawableMap,r=t.drawableListPreCull,i=0;for(var a in n)n.hasOwnProperty(a)&&(r[i++]=n[a]);r.length=i}}(),c=!1,f=!0),f&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),f=!1,p=!0),p&&function(){for(var e in l)if(l.hasOwnProperty(e)){for(var t=l[e],n=t.drawableListPreCull,r=t.drawableList,i=0,a=0,s=n.length;a0)for(n.withSAO=!0,O=0;O0)for(O=0;O0)for(O=0;O0)for(O=0;O0||Q>0||U>0||G>0){if(i.enable(i.CULL_FACE),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):(i.blendEquation(i.FUNC_ADD),i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,s||i.depthMask(!1),(U>0||G>0)&&i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),G>0)for(O=0;O0)for(O=0;O0)for(O=0;O0)for(O=0;O0||z>0){if(n.lastProgramId=null,e.highlightMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),z>0)for(O=0;O0)for(O=0;O0||Y>0||W>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),i.enable(i.CULL_FACE),Y>0)for(O=0;O0)for(O=0;O0||q>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),q>0)for(O=0;O0)for(O=0;O0||Z>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),i.enable(i.CULL_FACE),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),Z>0)for(O=0;O0)for(O=0;O1&&void 0!==arguments[1]?arguments[1]:s;d.reset(),T();var v=null,h=null;for(var I in d.pickSurface=p.pickSurface,p.canvasPos?(u[0]=p.canvasPos[0],u[1]=p.canvasPos[1],v=e.camera.viewMatrix,h=e.camera.projMatrix,d.canvasPos=p.canvasPos):(p.matrix?(v=p.matrix,h=e.camera.projMatrix):(c.set(p.origin||[0,0,0]),f.set(p.direction||[0,0,1]),A=$.addVec3(c,f,t),i[0]=Math.random(),i[1]=Math.random(),i[2]=Math.random(),$.normalizeVec3(i),$.cross3Vec3(f,i,a),v=$.lookAtMat4v(c,A,a,n),h=e.camera.projMatrix,d.origin=c,d.direction=f),u[0]=.5*r.clientWidth,u[1]=.5*r.clientHeight),l)if(l.hasOwnProperty(I))for(var m=l[I].drawableList,w=0,g=m.length;w1&&void 0!==arguments[1]?arguments[1]:30,a=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],s=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!a&&!s)return this.pick({canvasPos:t,pickSurface:!0});n.reset(),n.backfaces=!0,n.frontface=!0,n.pickZNear=e.camera.project.near,n.pickZFar=e.camera.project.far;var o=y.getRenderBuffer("uniquePickColors-aabs",{depthTexture:!0,size:[2*r+1,2*r+1]});n.snapVectorA=[_(t[0],i.drawingBufferWidth),B(t[1],i.drawingBufferHeight)],n.snapInvVectorAB=[i.drawingBufferWidth/(2*r),i.drawingBufferHeight/(2*r)],o.bind(i.RGBA32I),i.viewport(0,0,o.size[0],o.size[1]),i.enable(i.DEPTH_TEST),i.frontFace(i.CCW),i.disable(i.CULL_FACE),i.depthMask(!0),i.disable(i.BLEND),i.depthFunc(i.LESS),i.clear(i.DEPTH_BUFFER_BIT),i.clearBufferiv(i.COLOR,0,new Int32Array([0,0,0,0]));var u=e.camera.viewMatrix,c=e.camera.projMatrix;for(var f in l)if(l.hasOwnProperty(f))for(var p=l[f].drawableList,A=0,d=p.length;A0){var L=Math.floor(N/4),x=o.size[0],M=L%x-Math.floor(x/2),F=Math.floor(L/x)-Math.floor(x/2),H=Math.sqrt(Math.pow(M,2)+Math.pow(F,2));S.push({x:M,y:F,dist:H,isVertex:a&&s?m[N+3]>I.length/2:a,result:[m[N+0],m[N+1],m[N+2],m[N+3]]})}var U=null,G=null;if(S.length>0){S.sort((function(e,t){return e.isVertex!==t.isVertex?e.isVertex?-1:1:e.dist-t.dist})),G=S[0].isVertex?"vertex":"edge";var k=I[(S=S[0].result)[3]],j=k.origin,V=k.coordinateScale;U=[S[0]*V[0]+j[0],S[1]*V[1]+j[1],S[2]*V[2]+j[2]]}if(null===w&&null==U)return null;var Q=null;return null!==U&&(Q=e.camera.projectWorldPos(U)),{snapType:G,snappedToVertex:"vertex"===G,snappedToEdge:"edge"===G,worldPos:w,snappedWorldPos:U,snappedCanvasPos:Q}},this.addMarker=function(t){this._occlusionTester=this._occlusionTester||new nf(e,y),this._occlusionTester.addMarker(t),e.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){for(var e in T(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,i.viewport(0,0,i.drawingBufferWidth,i.drawingBufferHeight),i.clearColor(0,0,0,0),i.enable(i.DEPTH_TEST),i.disable(i.CULL_FACE),i.disable(i.BLEND),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),l)if(l.hasOwnProperty(e))for(var t=l[e].drawableList,r=0,a=t.length;r0&&void 0!==arguments[0]?arguments[0]:{},t=y.getRenderBuffer("snapshot");e.width&&e.height&&t.setSize([e.width,e.height]),t.bind(),t.clear(),m=!0},this.renderSnapshot=function(){m&&(y.getRenderBuffer("snapshot").clear(),this.render({force:!0,opaqueOnly:!1}),p=!0)},this.readSnapshot=function(e){return y.getRenderBuffer("snapshot").readImage(e)},this.readSnapshotAsCanvas=function(){return y.getRenderBuffer("snapshot").readImageAsCanvas()},this.endSnapshot=function(){m&&(y.getRenderBuffer("snapshot").unbind(),m=!1)},this.destroy=function(){l={},u={},y.destroy(),w.destroy(),g.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}},vf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).KEY_BACKSPACE=8,r.KEY_TAB=9,r.KEY_ENTER=13,r.KEY_SHIFT=16,r.KEY_CTRL=17,r.KEY_ALT=18,r.KEY_PAUSE_BREAK=19,r.KEY_CAPS_LOCK=20,r.KEY_ESCAPE=27,r.KEY_PAGE_UP=33,r.KEY_PAGE_DOWN=34,r.KEY_END=35,r.KEY_HOME=36,r.KEY_LEFT_ARROW=37,r.KEY_UP_ARROW=38,r.KEY_RIGHT_ARROW=39,r.KEY_DOWN_ARROW=40,r.KEY_INSERT=45,r.KEY_DELETE=46,r.KEY_NUM_0=48,r.KEY_NUM_1=49,r.KEY_NUM_2=50,r.KEY_NUM_3=51,r.KEY_NUM_4=52,r.KEY_NUM_5=53,r.KEY_NUM_6=54,r.KEY_NUM_7=55,r.KEY_NUM_8=56,r.KEY_NUM_9=57,r.KEY_A=65,r.KEY_B=66,r.KEY_C=67,r.KEY_D=68,r.KEY_E=69,r.KEY_F=70,r.KEY_G=71,r.KEY_H=72,r.KEY_I=73,r.KEY_J=74,r.KEY_K=75,r.KEY_L=76,r.KEY_M=77,r.KEY_N=78,r.KEY_O=79,r.KEY_P=80,r.KEY_Q=81,r.KEY_R=82,r.KEY_S=83,r.KEY_T=84,r.KEY_U=85,r.KEY_V=86,r.KEY_W=87,r.KEY_X=88,r.KEY_Y=89,r.KEY_Z=90,r.KEY_LEFT_WINDOW=91,r.KEY_RIGHT_WINDOW=92,r.KEY_SELECT_KEY=93,r.KEY_NUMPAD_0=96,r.KEY_NUMPAD_1=97,r.KEY_NUMPAD_2=98,r.KEY_NUMPAD_3=99,r.KEY_NUMPAD_4=100,r.KEY_NUMPAD_5=101,r.KEY_NUMPAD_6=102,r.KEY_NUMPAD_7=103,r.KEY_NUMPAD_8=104,r.KEY_NUMPAD_9=105,r.KEY_MULTIPLY=106,r.KEY_ADD=107,r.KEY_SUBTRACT=109,r.KEY_DECIMAL_POINT=110,r.KEY_DIVIDE=111,r.KEY_F1=112,r.KEY_F2=113,r.KEY_F3=114,r.KEY_F4=115,r.KEY_F5=116,r.KEY_F6=117,r.KEY_F7=118,r.KEY_F8=119,r.KEY_F9=120,r.KEY_F10=121,r.KEY_F11=122,r.KEY_F12=123,r.KEY_NUM_LOCK=144,r.KEY_SCROLL_LOCK=145,r.KEY_SEMI_COLON=186,r.KEY_EQUAL_SIGN=187,r.KEY_COMMA=188,r.KEY_DASH=189,r.KEY_PERIOD=190,r.KEY_FORWARD_SLASH=191,r.KEY_GRAVE_ACCENT=192,r.KEY_OPEN_BRACKET=219,r.KEY_BACK_SLASH=220,r.KEY_CLOSE_BRACKET=221,r.KEY_SINGLE_QUOTE=222,r.KEY_SPACE=32,r.element=i.element,r.altDown=!1,r.ctrlDown=!1,r.mouseDownLeft=!1,r.mouseDownMiddle=!1,r.mouseDownRight=!1,r.keyDown=[],r.enabled=!0,r.keyboardEnabled=!0,r.mouseover=!1,r.mouseCanvasPos=$.vec2(),r._keyboardEventsElement=i.keyboardEventsElement||document,r._bindEvents(),r}return P(n,[{key:"_bindEvents",value:function(){var e=this;if(!this._eventsBound){this._keyboardEventsElement.addEventListener("keydown",this._keyDownListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!0:t.keyCode===e.KEY_ALT?e.altDown=!0:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!0),e.keyDown[t.keyCode]=!0,e.fire("keydown",t.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!1:t.keyCode===e.KEY_ALT?e.altDown=!1:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!1),e.keyDown[t.keyCode]=!1,e.fire("keyup",t.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=function(t){e.enabled&&(e.mouseover=!0,e._getMouseCanvasPos(t),e.fire("mouseenter",e.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=function(t){e.enabled&&(e.mouseover=!1,e._getMouseCanvasPos(t),e.fire("mouseleave",e.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!0;break;case 2:e.mouseDownMiddle=!0;break;case 3:e.mouseDownRight=!0}e._getMouseCanvasPos(t),e.element.focus(),e.fire("mousedown",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!1;break;case 2:e.mouseDownMiddle=!1;break;case 3:e.mouseDownRight=!1}e.fire("mouseup",e.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("click",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("dblclick",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=function(t){e.enabled&&(e._getMouseCanvasPos(t),e.fire("mousemove",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=function(t,n){if(e.enabled){var r=Math.max(-1,Math.min(1,40*-t.deltaY));e.fire("mousewheel",r,!0)}},{passive:!0});var t,n;this.on("mousedown",(function(e){t=e[0],n=e[1]})),this.on("mouseup",(function(r){t>=r[0]-2&&t<=r[0]+2&&n>=r[1]-2&&n<=r[1]+2&&e.fire("mouseclicked",r,!0)})),this._eventsBound=!0}}},{key:"_unbindEvents",value:function(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}},{key:"_getMouseCanvasPos",value:function(e){if(e){for(var t=e.target,n=0,r=0;t.offsetParent;)n+=t.offsetLeft,r+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-n,this.mouseCanvasPos[1]=e.pageY-r}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}},{key:"setEnabled",value:function(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}},{key:"getEnabled",value:function(){return this.enabled}},{key:"setKeyboardEnabled",value:function(e){this.keyboardEnabled=e}},{key:"getKeyboardEnabled",value:function(){return this.keyboardEnabled}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._unbindEvents()}}]),n}(),hf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({boundary:[0,0,100,100]}),r.boundary=i.boundary,r.autoBoundary=i.autoBoundary,r}return P(n,[{key:"type",get:function(){return"Viewport"}},{key:"boundary",get:function(){return this._state.boundary},set:function(e){if(!this._autoBoundary){if(!e){var t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}},{key:"autoBoundary",get:function(){return this._autoBoundary},set:function(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){var t=e[2],n=e[3];this._state.boundary=[0,0,t,n],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),If=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new ot({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:2e3}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r._fov=60,r._canvasResized=r.scene.canvas.on("boundary",r._needUpdate,g(r)),r.fov=i.fov,r.fovAxis=i.fovAxis,r.near=i.near,r.far=i.far,r}return P(n,[{key:"type",get:function(){return"Perspective"}},{key:"_update",value:function(){var e=this.scene.canvas.boundary,t=e[2]/e[3],n=this._fovAxis,r=this._fov;("x"===n||"min"===n&&t<1||"max"===n&&t>1)&&(r/=t),r=Math.min(r,120),$.perspectiveMat4(r*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}},{key:"fov",get:function(){return this._fov},set:function(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}},{key:"fovAxis",get:function(){return this._fovAxis},set:function(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,$.mulMat4v4(this.inverseMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}]),n}(),yf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new ot({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:2e3}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.scale=i.scale,r.near=i.near,r.far=i.far,r._onCanvasBoundary=r.scene.canvas.on("boundary",r._needUpdate,g(r)),r}return P(n,[{key:"type",get:function(){return"Ortho"}},{key:"_update",value:function(){var e,t,n,r,i=this.scene,a=.5*this._scale,s=i.canvas.boundary,o=s[2],l=s[3],u=o/l;o>l?(e=-a,t=a,n=a/u,r=-a/u):(e=-a*u,t=a*u,n=a,r=-a),$.orthoMat4c(e,t,r,n,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,$.mulMat4v4(this.inverseMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}]),n}(),mf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new ot({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4(),near:.1,far:1e4}),r._left=-1,r._right=1,r._bottom=-1,r._top=1,r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.left=i.left,r.right=i.right,r.bottom=i.bottom,r.top=i.top,r.near=i.near,r.far=i.far,r}return P(n,[{key:"type",get:function(){return"Frustum"}},{key:"_update",value:function(){$.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"left",get:function(){return this._left},set:function(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}},{key:"right",get:function(){return this._right},set:function(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}},{key:"top",get:function(){return this._top},set:function(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}},{key:"bottom",get:function(){return this._bottom},set:function(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}},{key:"near",get:function(){return this._state.near},set:function(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}},{key:"far",get:function(){return this._state.far},set:function(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,$.mulMat4v4(this.inverseMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),wf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new ot({matrix:$.mat4(),inverseMatrix:$.mat4(),transposedMatrix:$.mat4()}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!1,r.matrix=i.matrix,r}return P(n,[{key:"type",get:function(){return"CustomProjection"}},{key:"matrix",get:function(){return this._state.matrix},set:function(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&($.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&($.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,$.mulMat4v4(this.inverseMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,$.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),gf=$.vec3(),Tf=$.vec3(),Ef=$.vec3(),bf=$.vec3(),Df=$.vec3(),Pf=$.vec3(),Rf=$.vec4(),Cf=$.vec4(),_f=$.vec4(),Bf=$.mat4(),Of=$.mat4(),Sf=$.vec3(),Nf=$.vec3(),Lf=$.vec3(),xf=$.vec3(),Mf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({deviceMatrix:$.mat4(),hasDeviceMatrix:!1,matrix:$.mat4(),normalMatrix:$.mat4(),inverseMatrix:$.mat4()}),r._perspective=new If(g(r)),r._ortho=new yf(g(r)),r._frustum=new mf(g(r)),r._customProjection=new wf(g(r)),r._project=r._perspective,r._eye=$.vec3([0,0,10]),r._look=$.vec3([0,0,0]),r._up=$.vec3([0,1,0]),r._worldUp=$.vec3([0,1,0]),r._worldRight=$.vec3([1,0,0]),r._worldForward=$.vec3([0,0,-1]),r.deviceMatrix=i.deviceMatrix,r.eye=i.eye,r.look=i.look,r.up=i.up,r.worldAxis=i.worldAxis,r.gimbalLock=i.gimbalLock,r.constrainPitch=i.constrainPitch,r.projection=i.projection,r._perspective.on("matrix",(function(){"perspective"===r._projectionType&&r.fire("projMatrix",r._perspective.matrix)})),r._ortho.on("matrix",(function(){"ortho"===r._projectionType&&r.fire("projMatrix",r._ortho.matrix)})),r._frustum.on("matrix",(function(){"frustum"===r._projectionType&&r.fire("projMatrix",r._frustum.matrix)})),r._customProjection.on("matrix",(function(){"customProjection"===r._projectionType&&r.fire("projMatrix",r._customProjection.matrix)})),r}return P(n,[{key:"type",get:function(){return"Camera"}},{key:"_update",value:function(){var e,t=this._state;"ortho"===this.projection?($.subVec3(this._eye,this._look,Sf),$.normalizeVec3(Sf,Nf),$.mulVec3Scalar(Nf,1e3,Lf),$.addVec3(this._look,Lf,xf),e=xf):e=this._eye,t.hasDeviceMatrix?($.lookAtMat4v(e,this._look,this._up,Of),$.mulMat4(t.deviceMatrix,Of,t.matrix)):$.lookAtMat4v(e,this._look,this._up,t.matrix),$.inverseMat4(this._state.matrix,this._state.inverseMatrix),$.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}},{key:"orbitYaw",value:function(e){var t=$.subVec3(this._eye,this._look,gf);$.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Bf),t=$.transformPoint3(Bf,t,Tf),this.eye=$.addVec3(this._look,t,Ef),this.up=$.transformPoint3(Bf,this._up,bf)}},{key:"orbitPitch",value:function(e){if(!(this._constrainPitch&&(e=$.dotVec3(this._up,this._worldUp)/$.DEGTORAD)<1)){var t=$.subVec3(this._eye,this._look,gf),n=$.cross3Vec3($.normalizeVec3(t,Tf),$.normalizeVec3(this._up,Ef));$.rotationMat4v(.0174532925*e,n,Bf),t=$.transformPoint3(Bf,t,bf),this.up=$.transformPoint3(Bf,this._up,Df),this.eye=$.addVec3(t,this._look,Pf)}}},{key:"yaw",value:function(e){var t=$.subVec3(this._look,this._eye,gf);$.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Bf),t=$.transformPoint3(Bf,t,Tf),this.look=$.addVec3(t,this._eye,Ef),this._gimbalLock&&(this.up=$.transformPoint3(Bf,this._up,bf))}},{key:"pitch",value:function(e){if(!(this._constrainPitch&&(e=$.dotVec3(this._up,this._worldUp)/$.DEGTORAD)<1)){var t=$.subVec3(this._look,this._eye,gf),n=$.cross3Vec3($.normalizeVec3(t,Tf),$.normalizeVec3(this._up,Ef));$.rotationMat4v(.0174532925*e,n,Bf),this.up=$.transformPoint3(Bf,this._up,Pf),t=$.transformPoint3(Bf,t,bf),this.look=$.addVec3(t,this._eye,Df)}}},{key:"pan",value:function(e){var t,n=$.subVec3(this._eye,this._look,gf),r=[0,0,0];if(0!==e[0]){var i=$.cross3Vec3($.normalizeVec3(n,[]),$.normalizeVec3(this._up,Tf));t=$.mulVec3Scalar(i,e[0]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]}0!==e[1]&&(t=$.mulVec3Scalar($.normalizeVec3(this._up,Ef),e[1]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),0!==e[2]&&(t=$.mulVec3Scalar($.normalizeVec3(n,bf),e[2]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),this.eye=$.addVec3(this._eye,r,Df),this.look=$.addVec3(this._look,r,Pf)}},{key:"zoom",value:function(e){var t=$.subVec3(this._eye,this._look,gf),n=Math.abs($.lenVec3(t,Tf)),r=Math.abs(n+e);if(!(r<.5)){var i=$.normalizeVec3(t,Ef);this.eye=$.addVec3(this._look,$.mulVec3Scalar(i,r),bf)}}},{key:"eye",get:function(){return this._eye},set:function(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}},{key:"look",get:function(){return this._look},set:function(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}},{key:"up",get:function(){return this._up},set:function(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}},{key:"deviceMatrix",get:function(){return this._state.deviceMatrix},set:function(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}},{key:"worldAxis",get:function(){return this._worldAxis},set:function(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=$.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}},{key:"worldUp",get:function(){return this._worldUp}},{key:"xUp",get:function(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}},{key:"yUp",get:function(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}},{key:"zUp",get:function(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}},{key:"worldRight",get:function(){return this._worldRight}},{key:"worldForward",get:function(){return this._worldForward}},{key:"gimbalLock",get:function(){return this._gimbalLock},set:function(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}},{key:"constrainPitch",set:function(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}},{key:"eyeLookDist",get:function(){return $.lenVec3($.subVec3(this._look,this._eye,gf))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"viewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"normalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"viewNormalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"inverseViewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}},{key:"projMatrix",get:function(){return this[this.projection].matrix}},{key:"perspective",get:function(){return this._perspective}},{key:"ortho",get:function(){return this._ortho}},{key:"frustum",get:function(){return this._frustum}},{key:"customProjection",get:function(){return this._customProjection}},{key:"projection",get:function(){return this._projectionType},set:function(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}},{key:"project",get:function(){return this._project}},{key:"projectWorldPos",value:function(e){var t=Rf,n=Cf,r=_f;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,$.mulMat4v4(this.viewMatrix,t,n),$.mulMat4v4(this.projMatrix,n,r),$.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1;var i=this.scene.canvas.canvas,a=i.offsetWidth/2,s=i.offsetHeight/2;return[r[0]*a+a,r[1]*s+s]}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ff={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}},Hf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._units="meters",r._scale=1,r._origin=$.vec3([0,0,0]),r.units=i.units,r.scale=i.scale,r.origin=i.origin,r}return P(n,[{key:"unitsInfo",get:function(){return Ff}},{key:"units",get:function(){return this._units},set:function(e){e||(e="meters"),Ff[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}},{key:"scale",get:function(){return this._scale},set:function(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}},{key:"origin",get:function(){return this._origin},set:function(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}},{key:"worldToRealPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec3(3);t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}},{key:"realToWorldPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.vec3(3);return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}]),n}(),Uf=function(e){I(n,he);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._supported=Ir.SUPPORTED_EXTENSIONS.OES_standard_derivatives,r.enabled=i.enabled,r.kernelRadius=i.kernelRadius,r.intensity=i.intensity,r.bias=i.bias,r.scale=i.scale,r.minResolution=i.minResolution,r.numSamples=i.numSamples,r.blur=i.blur,r.blendCutoff=i.blendCutoff,r.blendFactor=i.blendFactor,r}return P(n,[{key:"supported",get:function(){return this._supported}},{key:"enabled",get:function(){return this._enabled},set:function(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}},{key:"possible",get:function(){if(!this._supported)return!1;if(!this._enabled)return!1;var e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}},{key:"active",get:function(){return this._active}},{key:"kernelRadius",get:function(){return this._kernelRadius},set:function(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}},{key:"intensity",get:function(){return this._intensity},set:function(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}},{key:"bias",get:function(){return this._bias},set:function(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}},{key:"minResolution",get:function(){return this._minResolution},set:function(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}},{key:"numSamples",get:function(){return this._numSamples},set:function(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}},{key:"blur",get:function(){return this._blur},set:function(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}},{key:"blendCutoff",get:function(){return this._blendCutoff},set:function(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}},{key:"blendFactor",get:function(){return this._blendFactor},set:function(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Gf={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}},kf=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),i.preset?(r.preset=i.preset,void 0!==i.pointSize&&(r.pointSize=i.pointSize),void 0!==i.roundPoints&&(r.roundPoints=i.roundPoints),void 0!==i.perspectivePoints&&(r.perspectivePoints=i.perspectivePoints),void 0!==i.minPerspectivePointSize&&(r.minPerspectivePointSize=i.minPerspectivePointSize),void 0!==i.maxPerspectivePointSize&&(r.maxPerspectivePointSize=i.minPerspectivePointSize)):(r._preset="default",r.pointSize=i.pointSize,r.roundPoints=i.roundPoints,r.perspectivePoints=i.perspectivePoints,r.minPerspectivePointSize=i.minPerspectivePointSize,r.maxPerspectivePointSize=i.maxPerspectivePointSize),r.filterIntensity=i.filterIntensity,r.minIntensity=i.minIntensity,r.maxIntensity=i.maxIntensity,r}return P(n,[{key:"type",get:function(){return"PointsMaterial"}},{key:"presets",get:function(){return Gf}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||2,this.glRedraw()}},{key:"roundPoints",get:function(){return this._state.roundPoints},set:function(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"perspectivePoints",get:function(){return this._state.perspectivePoints},set:function(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minPerspectivePointSize",get:function(){return this._state.minPerspectivePointSize},set:function(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}},{key:"maxPerspectivePointSize",get:function(){return this._state.maxPerspectivePointSize},set:function(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}},{key:"filterIntensity",get:function(){return this._state.filterIntensity},set:function(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minIntensity",get:function(){return this._state.minIntensity},set:function(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}},{key:"maxIntensity",get:function(){return this._state.maxIntensity},set:function(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Gf[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Gf).join(", "))}}},{key:"hash",get:function(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),jf={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}},Vf=function(e){I(n,li);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new ot({type:"LinesMaterial",lineWidth:null}),i.preset?(r.preset=i.preset,void 0!==i.lineWidth&&(r.lineWidth=i.lineWidth)):(r._preset="default",r.lineWidth=i.lineWidth),r}return P(n,[{key:"type",get:function(){return"LinesMaterial"}},{key:"presets",get:function(){return jf}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=jf[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(jf).join(", "))}}},{key:"hash",get:function(){return[""+this.lineWidth].join(";")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function Qf(e,t){for(var n,r,i={},a=0,s=t.length;a1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),r=t.call(this,null,i);var a=i.canvasElement||document.getElementById(i.canvasId);if(!(a instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";var s=!!i.transparent,o=!!i.alphaDepthMask;return r._aabbDirty=!0,r.viewer=e,r.occlusionTestCountdown=0,r.loading=0,r.startTime=(new Date).getTime(),r.models={},r.objects={},r._numObjects=0,r.visibleObjects={},r._numVisibleObjects=0,r.xrayedObjects={},r._numXRayedObjects=0,r.highlightedObjects={},r._numHighlightedObjects=0,r.selectedObjects={},r._numSelectedObjects=0,r.colorizedObjects={},r._numColorizedObjects=0,r.opacityObjects={},r._numOpacityObjects=0,r.offsetObjects={},r._numOffsetObjects=0,r._modelIds=null,r._objectIds=null,r._visibleObjectIds=null,r._xrayedObjectIds=null,r._highlightedObjectIds=null,r._selectedObjectIds=null,r._colorizedObjectIds=null,r._opacityObjectIds=null,r._offsetObjectIds=null,r._collidables={},r._compilables={},r._needRecompile=!1,r.types={},r.components={},r.sectionPlanes={},r.lights={},r.lightMaps={},r.reflectionMaps={},r.bitmaps={},r.lineSets={},r.realWorldOffset=i.realWorldOffset||new Float64Array([0,0,0]),r.canvas=new qc(g(r),{dontClear:!0,canvas:a,spinnerElementId:i.spinnerElementId,transparent:s,webgl2:!1!==i.webgl2,contextAttr:i.contextAttr||{},backgroundColor:i.backgroundColor,backgroundColorFromAmbientLight:i.backgroundColorFromAmbientLight,premultipliedAlpha:i.premultipliedAlpha}),r.canvas.on("boundary",(function(){r.glRedraw()})),r.canvas.on("webglContextFailed",(function(){alert("xeokit failed to find WebGL!")})),r._renderer=new df(g(r),{transparent:s,alphaDepthMask:o}),r._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1;var e=null;this.getHash=function(){if(e)return e;var t=this.sectionPlanes;if(0===t.length)return this.hash=";";for(var n=[],r=0,i=t.length;r0&&t.push("/lm"),this.reflectionMaps.length>0&&t.push("/rm"),t.push(";"),n=t.join("")},this.addLight=function(e){this.lights.push(e),r=null,n=null},this.removeLight=function(e){for(var t=0,i=this.lights.length;t1&&void 0!==arguments[1])||arguments[1];e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}},{key:"_objectXRayedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}},{key:"_objectHighlightedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null,t&&this.fire("objectHighlighted",e,!0)}},{key:"_objectSelectedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}},{key:"_objectColorizeUpdated",value:function(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}},{key:"_objectOpacityUpdated",value:function(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}},{key:"_objectOffsetUpdated",value:function(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}},{key:"_webglContextLost",value:function(){for(var e in this.canvas.spinner.processes++,this.components)if(this.components.hasOwnProperty(e)){var t=this.components[e];t._webglContextLost&&t._webglContextLost()}this._renderer.webglContextLost()}},{key:"_webglContextRestored",value:function(){var e=this.canvas.gl;for(var t in this.components)if(this.components.hasOwnProperty(t)){var n=this.components[t];n._webglContextRestored&&n._webglContextRestored(e)}this._renderer.webglContextRestored(e),this.canvas.spinner.processes--}},{key:"capabilities",get:function(){return this._renderer.capabilities}},{key:"entityOffsetsEnabled",get:function(){return this._entityOffsetsEnabled}},{key:"pickSurfacePrecisionEnabled",get:function(){return!1}},{key:"logarithmicDepthBufferEnabled",get:function(){return this._logarithmicDepthBufferEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled},set:function(e){this._pbrEnabled=!!e,this.glRedraw()}},{key:"dtxEnabled",get:function(){return this._dtxEnabled},set:function(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled},set:function(e){this._colorTextureEnabled=!!e,this.glRedraw()}},{key:"doOcclusionTest",value:function(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}},{key:"render",value:function(e){e&&de.runTasks();var t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;var n,r,i=this._passes,a=this._clearEachPass;for(n=0;na&&(a=e[3]),e[4]>s&&(s=e[4]),e[5]>o&&(o=e[5]),u=!0}u||(n=-100,r=-100,i=-100,a=100,s=100,o=100),this._aabb[0]=n,this._aabb[1]=r,this._aabb[2]=i,this._aabb[3]=a,this._aabb[4]=s,this._aabb[5]=o,this._aabbDirty=!1}return this._aabb}},{key:"_setAABBDirty",value:function(){this._aabbDirty=!0,this.fire("boundary")}},{key:"pick",value:function(e,t){if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");var n=e.includeEntities||e.include;n&&(e.includeEntityIds=Qf(this,n));var r=e.excludeEntities||e.exclude;return r&&(e.excludeEntityIds=Qf(this,r)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=this._renderer.pick(e,t))?(t.entity&&t.entity.fire&&t.entity.fire("picked",t),t):void 0}},{key:"snapPick",value:function(e){return this._renderer.snapPick(e.canvasPos,e.snapRadius||30,e.snapToVertex,e.snapToEdge)}},{key:"clear",value:function(){var e;for(var t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}},{key:"clearLights",value:function(){for(var e=Object.keys(this.lights),t=0,n=e.length;ts&&(s=t[3]),t[4]>o&&(o=t[4]),t[5]>l&&(l=t[5]),n=!0}})),n){var u=$.AABB3();return u[0]=r,u[1]=i,u[2]=a,u[3]=s,u[4]=o,u[5]=l,u}return this.aabb}},{key:"setObjectsVisible",value:function(e,t){return this.withObjects(e,(function(e){var n=e.visible!==t;return e.visible=t,n}))}},{key:"setObjectsCollidable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.collidable!==t;return e.collidable=t,n}))}},{key:"setObjectsCulled",value:function(e,t){return this.withObjects(e,(function(e){var n=e.culled!==t;return e.culled=t,n}))}},{key:"setObjectsSelected",value:function(e,t){return this.withObjects(e,(function(e){var n=e.selected!==t;return e.selected=t,n}))}},{key:"setObjectsHighlighted",value:function(e,t){return this.withObjects(e,(function(e){var n=e.highlighted!==t;return e.highlighted=t,n}))}},{key:"setObjectsXRayed",value:function(e,t){return this.withObjects(e,(function(e){var n=e.xrayed!==t;return e.xrayed=t,n}))}},{key:"setObjectsEdges",value:function(e,t){return this.withObjects(e,(function(e){var n=e.edges!==t;return e.edges=t,n}))}},{key:"setObjectsColorized",value:function(e,t){return this.withObjects(e,(function(e){e.colorize=t}))}},{key:"setObjectsOpacity",value:function(e,t){return this.withObjects(e,(function(e){var n=e.opacity!==t;return e.opacity=t,n}))}},{key:"setObjectsPickable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.pickable!==t;return e.pickable=t,n}))}},{key:"setObjectsOffset",value:function(e,t){this.withObjects(e,(function(e){e.offset=t}))}},{key:"withObjects",value:function(e,t){se.isString(e)&&(e=[e]);for(var n=!1,r=0,i=e.length;r0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new fi(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}},{key:"disablePivotSphere",value:function(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}},{key:"startPivot",value:function(){if(this._cameraLookingDownwards())return this._pivoting=!1,!1;var e=this._scene.camera,t=$.lookAtMat4v(e.eye,e.look,e.worldUp);$.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var n=this.getPivotPos();this._cameraOffset[2]+=$.distVec3(e.eye,n),t=$.inverseMat4(t);var r=$.transformVec3(t,this._cameraOffset),i=$.vec3();if($.subVec3(e.eye,n,i),$.addVec3(i,r),e.zUp){var a=i[1];i[1]=i[2],i[2]=a}this._radius=$.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=$.normalizeVec3($.subVec3(e.look,e.eye,tp)),n=$.cross3Vec3(t,e.worldUp,np);return $.sqLenVec3(n)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,n=Math.abs($.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a),l=ip;t.project.unproject(e,o,ap,sp,l);var u=$.normalizeVec3($.subVec3(l,t.eye,tp)),c=$.addVec3(t.eye,$.mulVec3Scalar(u,n,np),rp);this.setPivotPos(c)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var n=this._scene.camera,r=-e,i=-t;1===n.worldUp[2]&&(r=-r),this._azimuth+=.01*-r,this._polar+=.01*i,this._polar=$.clamp(this._polar,.001,Math.PI-.001);var a=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===n.worldUp[2]){var s=a[1];a[1]=a[2],a[2]=s}var o=$.lenVec3($.subVec3(n.look,n.eye,$.vec3())),l=this.getPivotPos();$.addVec3(a,l);var u=$.lookAtMat4v(a,l,n.worldUp);u=$.inverseMat4(u);var c=$.transformVec3(u,this._cameraOffset);u[12]-=c[0],u[13]-=c[1],u[14]-=c[2];var f=[u[8],u[9],u[10]];n.eye=[u[12],u[13],u[14]],$.subVec3(n.eye,$.mulVec3Scalar(f,o),n.look),n.up=[u[4],u[5],u[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),lp=function(){function e(t,n){b(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=n,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=$.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._needFireEvents=!1}return P(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1,this._needFireEvents=!1;var e=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var t=this._scene.snapPick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});t&&t.snappedWorldPos?(this.snapPickResult=t,this.snappedOrPicked=!0,this._needFireEvents=!0):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var n=this.pickResult.canvasPos;if(n[0]===this.pickCursorPos[0]&&n[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents=e,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var r=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents=!0):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents=!0)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!0)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}},{key:"fireEvents",value:function(){if(this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,cursorPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new Zc;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.snappedWorldPos,e.cursorPos=this.pickCursorPos,e.canvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=!1}}},{key:"destroy",value:function(){}}]),e}(),up=$.vec2(),cp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o,l,u=n.pickController,c=0,f=0,p=0,A=0,d=!1,v=$.vec3(),h=!0,I=this._scene.canvas.canvas,y=[];function m(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];I.style.cursor="move",w(),e&&g()}function w(){c=i.pointerCanvasPos[0],f=i.pointerCanvasPos[1],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1]}function g(){u.pickCursorPos=i.pointerCanvasPos,u.schedulePickSurface=!0,u.update(),u.picked&&u.pickedSurface&&u.pickResult&&u.pickResult.worldPos?(d=!0,v.set(u.pickResult.worldPos)):d=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!1}}),I.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:y[t.input.KEY_SHIFT]||r.planView?(s=!0,m()):(s=!0,m(!1));break;case 2:o=!0,m();break;case 3:l=!0,r.panRightClick&&m()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(){if(r.active&&r.pointerEnabled&&(s||o||l)){var e=t.canvas.boundary,n=e[2],u=e[3],p=i.pointerCanvasPos[0],A=i.pointerCanvasPos[1];if(y[t.input.KEY_SHIFT]||r.planView||!r.panRightClick&&o||r.panRightClick&&l){var h=p-c,I=A-f,m=t.camera;if("perspective"===m.projection){var w=Math.abs(d?$.lenVec3($.subVec3(v,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);a.panDeltaX+=1.5*h*w/u,a.panDeltaY+=1.5*I*w/u}else a.panDeltaX+=.5*m.ortho.scale*(h/u),a.panDeltaY+=.5*m.ortho.scale*(I/u)}else!s||o||l||r.planView||(r.firstPerson?(a.rotateDeltaY-=(p-c)/n*r.dragRotationRate/2,a.rotateDeltaX+=(A-f)/u*(r.dragRotationRate/4)):(a.rotateDeltaY-=(p-c)/n*(1.5*r.dragRotationRate),a.rotateDeltaX+=(A-f)/u*(1.5*r.dragRotationRate)));c=p,f=A}}),I.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&i.mouseover&&(h=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:s=!1,o=!1,l=!1}}),I.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var n=e.target,r=0,i=0,a=0,s=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,a+=n.scrollLeft,s+=n.scrollTop,n=n.offsetParent;t[0]=e.pageX+a-r,t[1]=e.pageY+s-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,up);var t=up[0],i=up[1];Math.abs(t-p)<3&&Math.abs(i-A)<3&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:up,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var T=1/60,E=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==E?t-E:0;E=t,n>.05&&(n=.05),n0?n.cameraFlight.flyTo(hp,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(hp),n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot())}}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),yp=function(){function e(t,n,r,i,a){var s=this;b(this,e),this._scene=t;var o=n.pickController,l=n.pivotController,u=n.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null;var c=!1,f=!1,p=this._scene.canvas.canvas,A=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e&&e.entity?e.entity.aabb:t.aabb;if(r){var a=t.camera;$.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})};p.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverOut"),l=u.hasSubs("hoverOff"),p=u.hasSubs("hoverSurface"),A=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=p,o.scheduleSnapOrPick=A,o.update(),o.pickResult){if(o.pickResult.entity){var d=o.pickResult.entity.id;s._lastPickedEntityId!==d&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=d)}u.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&u.fire("hoverSurface",o.pickResult,!0)}else void 0!==s._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),s._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)}}),p.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(c=!0),3===e.which&&(f=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===e.which))){var n=o.pickResult;n&&n.worldPos?(l.setPivotPos(n.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(i.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(c=!1),3===e.which&&(f=!1),l.getPivoting()&&l.endPivot()}),p.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var a=u.hasSubs("picked"),c=u.hasSubs("pickedNothing"),f=u.hasSubs("pickedSurface"),p=u.hasSubs("doublePicked"),d=u.hasSubs("doublePickedSurface"),v=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||p||d||v))return(a||c||f)&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=f,o.update(),o.pickResult?(u.fire("picked",o.pickResult,!0),o.pickedSurface&&u.fire("pickedSurface",o.pickResult,!0)):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(s._clicks=0);if(s._clicks++,1===s._clicks){o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo,o.schedulePickSurface=f,o.update();var h=o.pickResult,I=o.pickedSurface;s._timeout=setTimeout((function(){h?(u.fire("picked",h,!0),I&&(u.fire("pickedSurface",h,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(h.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),s._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==s._timeout&&(window.clearTimeout(s._timeout),s._timeout=null),o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo||p||d,o.schedulePickSurface=o.schedulePickEntity&&d,o.update(),o.pickResult){if(u.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&u.fire("doublePickedSurface",o.pickResult,!0),r.doublePickFlyTo&&(A(o.pickResult),!r.firstPerson&&r.followPointer)){var y=o.pickResult.entity.aabb,m=$.getAABB3Center(y);n.pivotController.setPivotPos(m),n.pivotController.startPivot()&&n.pivotController.showPivot()}}else if(u.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),r.doublePickFlyTo&&(A(),!r.firstPerson&&r.followPointer)){var w=t.aabb,g=$.getAABB3Center(w);n.pivotController.setPivotPos(g),n.pivotController.startPivot()&&n.pivotController.showPivot()}s._clicks=0}}},!1)}return P(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),mp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.input,o=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=s.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=s.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover&&(o[e]=!0,e===s.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=s.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(o[e]=!1,e===s.KEY_SHIFT&&(l.style.cursor=null),n.pivotController.getPivoting()&&n.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var l=n.cameraControl,c=e.deltaTime/1e3;if(!r.planView){var f=l._isKeyDownForAction(l.ROTATE_Y_POS,o),p=l._isKeyDownForAction(l.ROTATE_Y_NEG,o),A=l._isKeyDownForAction(l.ROTATE_X_POS,o),d=l._isKeyDownForAction(l.ROTATE_X_NEG,o),v=c*r.keyboardRotationRate;(f||p||A||d)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),f?a.rotateDeltaY+=v:p&&(a.rotateDeltaY-=v),A?a.rotateDeltaX+=v:d&&(a.rotateDeltaX-=v),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!o[s.KEY_CTRL]&&!o[s.KEY_ALT]){var h=l._isKeyDownForAction(l.DOLLY_BACKWARDS,o),I=l._isKeyDownForAction(l.DOLLY_FORWARDS,o);if(h||I){var y=c*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),I?a.dollyDelta-=y:h&&(a.dollyDelta+=y),u&&(i.followPointerDirty=!0,u=!1)}}var m=l._isKeyDownForAction(l.PAN_FORWARDS,o),w=l._isKeyDownForAction(l.PAN_BACKWARDS,o),g=l._isKeyDownForAction(l.PAN_LEFT,o),T=l._isKeyDownForAction(l.PAN_RIGHT,o),E=l._isKeyDownForAction(l.PAN_UP,o),b=l._isKeyDownForAction(l.PAN_DOWN,o),D=(o[s.KEY_ALT]?.3:1)*c*r.keyboardPanRate;(m||w||g||T||E||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:E&&(a.panDeltaY+=-D),T?a.panDeltaX+=-D:g&&(a.panDeltaX+=D),w?a.panDeltaZ+=D:m&&(a.panDeltaZ+=-D))}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),wp=$.vec3(),gp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.camera,o=n.pickController,l=n.pivotController,u=n.panController,c=1,f=1,p=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(a.dollyDelta)<.001&&(a.dollyDelta=0),Math.abs(a.rotateDeltaX)<.001&&(a.rotateDeltaX=0),Math.abs(a.rotateDeltaY)<.001&&(a.rotateDeltaY=0),0===a.rotateDeltaX&&0===a.rotateDeltaY||(a.dollyDelta=0),r.followPointer&&--c<=0&&(c=1,0!==a.dollyDelta)){if(0===a.rotateDeltaY&&0===a.rotateDeltaX&&r.followPointer&&i.followPointerDirty&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),o.pickResult&&o.pickResult.worldPos?p=o.pickResult.worldPos:(f=1,p=null),i.followPointerDirty=!1),p){var n=Math.abs($.lenVec3($.subVec3(p,t.camera.eye,wp)));f=n/r.dollyProximityThreshold}fr.longTapRadius||Math.abs(I)>r.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),r.planView){var y=t.camera;if("perspective"===y.projection){var m=Math.abs(t.camera.eyeLookDist)*Math.tan(y.perspective.fov/2*Math.PI/180);a.panDeltaX+=h*m/l*r.touchPanRate,a.panDeltaY+=I*m/l*r.touchPanRate}else a.panDeltaX+=.5*y.ortho.scale*(h/l)*r.touchPanRate,a.panDeltaY+=.5*y.ortho.scale*(I/l)*r.touchPanRate}else a.rotateDeltaY-=h/o*(1*r.dragRotationRate),a.rotateDeltaX+=I/l*(1.5*r.dragRotationRate)}else if(2===d){var w=A[0],g=A[1];bp(w,u),bp(g,c);var T=$.geometricMeanVec2(p[0],p[1]),E=$.geometricMeanVec2(u,c),b=$.vec2();$.subVec2(T,E,b);var D=b[0],P=b[1],R=t.camera,C=$.distVec2([w.pageX,w.pageY],[g.pageX,g.pageY]),_=($.distVec2(p[0],p[1])-C)*r.touchDollyRate;if(a.dollyDelta=_,Math.abs(_)<1)if("perspective"===R.projection){var B=s.pickResult?s.pickResult.worldPos:t.center,O=Math.abs($.lenVec3($.subVec3(B,t.camera.eye,[])))*Math.tan(R.perspective.fov/2*Math.PI/180);a.panDeltaX-=D*O/l*r.touchPanRate,a.panDeltaY-=P*O/l*r.touchPanRate}else a.panDeltaX-=.5*R.ortho.scale*(D/l)*r.touchPanRate,a.panDeltaY-=.5*R.ortho.scale*(P/l)*r.touchPanRate;i.pointerCanvasPos=E}for(var S=0;S-1&&t-f<150&&(p>-1&&f-p<325?(Pp(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("doublePicked",o.pickResult),o.pickedSurface&&l.fire("doublePickedSurface",o.pickResult),r.doublePickFlyTo&&d(o.pickResult)):(l.fire("doublePickedNothing"),r.doublePickFlyTo&&d()),p=-1):$.distVec2(u[0],c)<4&&(Pp(a[0],o.pickCursorPos),o.schedulePickEntity=!0,o.schedulePickSurface=s,o.update(),o.pickResult?(o.pickResult.touchInput=!0,l.fire("picked",o.pickResult),o.pickedSurface&&l.fire("pickedSurface",o.pickResult)):l.fire("pickedNothing"),p=t),f=-1),u.length=n.length;for(var A=0,v=n.length;A1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i)).PAN_LEFT=0,r.PAN_RIGHT=1,r.PAN_UP=2,r.PAN_DOWN=3,r.PAN_FORWARDS=4,r.PAN_BACKWARDS=5,r.ROTATE_X_POS=6,r.ROTATE_X_NEG=7,r.ROTATE_Y_POS=8,r.ROTATE_Y_NEG=9,r.DOLLY_FORWARDS=10,r.DOLLY_BACKWARDS=11,r.AXIS_VIEW_RIGHT=12,r.AXIS_VIEW_BACK=13,r.AXIS_VIEW_LEFT=14,r.AXIS_VIEW_FRONT=15,r.AXIS_VIEW_TOP=16,r.AXIS_VIEW_BOTTOM=17,r._keyMap={},r.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},r._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,snapToVertex:true,snapToEdge:true,snapRadius:30,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},r._states={pointerCanvasPos:$.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:$.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var a=r.scene;return r._controllers={cameraControl:g(r),pickController:new lp(g(r),r._configs),pivotController:new op(a,r._configs),panController:new ep(a),cameraFlight:new rt(g(r),{duration:.5})},r._handlers=[new Tp(r.scene,r._controllers,r._configs,r._states,r._updates),new Dp(r.scene,r._controllers,r._configs,r._states,r._updates),new cp(r.scene,r._controllers,r._configs,r._states,r._updates),new Ip(r.scene,r._controllers,r._configs,r._states,r._updates),new yp(r.scene,r._controllers,r._configs,r._states,r._updates),new Rp(r.scene,r._controllers,r._configs,r._states,r._updates),new mp(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new gp(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=i.navMode,i.planView&&(r.planView=i.planView),r.constrainVertical=i.constrainVertical,i.keyboardLayout?r.keyboardLayout=i.keyboardLayout:r.keyMap=i.keyMap,r.doublePickFlyTo=i.doublePickFlyTo,r.panRightClick=i.panRightClick,r.active=i.active,r.followPointer=i.followPointer,r.rotationInertia=i.rotationInertia,r.keyboardPanRate=i.keyboardPanRate,r.touchPanRate=i.touchPanRate,r.keyboardRotationRate=i.keyboardRotationRate,r.dragRotationRate=i.dragRotationRate,r.touchDollyRate=i.touchDollyRate,r.dollyInertia=i.dollyInertia,r.dollyProximityThreshold=i.dollyProximityThreshold,r.dollyMinSpeed=i.dollyMinSpeed,r.panInertia=i.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=i.keyboardDollyRate,r.mouseWheelDollyRate=i.mouseWheelDollyRate,r}return P(n,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",se.isString(e)){var t=this.scene.input,n={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":n[this.PAN_LEFT]=[t.KEY_A],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_Z],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6];break;case"azerty":n[this.PAN_LEFT]=[t.KEY_Q],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_W],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6]}this._keyMap=n}else{var r=e;this._keyMap=r}}},{key:"_isKeyDownForAction",value:function(e,t){var n=this._keyMap[e];if(!n)return!1;t||(t=this.scene.input.keyDown);for(var r=0,i=n.length;r0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),v(T(n.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var n=this.metaScene;if(e.propertySets)for(var r=0,i=e.propertySets.length;r0?Lp(t):null,s=n&&n.length>0?Lp(n):null;return function e(t){if(t){var n=!0;(s&&s[t.type]||a&&!a[t.type])&&(n=!1),n&&r.push(t.id);var i=t.children;if(i)for(var o=0,l=i.length;o * Copyright (c) 2022 Niklas von Hertzen