@xeokit/xeokit-sdk 2.4.2-beta-37 → 2.4.2-beta-38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ var e,t=o().mark(RE),n=o().mark(CE),r=o().mark(UD);function i(e,t){var n=Object.
14
14
  /**
15
15
  * @author https://github.com/tmarti, with support from https://tribia.com/
16
16
  * @license MIT
17
- **/var $u=null;function ec(e,t){var n,r,i,a,s,o,l=3*e,u=3*t,c=Math.min(n=$u[l],r=$u[l+1],i=$u[l+2]),f=Math.min(a=$u[u],s=$u[u+1],o=$u[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 tc(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r<i;r++)n[r]=r;$u=new Int32Array(e.length);for(var a=0,s=e.length;a<s;a++)$u[a]=e[a]>>t;n.sort(ec);for(var o=new Int32Array(e.length),l=0,u=n.length;l<u;l++)o[3*l+0]=e[3*n[l]+0],o[3*l+1]=e[3*n[l]+1],o[3*l+2]=e[3*n[l]+2];return o}var nc=null;function rc(e,t){var n=nc[2*e]-nc[2*t];return 0!==n?n:nc[2*e+1]-nc[2*t+1]}function ic(e){if(0===(e||[]).length)return[];for(var t=new Int32Array(e.length/2),n=0,r=t.length;n<r;n++)t[n]=n;for(var i=0,a=e.length;i<a;i+=2)if(e[i]>e[i+1]){var s=e[i];e[i]=e[i+1],e[i+1]=s}nc=new Int32Array(e),t.sort(rc);for(var o=new Int32Array(e.length),l=0,u=t.length;l<u;l++)o[2*l+0]=e[2*t[l]+0],o[2*l+1]=e[2*t[l]+1];return o}function ac(e,t){var n={},r={};e.forEach((function(e){for(var t=e.indices,i=e.edgeIndices,a=e.positionsCompressed,s=0,o=t.length;s<o;s+=3){var l=a[3*t[s]]+"_"+a[3*t[s]+1]+"_"+a[3*t[s]+2]+"/"+a[3*t[s+1]]+"_"+a[3*t[s+1]+1]+"_"+a[3*t[s+1]+2]+"/"+a[3*t[s+2]]+"_"+a[3*t[s+2]+1]+"_"+a[3*t[s+2]+2];n[l]=!0}e.edgeIndices.length/2;for(var u=0,c=i.length;u<c;u+=2){var f=a[3*i[u]]+"_"+a[3*i[u]+1]+"_"+a[3*i[u]+2]+"/"+a[3*i[u+1]]+"_"+a[3*i[u+1]+1]+"_"+a[3*i[u+1]+2]+"/";r[f]=!0}}));var i=t.indices;t.edgeIndices;for(var a=t.positionsCompressed,s=0,o=i.length;s<o;s+=3){var l=a[3*i[s]]+"_"+a[3*i[s]+1]+"_"+a[3*i[s]+2]+"/"+a[3*i[s+1]]+"_"+a[3*i[s+1]+1]+"_"+a[3*i[s+1]+2]+"/"+a[3*i[s+2]]+"_"+a[3*i[s+2]+1]+"_"+a[3*i[s+2]+2];if(!(l in n))throw console.log("Not found "+l),"Ohhhh!"}}var sc=$.vec3(),oc=$.vec3(),lc=$.vec3();$.vec3();var uc=$.vec4(),cc=$.mat4(),fc=function(){function e(t,n){b(this,e),this._scene=t,this._withSAO=n,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{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,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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=sc;if(v){var y=$.transformPoint3(f,u,oc);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=Be(i.viewMatrix,I,cc),(d=lc)[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._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),g=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var E=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*g,b=a.renderFlags,D=0;D<w;D++){var P=this._uSectionPlanes[D];if(P)if(D<g){var R=b.sectionPlanesActivePerLayer[T+D];if(s.uniform1i(P.active,R?1:0),R){var C=E[D];if(u){var _=Le(C.dist,C.dir,u,sc);s.uniform3fv(P.pos,_)}else s.uniform3fv(P.pos,C.pos);s.uniform3fv(P.dir,C.dir)}}else s.uniform1i(P.active,0)}o.numIndices8Bits>0&&(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 bt(t,this._buildShader()),this._program.errors)return this.errors=this._program.errors,void console.error(this.errors);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;a<s;a++)switch(i[a].type){case"dir":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=null,this._uLightDir[a]=r.getLocation("lightDir"+a);break;case"point":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=r.getLocation("lightPos"+a),this._uLightDir[a]=null,this._uLightAttenuation[a]=r.getLocation("lightAttenuation"+a);break;case"spot":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=r.getLocation("lightPos"+a),this._uLightDir[a]=r.getLocation("lightDir"+a),this._uLightAttenuation[a]=r.getLocation("lightAttenuation"+a)}this._uSceneModelMatrix=r.getLocation("sceneModelMatrix"),this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.getNumAllocatedSectionPlanes();o<l;o++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+o),pos:r.getLocation("sectionPlanePos"+o),dir:r.getLocation("sectionPlaneDir"+o)});this._withSAO&&(this._uOcclusionTexture="uOcclusionTexture",this._uSAOParams=r.getLocation("uSAOParams")),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=r.getLocation("uCameraEyeRtc")}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=this._program,i=t._lightsState.lights,a=t.camera.project;r.bind(),this._uLightAmbient&&n.uniform4fv(this._uLightAmbient,t._lightsState.getAmbientColorAndIntensity());for(var s=0,o=i.length;s<o;s++){var l=i[s];this._uLightColor[s]&&n.uniform4f(this._uLightColor[s],l.color[0],l.color[1],l.color[2],l.intensity),this._uLightPos[s]&&(n.uniform3fv(this._uLightPos[s],l.pos),this._uLightAttenuation[s]&&n.uniform1f(this._uLightAttenuation[s],l.attenuation)),this._uLightDir[s]&&n.uniform3fv(this._uLightDir[s],l.dir)}if(this._withSAO){var u=t.sao;if(u.possible){var c=n.drawingBufferWidth,f=n.drawingBufferHeight;uc[0]=c,uc[1]=f,uc[2]=u.blendCutoff,uc[3]=u.blendFactor,n.uniform4fv(this._uSAOParams,uc),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,10)}}if(t.logarithmicDepthBufferEnabled){var p=2/(Math.log(a.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,p)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e,t=this._scene,n=t._sectionPlanesState,r=t._lightsState,i=n.getNumAllocatedSectionPlanes()>0,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;"),a.push("uniform mat4 sceneModelMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectMatrix;"),a.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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<o;s++)"ambient"!==(e=r.lights[s]).type&&(a.push("uniform vec4 lightColor"+s+";"),"dir"===e.type&&a.push("uniform vec3 lightDir"+s+";"),"point"===e.type&&a.push("uniform vec3 lightPos"+s+";"),"spot"===e.type&&(a.push("uniform vec3 lightPos"+s+";"),a.push("uniform vec3 lightDir"+s+";")));i&&(a.push("out vec4 vWorldPosition;"),a.push("flat out uint vFlags2;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int polygonIndex = gl_VertexID / 3;"),a.push("int h_packed_object_id_index = (polygonIndex >> 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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 = sceneModelMatrix * ((objectDecodeAndInstanceMatrix * vec4(position, 1.0))); "),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;l<u;l++)if("ambient"!==(e=r.lights[l]).type){if("dir"===e.type)"view"===e.space?a.push("viewLightDir = normalize(lightDir"+l+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+l+", 0.0)).xyz);");else if("point"===e.type)"view"===e.space?a.push("viewLightDir = -normalize(lightPos"+l+" - viewPosition.xyz);"):a.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+l+", 0.0)).xyz);");else{if("spot"!==e.type)continue;"view"===e.space?a.push("viewLightDir = normalize(lightDir"+l+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+l+", 0.0)).xyz);")}a.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),a.push("reflectedColor += lambertian * (lightColor"+l+".rgb * lightColor"+l+".a);")}return a.push("vec3 rgb = vec3(color.rgb) / 255.0;"),a.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags2 = flags2.r;")),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.getNumAllocatedSectionPlanes()>0,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.getNumAllocatedSectionPlanes();i<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = vFlags2 > 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.getNumAllocatedSectionPlanes();s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 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}(),pc=new Float32Array([1,1,1]),Ac=$.vec3(),dc=$.vec3(),vc=$.vec3();$.vec3();var hc=$.mat4(),Ic=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=Ac;if(u){var I=dc;$.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=Be(A,h,hc),(v=vc)[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===Xs.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===Xs.SILHOUETTE_HIGHLIGHTED){var g=r.highlightMaterial._state,E=g.fillColor,T=g.fillAlpha;s.uniform4f(this._uColor,E[0],E[1],E[2],T)}else if(n===Xs.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,pc);if(r.logarithmicDepthBufferEnabled){var R=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,R)}var C=r._sectionPlanesState.getNumAllocatedSectionPlanes(),_=r._sectionPlanesState.sectionPlanes.length;if(C>0)for(var B=r._sectionPlanesState.sectionPlanes,O=t.layerIndex*_,S=a.renderFlags,N=0;N<C;N++){var L=this._uSectionPlanes[N];if(L)if(N<_){var M=S.sectionPlanesActivePerLayer[O+N];if(s.uniform1i(L.active,M?1:0),M){var x=B[N];if(u){var F=Le(x.dist,x.dir,u,Ac);s.uniform3fv(L.pos,F)}else s.uniform3fv(L.pos,x.pos);s.uniform3fv(L.dir,x.dir)}}else s.uniform1i(L.active,0)}o.numIndices8Bits>0&&(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 bt(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("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=t.camera.project;if(this._program.bind(),t.logarithmicDepthBufferEnabled){var i=2/(Math.log(r.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,i)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("uniform vec4 color;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),yc=new Float32Array([0,0,0,1]),mc=$.vec3(),wc=$.vec3();$.vec3();var gc=$.mat4(),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=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=mc;if(v){var y=$.transformPoint3(f,u,wc);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=Be(A,I,gc)}else d=A;if(s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),n===Xs.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===Xs.EDGES_HIGHLIGHTED){var E=i.highlightMaterial._state,T=E.edgeColor,b=E.edgeAlpha;s.uniform4f(this._uColor,T[0],T[1],T[2],b)}else if(n===Xs.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,yc);var C=i._sectionPlanesState.getNumAllocatedSectionPlanes(),_=i._sectionPlanesState.sectionPlanes.length;if(C>0)for(var B=i._sectionPlanesState.sectionPlanes,O=t.layerIndex*_,S=r.renderFlags,N=0;N<C;N++){var L=this._uSectionPlanes[N];if(L)if(N<_){var M=S.sectionPlanesActivePerLayer[O+N];if(s.uniform1i(L.active,M?1:0),M){var x=B[N];if(u){var F=Le(x.dist,x.dir,u,mc);s.uniform3fv(L.pos,F)}else s.uniform3fv(L.pos,x.pos);s.uniform3fv(L.dir,x.dir)}}else s.uniform1i(L.active,0)}o.numEdgeIndices8Bits>0&&(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 bt(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._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix"}}},{key:"_bindProgram",value:function(){var e=this._scene,t=e.canvas.gl,n=this._program,r=e.camera.project;if(n.bind(),e.logarithmicDepthBufferEnabled){var i=2/(Math.log(r.far+1)/Math.LN2);t.uniform1f(this._uLogDepthBufFC,i)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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;"),n.push("uniform mat4 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("mat4 matrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.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("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.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vColor;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Tc=$.vec3(),bc=$.vec3();$.vec3();var Dc=$.mat4(),Pc=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=Tc;if(v){var y=$.transformPoint3(f,u,bc);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=Be(A,I,Dc)}else d=A;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var m=i._sectionPlanesState.getNumAllocatedSectionPlanes(),w=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var g=i._sectionPlanesState.sectionPlanes,E=t.layerIndex*w,T=r.renderFlags,b=0;b<m;b++){var D=this._uSectionPlanes[b];if(D)if(b<w){var P=T.sectionPlanesActivePerLayer[E+b];if(s.uniform1i(D.active,P?1:0),P){var R=g[b];if(u){var C=Le(R.dist,R.dir,u,Tc);s.uniform3fv(D.pos,C)}else s.uniform3fv(D.pos,R.pos);s.uniform3fv(D.dir,R.dir)}}else s.uniform1i(D.active,0)}o.numEdgeIndices8Bits>0&&(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 bt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix"}}},{key:"_bindProgram",value:function(){var e=this._scene,t=e.canvas.gl,n=this._program,r=e.camera.project;if(n.bind(),e.logarithmicDepthBufferEnabled){var i=2/(Math.log(r.far+1)/Math.LN2);t.uniform1f(this._uLogDepthBufFC,i)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform highp sampler2D uObjectPerObjectOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.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.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vColor;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Rc=$.vec3(),Cc=$.vec3(),_c=$.vec3(),Bc=$.mat4(),Oc=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=Rc;if(v){var y=$.transformPoint3(A,f,Cc);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=Be(o.viewMatrix,I,Bc),(i=_c)[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.uniform2f(this._uDrawingBufferSize,l.drawingBufferWidth,l.drawingBufferHeight),l.uniformMatrix4fv(this._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),g=s._sectionPlanesState.sectionPlanes.length;if(w>0)for(var E=s._sectionPlanesState.sectionPlanes,T=t.layerIndex*g,b=a.renderFlags,D=0;D<w;D++){var P=this._uSectionPlanes[D];if(P)if(D<g){var R=b.sectionPlanesActivePerLayer[T+D];if(l.uniform1i(P.active,R?1:0),R){var C=E[D];if(f){var _=Le(C.dist,C.dir,f,Rc);l.uniform3fv(P.pos,_)}else l.uniform3fv(P.pos,C.pos);l.uniform3fv(P.dir,C.dir)}}else l.uniform1i(P.active,0)}u.numIndices8Bits>0&&(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 bt(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._uDrawingBufferSize=n.getLocation("drawingBufferSize"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(e){var t=this._scene.canvas.gl;this._program.bind(),t.uniform1i(this._uPickInvisible,e.pickInvisible)}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("uniform vec2 drawingBufferSize;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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*objectDecodeAndInstanceMatrix)) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uvec4 vFlags2;");for(var r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vPickColor;"),n.push("out vec4 outPickColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = (float(vFlags2.x) > 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push(" if (sectionPlaneActive"+r+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+r+".xyz, vWorldPosition.xyz - sectionPlanePos"+r+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Sc=$.vec3(),Nc=$.vec3(),Lc=$.vec3();$.vec3();var Mc=$.mat4(),xc=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),f||0!==p[0]||0!==p[1]||0!==p[2]){var h=Sc;if(f){var I=Nc;$.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=Be(v,h,Mc),(i=Lc)[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.uniform2f(this._uDrawingBufferSize,l.drawingBufferWidth,l.drawingBufferHeight),l.uniform1f(this._uPickZNear,e.pickZNear),l.uniform1f(this._uPickZFar,e.pickZFar),l.uniformMatrix4fv(this._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),w=s._sectionPlanesState.sectionPlanes.length;if(m>0)for(var g=s._sectionPlanesState.sectionPlanes,E=t.layerIndex*w,T=a.renderFlags,b=0;b<m;b++){var D=this._uSectionPlanes[b];if(D)if(b<w){var P=T.sectionPlanesActivePerLayer[E+b];if(l.uniform1i(D.active,P?1:0),P){var R=g[b];if(f){var C=Le(R.dist,R.dir,f,Sc);l.uniform3fv(D.pos,C)}else l.uniform3fv(D.pos,R.pos);l.uniform3fv(D.dir,R.dir)}}else l.uniform1i(D.active,0)}u.numIndices8Bits>0&&(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 bt(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._uDrawingBufferSize=n.getLocation("drawingBufferSize"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._uPickZNear=n.getLocation("pickZNear"),this._uPickZFar=n.getLocation("pickZFar"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("uniform vec2 drawingBufferSize;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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*objectDecodeAndInstanceMatrix)) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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.getNumAllocatedSectionPlanes()>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;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vViewPosition;"),n.push("vec4 packDepth(const in float depth) {"),n.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),n.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),n.push(" vec4 res = fract(depth * bitShift);"),n.push(" res -= res.xxyz * bitMask;"),n.push(" return res;"),n.push("}"),n.push("out vec4 outPackedDepth;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push(" if (sectionPlaneActive"+r+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+r+".xyz, vWorldPosition.xyz - sectionPlanePos"+r+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Fc=$.vec3(),Hc=$.vec3(),Uc=$.vec3(),Gc=$.vec3();$.vec3();var kc=$.mat4(),jc=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=Fc;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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=Hc;if(y){var g=$.transformPoint3(A,f,Uc);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=Be(h,w,kc),(i=Gc)[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._uSceneModelMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var E=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,E);var T=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(T>0)for(var D=s._sectionPlanesState.sectionPlanes,P=t.layerIndex*b,R=a.renderFlags,C=0;C<T;C++){var _=this._uSectionPlanes[C];if(_)if(C<b){var B=R.sectionPlanesActivePerLayer[P+C];if(l.uniform1i(_.active,B?1:0),B){var O=D[C];if(f){var S=Le(O.dist,O.dir,f,Fc);l.uniform3fv(_.pos,S)}else l.uniform3fv(_.pos,O.pos);l.uniform3fv(_.dir,O.dir)}}else l.uniform1i(_.active,0)}var N="edge"===e.snapMode?l.LINES:l.POINTS;u.numEdgeIndices8Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),l.drawArrays(N,0,u.numEdgeIndices8Bits)),u.numEdgeIndices16Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),l.drawArrays(N,0,u.numEdgeIndices16Bits)),u.numEdgeIndices32Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),l.drawArrays(N,0,u.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new bt(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._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._uLogDepthBufFC=n.getLocation("logDepthBufFC"),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("uSnapVectorA"),this.uInverseVectorAB=n.getLocation("uSnapInvVectorAB"),this._uLayerNumber=n.getLocation("uLayerNumber"),this._uCoordinateScaler=n.getLocation("uCoordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>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._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in highp vec3 relativeToOriginPosition;"),n.push("out highp ivec4 outCoords;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0;a<e._sectionPlanesState.getNumAllocatedSectionPlanes();a++)n.push(" if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 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}(),Vc=$.vec3(),Qc=$.vec3(),Wc=$.vec3(),zc=$.vec3();$.vec3();var Kc=$.mat4(),Yc=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=Vc;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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=Qc;if(y){var g=Wc;$.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=Be(h,w,Kc),(i=zc)[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 E=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,E);var T=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(T>0)for(var D=s._sectionPlanesState.sectionPlanes,P=t.layerIndex*b,R=a.renderFlags,C=0;C<T;C++){var _=this._uSectionPlanes[C];if(_)if(C<b){var B=R.sectionPlanesActivePerLayer[P+C];if(l.uniform1i(_.active,B?1:0),B){var O=D[C];if(f){var S=Le(O.dist,O.dir,f,Vc);l.uniform3fv(_.pos,S)}else l.uniform3fv(_.pos,O.pos);l.uniform3fv(_.dir,O.dir)}}else l.uniform1i(_.active,0)}u.numIndices8Bits>0&&(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 bt(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("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._uLogDepthBufFC=n.getLocation("logDepthBufFC"),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this._uVectorA=n.getLocation("uVectorAB"),this._uInverseVectorAB=n.getLocation("uInverseVectorAB"),this._uLayerNumber=n.getLocation("uLayerNumber"),this._uCoordinateScaler=n.getLocation("uCoordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("}"),n.push("flat out vec4 vPickColor;"),n.push("out vec4 vWorldPosition;"),t&&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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vWorldPosition = worldPosition;"),t&&n.push("vFlags2 = flags2.r;"),n.push("vPickColor = vec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0));"),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(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>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;"),n.push("in vec4 vWorldPosition;"),n.push("flat in vec4 vPickColor;"),t){n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in highp vec3 relativeToOriginPosition;"),n.push("layout(location = 0) out highp ivec4 outCoords;"),n.push("layout(location = 1) out highp ivec4 outNormal;"),n.push("layout(location = 2) out lowp uvec4 outPickColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0;a<e._sectionPlanesState.getNumAllocatedSectionPlanes();a++)n.push(" if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 0.0) { discard; }"),n.push(" }")}return n.push(" float dx = dFdx(vFragDepth);"),n.push(" float dy = dFdy(vFragDepth);"),n.push(" float diff = sqrt(dx*dx+dy*dy);"),n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),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(".concat($.MAX_INT,"), 1.0);")),n.push("outPickColor = uvec4(vPickColor);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Xc=$.vec3(),qc=$.vec3(),Jc=$.vec3();$.vec3();var Zc=$.mat4(),$c=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=Xc;if(u){var I=qc;$.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=Be(A,h,Zc),(v=Jc)[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.getNumAllocatedSectionPlanes(),m=i._sectionPlanesState.sectionPlanes.length;if(y>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,E=r.renderFlags,T=0;T<y;T++){var b=this._uSectionPlanes[T];if(b)if(T<m){var D=E.sectionPlanesActivePerLayer[g+T];if(s.uniform1i(b.active,D?1:0),D){var P=w[T];if(u){var R=Le(P.dist,P.dir,u,Xc);s.uniform3fv(b.pos,R)}else s.uniform3fv(b.pos,P.pos);s.uniform3fv(b.dir,P.dir)}}else s.uniform1i(b.active,0)}o.numIndices8Bits>0&&(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 bt(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("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._uPickZNear=n.getLocation("pickZNear"),this._uPickZFar=n.getLocation("pickZFar"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(){var e=this._scene;e.canvas.gl,e.camera.project,this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureOcclusionRenderer 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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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*objectDecodeAndInstanceMatrix)) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),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.getNumAllocatedSectionPlanes()>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("flat in uint vFlags2;");for(var r=0;r<e.getNumAllocatedSectionPlanes();r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = (float(vFlags2) > 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i<e.getNumAllocatedSectionPlanes();i++)n.push(" if (sectionPlaneActive"+i+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 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}(),ef=$.vec3(),tf=$.vec3(),nf=$.vec3();$.vec3();var rf=$.mat4(),af=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=ef;if(v){var y=$.transformPoint3(f,u,tf);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=Be(i.viewMatrix,I,rf),(d=nf)[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._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),g=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var E=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*g,b=a.renderFlags,D=0;D<w;D++){var P=this._uSectionPlanes[D];if(P)if(D<g){var R=b.sectionPlanesActivePerLayer[T+D];if(s.uniform1i(P.active,R?1:0),R){var C=E[D];if(u){var _=Le(C.dist,C.dir,u,ef);s.uniform3fv(P.pos,_)}else s.uniform3fv(P.pos,C.pos);s.uniform3fv(P.dir,C.dir)}}else s.uniform1i(P.active,0)}o.numIndices8Bits>0&&(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 bt(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("objectDecodeAndInstanceMatrix"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=this._program,i=t.camera.project;if(r.bind(),n.uniformMatrix4fv(this._uProjMatrix,!1,i.matrix),t.logarithmicDepthBufferEnabled){var a=2/(Math.log(i.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,a)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),sf=$.vec3(),of=$.vec3(),lf=$.vec3();$.vec3();var uf=$.mat4(),cf=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=sf;if(v){var y=of;$.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=Be(p,I,uf),(d=lf)[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.getNumAllocatedSectionPlanes(),w=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var g=i._sectionPlanesState.sectionPlanes,E=t.layerIndex*w,T=r.renderFlags,b=0;b<m;b++){var D=this._uSectionPlanes[b];if(D)if(b<w){var P=T.sectionPlanesActivePerLayer[E+b];if(s.uniform1i(D.active,P?1:0),P){var R=g[b];if(l){var C=Le(R.dist,R.dir,l,sf);s.uniform3fv(D.pos,C)}else s.uniform3fv(D.pos,R.pos);s.uniform3fv(D.dir,R.dir)}}else s.uniform1i(D.active,0)}s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,t._state.objectDecodeAndInstanceMatrix),this._aPosition.bindArrayBuffer(o.positionsBuf),this._aOffset.bindArrayBuffer(o.offsetsBuf),this._aNormal.bindArrayBuffer(o.normalsBuf),this._aColor.bindArrayBuffer(o.colorsBuf),this._aFlags.bindArrayBuffer(o.flagsBuf),this._aFlags2&&this._aFlags2.bindArrayBuffer(o.flags2Buf),o.indicesBuf.bind(),s.drawElements(s.TRIANGLES,o.indicesBuf.numItems,o.indicesBuf.itemType,0)}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new bt(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("objectDecodeAndInstanceMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uWorldNormalMatrix=n.getLocation("worldNormalMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uViewNormalMatrix=n.getLocation("viewNormalMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aNormal=n.getAttribute("normal"),this._aColor=n.getAttribute("color"),this._aFlags=n.getAttribute("flags"),this._aFlags2&&(this._aFlags2=n.getAttribute("flags2")),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC"))}}},{key:"_bindProgram",value:function(){var e=this._scene,t=e.canvas.gl,n=e.camera.project;if(this._program.bind(),t.uniformMatrix4fv(this._uProjMatrix,!1,n.matrix),e.logarithmicDepthBufferEnabled){var r=2/(Math.log(n.far+1)/Math.LN2);t.uniform1f(this._uLogDepthBufFC,r)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=[];return n.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&dt.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 objectDecodeAndInstanceMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),dt.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 * (objectDecodeAndInstanceMatrix * 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&&(dt.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.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&dt.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&&dt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),t){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(var r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec3 vViewNormal;"),n.push("vec3 packNormalToRGB( const in vec3 normal ) {"),n.push(" return normalize( normal ) * 0.5 + 0.5;"),n.push("}"),n.push("void main(void) {"),t){n.push(" bool clippable = (float(vFlags2.x) > 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i<e._sectionPlanesState.getNumAllocatedSectionPlanes();i++)n.push(" if (sectionPlaneActive"+i+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&dt.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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),ff=$.vec3(),pf=$.vec3(),Af=$.vec3();$.vec3(),$.vec4();var df=$.mat4(),vf=function(){function e(t,n){b(this,e),this._scene=t,this._withSAO=n,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{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,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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=ff;if(v){var y=$.transformPoint3(f,u,pf);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=Be(i.viewMatrix,I,df),(d=Af)[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.uniform2fv(this._uPickClipPos,e.pickClipPos),s.uniform2f(this._uDrawingBufferSize,s.drawingBufferWidth,s.drawingBufferHeight),s.uniformMatrix4fv(this._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),g=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var E=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*g,b=a.renderFlags,D=0;D<w;D++){var P=this._uSectionPlanes[D];if(P)if(D<g){var R=b.sectionPlanesActivePerLayer[T+D];if(s.uniform1i(P.active,R?1:0),R){var C=E[D];if(u){var _=Le(C.dist,C.dir,u,ff);s.uniform3fv(P.pos,_)}else s.uniform3fv(P.pos,C.pos);s.uniform3fv(P.dir,C.dir)}}else s.uniform1i(P.active,0)}o.numIndices8Bits>0&&(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 bt(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._uDrawingBufferSize=n.getLocation("drawingBufferSize"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=this._program,i=t.camera.project;if(r.bind(),t.logarithmicDepthBufferEnabled){var a=2/(Math.log(i.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,a)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=[];return n.push("#version 300 es"),n.push("// trianglesDatatextureNormalsRenderer 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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("uniform vec2 drawingBufferSize;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),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("}"),n.push("out vec4 vWorldPosition;"),t&&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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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));")),n.push("vWorldPosition = worldPosition;"),t&&n.push("vFlags2 = flags2.r;"),n.push("gl_Position = remapClipPos(clipPos);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTexturePickNormalsRenderer 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;"),t){n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("out highp ivec4 outNormal;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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(" 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(".concat($.MAX_INT,"), 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}(),hf=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:"eagerCreateRenders",value:function(){this._silhouetteRenderer||(this._silhouetteRenderer=new Ic(this._scene)),this._pickMeshRenderer||(this._pickMeshRenderer=new Oc(this._scene)),this._pickDepthRenderer||(this._pickDepthRenderer=new xc(this._scene)),this._pickNormalsRenderer||(this._pickNormalsRenderer=new vf(this._scene)),this._vertexDepthRenderer||(this._vertexDepthRenderer=new jc(this._scene)),this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Yc(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new fc(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new fc(this._scene,!0)),this._colorRendererWithSAO}},{key:"colorQualityRendererWithSAO",get:function(){return this._colorQualityRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Ic(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new af(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new cf(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new Ec(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new Pc(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Oc(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new vf(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new vf(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new xc(this._scene)),this._pickDepthRenderer}},{key:"vertexDepthRenderer",get:function(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new jc(this._scene)),this._vertexDepthRenderer}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Yc(this._scene)),this._snapDepthBufInitRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new $c(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}(),If={};var yf=P((function e(){b(this,e),this.positionsCompressed=[],this.lenPositionsCompressed=0,this.metallicRoughness=[],this.indices8Bits=[],this.lenIndices8Bits=0,this.indices16Bits=[],this.lenIndices16Bits=0,this.indices32Bits=[],this.lenIndices32Bits=0,this.edgeIndices8Bits=[],this.lenEdgeIndices8Bits=0,this.edgeIndices16Bits=[],this.lenEdgeIndices16Bits=0,this.edgeIndices32Bits=[],this.lenEdgeIndices32Bits=0,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=[]})),mf=function(){function e(){b(this,e),this.texturePerObjectColorsAndFlags=null,this.texturePerObjectOffsets=null,this.texturePerObjectInstanceMatrices=null,this.texturePerObjectPositionsDecodeMatrix=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){this.texturePerObjectPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,n,2),this.texturePerObjectColorsAndFlags.bindTexture(e,r,3),this.texturePerObjectInstanceMatrices.bindTexture(e,i,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}(),wf=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}(),gf={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(gf,null,4));var e=0;Object.keys(gf).forEach((function(t){t.startsWith("size")&&(e+=gf[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/gf.totalPolygons).toFixed(2)));var t={};Object.keys(gf).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((gf[n]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var Ef=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);gf.sizeDataColorsAndFlags+=c.byteLength,gf.numberOfTextures++;for(var f=0;f<o;f++)c.set(t[f],32*f+0),c.set(n[f],32*f+4),c.set([0,0,0,0],32*f+8),c.set([0,0,0,0],32*f+12),c.set([r[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 wf(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);gf.sizeDataTextureOffsets+=i.byteLength,gf.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 wf(e,a,n,r,i)}},{key:"generateTextureForInstancingMatrices",value:function(e,t){var n=t.length;if(0===n)throw"num instance matrices===0";var r=2048,i=Math.ceil(n/512),a=new Float32Array(8192*i);gf.numberOfTextures++;for(var s=0;s<t.length;s++)a.set(t[s],16*s);var o=e.createTexture();return e.bindTexture(e.TEXTURE_2D,o),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGBA,e.FLOAT,a,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 wf(e,o,r,i,a)}},{key:"generateTextureForPositionsDecodeMatrices",value:function(e,t){var n=t.length;if(0===n)throw"num decode+entity matrices===0";var r=2048,i=Math.ceil(n/512),a=new Float32Array(8192*i);gf.sizeDataPositionDecodeMatrices+=a.byteLength,gf.numberOfTextures++;for(var s=0;s<t.length;s++)a.set(t[s],16*s);var o=e.createTexture();return e.bindTexture(e.TEXTURE_2D,o),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGBA,e.FLOAT,a,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 wf(e,o,r,i)}},{key:"generateTextureFor8BitIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/3/r);if(0===i)throw"texture height===0";var a=new Uint8Array(r*i*3);gf.sizeDataTextureIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RGB8UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGB_INTEGER,e.UNSIGNED_BYTE,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor16BitIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/3/r);if(0===i)throw"texture height===0";var a=new Uint16Array(r*i*3);gf.sizeDataTextureIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RGB16UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGB_INTEGER,e.UNSIGNED_SHORT,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor32BitIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/3/r);if(0===i)throw"texture height===0";var a=new Uint32Array(r*i*3);gf.sizeDataTextureIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGB_INTEGER,e.UNSIGNED_INT,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor8BitsEdgeIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/2/r);if(0===i)throw"texture height===0";var a=new Uint8Array(r*i*2);gf.sizeDataTextureEdgeIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RG8UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RG_INTEGER,e.UNSIGNED_BYTE,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor16BitsEdgeIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/2/r);if(0===i)throw"texture height===0";var a=new Uint16Array(r*i*2);gf.sizeDataTextureEdgeIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RG16UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RG_INTEGER,e.UNSIGNED_SHORT,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor32BitsEdgeIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/2/r);if(0===i)throw"texture height===0";var a=new Uint32Array(r*i*2);gf.sizeDataTextureEdgeIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RG32UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RG_INTEGER,e.UNSIGNED_INT,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureForPositions",value:function(e,t,n){var r=n/3,i=4096,a=Math.ceil(r/i);if(0===a)throw"texture height===0";var s=new Uint16Array(i*a*3);gf.sizeDataTexturePositions+=s.byteLength,gf.numberOfTextures++;for(var o=0,l=0,u=t.length;o<u;o++){var c=t[o];s.set(c,l),l+=c.length}var f=e.createTexture();return e.bindTexture(e.TEXTURE_2D,f),e.texStorage2D(e.TEXTURE_2D,1,e.RGB16UI,i,a),e.texSubImage2D(e.TEXTURE_2D,0,0,0,i,a,e.RGB_INTEGER,e.UNSIGNED_SHORT,s,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 wf(e,f,i,a)}},{key:"generateTextureForPackedPortionIds",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=t.length,r=4096,i=Math.ceil(n/r);if(0===i)throw"texture height===0";var a=new Uint16Array(r*i);a.set(t,0),gf.sizeDataTexturePortionIds+=a.byteLength,gf.numberOfTextures++;var s=e.createTexture();return e.bindTexture(e.TEXTURE_2D,s),e.texStorage2D(e.TEXTURE_2D,1,e.R16UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RED_INTEGER,e.UNSIGNED_SHORT,a,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 wf(e,s,r,i)}}]),e}();$.vec4([0,0,0,1]),$.vec4([0,0,0,1]),$.vec4([0,0,0,1]);var Tf=new Float32Array(16),bf=new Uint8Array(4),Df=new Float32Array(3);$.AABB3();var Pf=0,Rf=$.identityMat4(),Cf=function(){function e(t,n){var r,i,a;b(this,e),gf.numberOfLayers++,this._layerNumber=Pf++,this.sortId="TriDTX-".concat(this._layerNumber),this.layerIndex=n.layerIndex,this._dataTextureRenderers=(r=t.scene,i=r.id,(a=If[i])||(a=new hf(r),If[i]=a,a._compile(),a.eagerCreateRenders(),r.on("compile",(function(){a._compile(),a.eagerCreateRenders()})),r.on("destroyed",(function(){delete If[i],a._destroy()}))),a),this.model=t,this._buffer=new yf,this._dataTextureState=new mf,this._dataTextureGenerator=new Ef,this._state=new Wt({origin:$.vec3(n.origin),metallicRoughnessBuf:null,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=$.collapseAABB3(),this._numUpdatesInFrame=0,this._finalized=!1}return P(e,[{key:"canCreatePortion",value:function(e){if(this._finalized)throw"Already finalized";var t=e.buckets.length;this._numPortions+t>65536&&gf.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)&&gf.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=[];e.buckets.forEach((function(r,i){var a=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(i):"".concat(e.id,"#").concat(i),s=t._bucketGeometries[a];s||(s=t._createBucketGeometry(e,r),t._bucketGeometries[a]=s);var o=t._createSubPortion(e,s,r);n.push(o)}));var r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(n),this.model.numPortions++,r}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var n=8*Math.ceil(t.indices.length/3/8)*3;gf.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;gf.overheadSizeAlignementEdgeIndices+=2*(i-t.edgeIndices.length);var a=new Uint32Array(i);a.fill(0),a.set(t.edgeIndices),t.edgeIndices=a}var s=t.positionsCompressed,o=t.indices,l=t.edgeIndices,u=this._buffer;u.positionsCompressed.push(s);var c,f=u.lenPositionsCompressed/3,p=s.length/3;u.lenPositionsCompressed+=s.length;var A,d,v=0;o&&(v=o.length/3,p<=256?(A=u.indices8Bits,c=u.lenIndices8Bits/3,u.lenIndices8Bits+=o.length):p<=65536?(A=u.indices16Bits,c=u.lenIndices16Bits/3,u.lenIndices16Bits+=o.length):(A=u.indices32Bits,c=u.lenIndices32Bits/3,u.lenIndices32Bits+=o.length),A.push(o));var h,I=0;l&&(I=l.length/2,p<=256?(h=u.edgeIndices8Bits,d=u.lenEdgeIndices8Bits/2,u.lenEdgeIndices8Bits+=l.length):p<=65536?(h=u.edgeIndices16Bits,d=u.lenEdgeIndices16Bits/2,u.lenEdgeIndices16Bits+=l.length):(h=u.edgeIndices32Bits,d=u.lenEdgeIndices32Bits/2,u.lenEdgeIndices32Bits+=l.length),h.push(l));return this._state.numVertices+=p,gf.numberOfGeometries++,{vertexBase:f,numVertices:p,numTriangles:v,numEdges:I,indicesBase:c,edgeIndicesBase:d,obb:null}}},{key:"_createSubPortion",value:function(e,t,n,r){var i=e.color;e.metallic,e.roughness;var a,s,o=e.colors,l=e.opacity,u=e.meshMatrix,c=e.pickColor,f=this._buffer,p=this._state;f.perObjectPositionsDecodeMatrices.push(e.positionsDecodeMatrix),f.perObjectInstancePositioningMatrices.push(u||Rf),f.perObjectSolid.push(!!e.solid),o?f.perObjectColors.push([255*o[0],255*o[1],255*o[2],255]):i&&f.perObjectColors.push([i[0],i[1],i[2],l]),f.perObjectPickColors.push(c),f.perObjectVertexBases.push(t.vertexBase),a=t.numVertices<=256?p.numIndices8Bits:t.numVertices<=65536?p.numIndices16Bits:p.numIndices32Bits,f.perObjectIndexBaseOffsets.push(a/3-t.indicesBase),s=t.numVertices<=256?p.numEdgeIndices8Bits:t.numVertices<=65536?p.numEdgeIndices16Bits:p.numEdgeIndices32Bits,f.perObjectEdgeIndexBaseOffsets.push(s/2-t.edgeIndicesBase);var A=this._subPortions.length;if(t.numTriangles>0){var d,v=3*t.numTriangles;t.numVertices<=256?(d=f.perTriangleNumberPortionId8Bits,p.numIndices8Bits+=v,gf.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(d=f.perTriangleNumberPortionId16Bits,p.numIndices16Bits+=v,gf.totalPolygons16Bits+=t.numTriangles):(d=f.perTriangleNumberPortionId32Bits,p.numIndices32Bits+=v,gf.totalPolygons32Bits+=t.numTriangles),gf.totalPolygons+=t.numTriangles;for(var h=0;h<t.numTriangles;h+=8)d.push(A)}if(t.numEdges>0){var I,y=2*t.numEdges;t.numVertices<=256?(I=f.perEdgeNumberPortionId8Bits,p.numEdgeIndices8Bits+=y,gf.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(I=f.perEdgeNumberPortionId16Bits,p.numEdgeIndices16Bits+=y,gf.totalEdges16Bits+=t.numEdges):(I=f.perEdgeNumberPortionId32Bits,p.numEdgeIndices32Bits+=y,gf.totalEdges32Bits+=t.numEdges),gf.totalEdges+=t.numEdges;for(var m=0;m<t.numEdges;m+=8)I.push(A)}return this._subPortions.push({numVertices:t.numTriangles}),this._numPortions++,gf.numberOfPortions++,A}},{key:"finalize",value:function(){var e=this;if(!this._finalized){var t=this._state,n=this._dataTextureState,r=this.model.scene.canvas.gl,i=this._buffer;t.gl=r,n.texturePerObjectColorsAndFlags=this._dataTextureGenerator.generateTextureForColorsAndFlags(r,i.perObjectColors,i.perObjectPickColors,i.perObjectVertexBases,i.perObjectIndexBaseOffsets,i.perObjectEdgeIndexBaseOffsets,i.perObjectSolid),n.texturePerObjectInstanceMatrices=this._dataTextureGenerator.generateTextureForInstancingMatrices(r,i.perObjectInstancePositioningMatrices),n.texturePerObjectPositionsDecodeMatrix=this._dataTextureGenerator.generateTextureForPositionsDecodeMatrices(r,i.perObjectPositionsDecodeMatrices),n.texturePerVertexIdCoordinates=this._dataTextureGenerator.generateTextureForPositions(r,i.positionsCompressed,i.lenPositionsCompressed),n.texturePerPolygonIdPortionIds8Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perTriangleNumberPortionId8Bits),n.texturePerPolygonIdPortionIds16Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perTriangleNumberPortionId16Bits),n.texturePerPolygonIdPortionIds32Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perTriangleNumberPortionId32Bits),i.perEdgeNumberPortionId8Bits.length>0&&(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.lenIndices8Bits>0&&(n.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(r,i.indices8Bits,i.lenIndices8Bits)),i.lenIndices16Bits>0&&(n.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(r,i.indices16Bits,i.lenIndices16Bits)),i.lenIndices32Bits>0&&(n.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(r,i.indices32Bits,i.lenIndices32Bits)),i.lenEdgeIndices8Bits>0&&(n.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(r,i.edgeIndices8Bits,i.lenEdgeIndices8Bits)),i.lenEdgeIndices16Bits>0&&(n.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(r,i.edgeIndices16Bits,i.lenEdgeIndices16Bits)),i.lenEdgeIndices32Bits>0&&(n.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(r,i.edgeIndices32Bits,i.lenEdgeIndices32Bits)),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&Me&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&ke&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ge&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&je&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&He&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Ve&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&Fe&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&xe&&(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&Me?(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&ke?(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&Ge?(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&je?(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&Ve?(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&He?(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.texturePerObjectColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectColorsAndFlags._textureWidth,t.texturePerObjectColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectColorsAndFlags._textureData)}}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&xe?(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&Fe?(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<i;r++)this._subPortionSetColor(n[r],t)}},{key:"_subPortionSetColor",value:function(e,t){if(!this._finalized)throw"Not finalized";var n=this._dataTextureState,r=this.model.scene.canvas.gl;if(bf[0]=t[0],bf[1]=t[1],bf[2]=t[2],bf[3]=t[3],n.texturePerObjectColorsAndFlags._textureData.set(bf,32*e),this._deferredSetFlagsActive)return console.info("_subPortionSetColor defer"),void(this._deferredSetFlagsDirty=!0);++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectColorsAndFlags._texture),r.texSubImage2D(r.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,r.RGBA_INTEGER,r.UNSIGNED_BYTE,bf)}},{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;a<s;a++)this._subPortionSetFlags(i[a],t,n,r)}},{key:"_subPortionSetFlags",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=!!(t&Me),o=!!(t&Ge),l=!!(t&ke),u=!!(t&je),c=!!(t&Ve),f=!!(t&Fe),p=!!(t&xe);i=!s||p||o?Xs.NOT_RENDERED:n?Xs.COLOR_TRANSPARENT:Xs.COLOR_OPAQUE,a=!s||p?Xs.NOT_RENDERED:u?Xs.SILHOUETTE_SELECTED:l?Xs.SILHOUETTE_HIGHLIGHTED:o?Xs.SILHOUETTE_XRAYED:Xs.NOT_RENDERED;var A=0;A=!s||p?Xs.NOT_RENDERED:u?Xs.EDGES_SELECTED:l?Xs.EDGES_HIGHLIGHTED:o?Xs.EDGES_XRAYED:c?n?Xs.EDGES_COLOR_TRANSPARENT:Xs.EDGES_COLOR_OPAQUE:Xs.NOT_RENDERED;var d=s&&f?Xs.PICK:Xs.NOT_RENDERED,v=this._dataTextureState,h=this.model.scene.canvas.gl;bf[0]=i,bf[1]=a,bf[2]=A,bf[3]=d,v.texturePerObjectColorsAndFlags._textureData.set(bf,32*e+8),this._deferredSetFlagsActive||r?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),h.bindTexture(h.TEXTURE_2D,v.texturePerObjectColorsAndFlags._texture),h.texSubImage2D(h.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,h.RGBA_INTEGER,h.UNSIGNED_BYTE,bf))}},{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;i<a;i++)this._subPortionSetFlags2(r[i],t,n)}},{key:"_subPortionSetFlags2",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!this._finalized)throw"Not finalized";var r=t&He?255:0,i=this._dataTextureState,a=this.model.scene.canvas.gl;bf[0]=r,bf[1]=0,bf[2]=1,bf[3]=2,i.texturePerObjectColorsAndFlags._textureData.set(bf,32*e+12),this._deferredSetFlagsActive||n?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,bf))}},{key:"_setDeferredFlags2",value:function(){}},{key:"setOffset",value:function(e,t){for(var n=this._portionToSubPortionsMap[e],r=0,i=n.length;r<i;r++)this._subPortionSetOffset(n[r],t)}},{key:"_subPortionSetOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";var n=this._dataTextureState,r=this.model.scene.canvas.gl;Df[0]=t[0],Df[1]=t[1],Df[2]=t[2],n.texturePerObjectOffsets._textureData.set(Df,3*e),this._deferredSetFlagsActive?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectOffsets._texture),r.texSubImage2D(r.TEXTURE_2D,0,0,e,1,1,r.RGB,r.FLOAT,Df))}},{key:"setMatrix",value:function(e,t){for(var n=this._portionToSubPortionsMap[e],r=0,i=n.length;r<i;r++)this._subPortionSetMatrix(n[r],t)}},{key:"_subPortionSetMatrix",value:function(e,t){if(!this._finalized)throw"Not finalized";var n=this._dataTextureState,r=this.model.scene.canvas.gl;Tf.set(t),n.texturePerObjectInstanceMatrices._textureData.set(Tf,16*e),this._deferredSetFlagsActive?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectInstanceMatrices._texture),r.texSubImage2D(r.TEXTURE_2D,0,e%512*4,Math.floor(e/512),4,1,r.RGBA,r.FLOAT,Tf))}},{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,Xs.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.PICK))}},{key:"drawPickDepths",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,Xs.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,Xs.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,Xs.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,Xs.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}(),_f=$.vec4(4),Bf=$.vec4(),Of=$.vec4(),Sf=$.vec3([1,0,0]),Nf=$.vec3([0,1,0]),Lf=$.vec3([0,0,1]);$.vec3(3),$.vec3(3);var Mf=$.identityMat4(),xf=function(){function e(t){b(this,e),this._model=t.model,this.id=t.id,this._parentTransform=t.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=$.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=$.identityMat4(new Float32Array(16)),this._worldMatrix=$.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),t.parent&&t.parent._addChildTransform(this)}return P(e,[{key:"_addChildTransform",value:function(e){this._childTransforms.push(e),e._parentTransform=this,e._setWorldMatrixDirty(),e._setAABBDirty()}},{key:"_addMesh",value:function(e){this._meshes.push(e),e.transform=this}},{key:"parentTransform",get:function(){return this._parentTransform}},{key:"meshes",get:function(){return this._meshes}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.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._model.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._model.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.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||Mf),$.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"rotate",value:function(e,t){return _f[0]=e[0],_f[1]=e[1],_f[2]=e[2],_f[3]=t*$.DEGTORAD,$.angleAxisToQuaternion(_f,Bf),$.mulQuaternions(this.quaternion,Bf,Of),this.quaternion=Of,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return _f[0]=e[0],_f[1]=e[1],_f[2]=e[2],_f[3]=t*$.DEGTORAD,$.angleAxisToQuaternion(_f,Bf),$.mulQuaternions(Bf,this.quaternion,Bf),this}},{key:"rotateX",value:function(e){return this.rotate(Sf,e)}},{key:"rotateY",value:function(e){return this.rotate(Nf,e)}},{key:"rotateZ",value:function(e){return this.rotate(Lf,e)}},{key:"translate",value:function(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateX",value:function(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateY",value:function(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateZ",value:function(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._transformDirty()}},{key:"_transformDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._childTransforms.length;e<t;e++){var n=this._childTransforms[e];if(n._transformDirty(),n._meshes&&n._meshes.length>0)for(var r=n._meshes,i=0,a=r.length;i<a;i++)r[i]._transformDirty()}if(this._meshes&&this._meshes.length>0)for(var s=this._meshes,o=0,l=s.length;o<l;o++)s[o]._transformDirty()}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentTransform)$.mulMat4(this._parentTransform.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_setSubtreeAABBsDirty",value:function(e){if(e._aabbDirty=!0,e._childTransforms)for(var t=0,n=e._childTransforms.length;t<n;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}]),e}(),Ff=$.vec3();$.mat4();var Hf=$.OBB3(),Uf=$.vec3([1,1,1]),Gf=$.vec3([0,0,0]),kf=$.vec3([0,0,0]),jf=$.identityQuaternion(),Vf=$.identityMat4(),Qf=new Uint8Array([255,255,255]),Wf=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))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!1,r._vboBatchingLayerScratchMemory=Ys(),r._textureTranscoder=i.textureTranscoder||Yu(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._transforms={},r._meshes={},r._entities={},r._scheduledMeshes={},r.renderFlags=new Gi,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._meshesWithDirtyMatrices=[],r._numMeshesWithDirtyMatrices=0,r._onTick=r.scene.on("tick",(function(){for(;r._numMeshesWithDirtyMatrices>0;)r._meshesWithDirtyMatrices[--r._numMeshesWithDirtyMatrices]._updateMatrix()})),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:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new Fu({id:"defaultColorTexture",texture:new ba({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Fu({id:"defaultMetalRoughTexture",texture:new ba({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new Fu({id:"defaultNormalsTexture",texture:new ba({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new Fu({id:"defaultEmissiveTexture",texture:new ba({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new Fu({id:"defaultOcclusionTexture",texture:new ba({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 xu({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"transforms",get:function(){return this._transforms}},{key:"textures",get:function(){return this._textures}},{key:"textureSets",get:function(){return this._textureSets}},{key:"meshes",get:function(){return this._meshes}},{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._sceneModelDirty(),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._sceneModelDirty(),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._sceneModelDirty(),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||Vf),$.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._sceneModelDirty(),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,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._sceneModelDirty()}},{key:"worldMatrix",get:function(){return this.matrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrix}},{key:"viewMatrix",get:function(){return this._viewMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&($.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),this._viewMatrix):this.scene.camera.viewMatrix}},{key:"viewNormalMatrix",get:function(){return this._viewNormalMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&($.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}},{key:"backfaces",get:function(){return this._backfaces},set:function(e){e=!!e,this._backfaces=e,this.glRedraw()}},{key:"entityList",get:function(){return this._entityList}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return!1}},{key:"aabb",get:function(){if(this._aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._entityList.length;e<t;e++)$.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"numLines",get:function(){return this._numLines}},{key:"numPoints",get:function(){return this._numPoints}},{key:"visible",get:function(){return this.numVisibleLayerPortions>0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].visible=e;this.glRedraw()}},{key:"xrayed",get:function(){return this.numXRayedLayerPortions>0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].xrayed=e;this.glRedraw()}},{key:"highlighted",get:function(){return this.numHighlightedLayerPortions>0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].highlighted=e;this.glRedraw()}},{key:"selected",get:function(){return this.numSelectedLayerPortions>0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].selected=e;this.glRedraw()}},{key:"edges",get:function(){return this.numEdgesLayerPortions>0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].edges=e;this.glRedraw()}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].culled=e;this.glRedraw()}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].clippable=e;this.glRedraw()}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].collidable=e}},{key:"pickable",get:function(){return this.numPickableLayerPortions>0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].pickable=e}},{key:"colorize",get:function(){return this._colorize},set:function(e){this._colorize=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].colorize=e}},{key:"opacity",get:function(){return this._opacity},set:function(e){this._opacity=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].opacity=e}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}},{key:"saoEnabled",get:function(){return this._saoEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!1}},{key:"xrayMaterial",get:function(){return this.scene.xrayMaterial}},{key:"highlightMaterial",get:function(){return this.scene.highlightMaterial}},{key:"selectedMaterial",get:function(){return this.scene.selectedMaterial}},{key:"edgeMaterial",get:function(){return this.scene.edgeMaterial}},{key:"getPickViewMatrix",value:function(e){return this._viewMatrix?this._viewMatrix:e}},{key:"createQuantizationRange",value:function(e){void 0!==e.id&&null!==e.id?e.aabb?this.error("[createQuantizationRange] Config missing: aabb"):this._quantizationRanges[e.id]?this.error("[createQuantizationRange] QuantizationRange already created: "+e.id):this._quantizationRanges[e.id]={id:e.id,aabb:e.aabb,matrix:No(e.aabb,$.mat4())}:this.error("[createQuantizationRange] Config missing: id")}},{key:"createGeometry",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._geometries[e.id])this.error("[createGeometry] Geometry already created: "+e.id);else 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){if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.positionsDecodeMatrix&&e.positionsDecodeBoundary)return this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')"),null;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error("[createGeometry] Param expected: indices (required for '".concat(e.primitive,"' primitive type)")),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=No(e.positionsDecodeBoundary,$.mat4())),e.positions){var t=$.collapseAABB3();e.positionsDecodeMatrix=$.mat4(),$.expandAABB3Points3(t,e.positions),e.positionsCompressed=So(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){var n=$.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),$.expandAABB3Points3(n,e.positionsCompressed),Dn.decompressAABB(n,e.positionsDecodeMatrix),e.aabb=n}else if(e.buckets){var r=$.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(var i=0,a=e.buckets.length;i<a;i++){var s=e.buckets[i];s.positions?$.expandAABB3Points3(r,s.positions):s.positionsCompressed&&$.expandAABB3Points3(r,s.positionsCompressed)}e.positionsDecodeMatrix&&Dn.decompressAABB(r,e.positionsDecodeMatrix),e.aabb=r}if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var o=e.colors,l=new Uint8Array(o.length),u=0,c=o.length;u<c;u++)l[u]=255*o[u];e.colorsCompressed=l}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=yn(e.positions,e.indices,null,5):e.edgeIndices=yn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){var f=Dn.getUVBounds(e.uv),p=Dn.compressUVs(e.uv,f.min,f.max);e.uvCompressed=p.quantized,e.uvDecodeMatrix=p.decodeMatrix}else e.uvCompressed&&(e.uvCompressed=new Uint16Array(e.uvCompressed),e.uvDecodeMatrix=new Float64Array(e.uvDecodeMatrix));e.normals&&(e.normals=null),this._geometries[e.id]=e,this._numTriangles+=e.indices?Math.round(e.indices.length/3):0,this.numGeometries++}else this.error("[createGeometry] Unsupported value for 'primitive': '".concat(e.primitive,"' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'."));else this.error("[createGeometry] Config missing: id")}},{key:"createTexture",value:function(e){var t=this,n=e.id;if(null!=n)if(this._textures[n])this.error("[createTexture] Texture already created: "+n);else{if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;var r=e.minFilter||1008;1006!==r&&1007!==r&&1008!==r&&1005!==r&&1004!==r&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),r=1008);var i=e.magFilter||1006;1006!==i&&1003!==i&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),i=1006);var a=e.wrapS||1e3;1001!==a&&1002!==a&&1e3!==a&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),a=1e3);var s=e.wrapT||1e3;1001!==s&&1002!==s&&1e3!==s&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),s=1e3);var o=e.wrapR||1e3;1001!==o&&1002!==o&&1e3!==o&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),o=1e3);var l=e.encoding||3e3;3e3!==l&&3001!==l&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),l=3e3);var u=new ba({gl:this.scene.canvas.gl,minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,encoding:l});if(e.preloadColor&&u.setPreloadColor(e.preloadColor),e.image){var c=e.image;c.crossOrigin="Anonymous",u.setImage(c,{minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,flipY:e.flipY,encoding:l})}else if(e.src){var f=e.src.split(".").pop();switch(f){case"jpeg":case"jpg":case"png":case"gif":var p=new Image;p.onload=function(){u.setImage(p,{minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,flipY:e.flipY,encoding:l}),t.glRedraw()},p.src=e.src;break;default:this._textureTranscoder?le.loadArraybuffer(e.src,(function(e){e.byteLength?t._textureTranscoder.transcode([e],u).then((function(){t.glRedraw()})):t.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error("[createTexture] Can't create texture from 'src': ".concat(e))})):this.error("[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('".concat(f,"')"))}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,u).then((function(){t.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[n]=new Fu({id:n,texture:u})}else this.error("[createTexture] Config missing: id")}},{key:"createTextureSet",value:function(e){var t=e.id;if(null!=t){if(!this._textureSets[t]){var n,r,i,a,s;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(!(n=this._textures[e.colorTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.colorTextureId," - ensure that you create it first with createTexture()"))}else n=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(!(r=this._textures[e.metallicRoughnessTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.metallicRoughnessTextureId," - ensure that you create it first with createTexture()"))}else r=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(!(i=this._textures[e.normalsTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(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]))return void this.error("[createTextureSet] Texture not found: ".concat(e.emissiveTextureId," - ensure that you create it first with createTexture()"))}else a=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(!(s=this._textures[e.occlusionTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.occlusionTextureId," - ensure that you create it first with createTexture()"))}else s=this._textures.defaultOcclusionTexture;var o=new xu({id:t,model:this,colorTexture:n,metallicRoughnessTexture:r,normalsTexture:i,emissiveTexture:a,occlusionTexture:s});return this._textureSets[t]=o,o}this.error("[createTextureSet] Texture set already created: ".concat(t))}else this.error("[createTextureSet] Config missing: id")}},{key:"createTransform",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._transforms[e.id])this.error("[createTransform] SceneModel already has a transform with this ID: ".concat(e.id));else{var t;if(!this.parentTransformId||(t=this._transforms[e.parentTransformId])){var n=new xf({id:e.id,model:this,parentTransform:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[n.id]=n,n}this.error("[createTransform] SceneModel.createTransform() config missing: id")}else this.error("[createTransform] SceneModel.createTransform() config missing: id")}},{key:"createMesh",value:function(e){if(void 0!==e.id&&null!==e.id){if(!this._scheduledMeshes[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': '".concat(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 '".concat(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;var t=!!this._dtxEnabled&&("triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive);if(e.origin=e.origin?$.addVec3(this._origin,e.origin,$.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){var n=e.scale||Uf,r=e.position||Gf,i=e.rotation||kf;$.eulerToQuaternion(i,"XYZ",jf),e.meshMatrix=$.composeMat4(r,jf,n,$.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=No(e.positionsDecodeBoundary,$.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])]):Qf,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){var a=$.vec3(),s=[];Se(e.positions,s,a)&&(e.positions=s,e.origin=$.addVec3(e.origin,a,a))}if(e.positions){var o=$.collapseAABB3();e.positionsDecodeMatrix=$.mat4(),$.expandAABB3Points3(o,e.positions),e.positionsCompressed=So(e.positions,o,e.positionsDecodeMatrix),e.aabb=o}else if(e.positionsCompressed){var l=$.collapseAABB3();$.expandAABB3Points3(l,e.positionsCompressed),Dn.decompressAABB(l,e.positionsDecodeMatrix),e.aabb=l}if(e.buckets){for(var u=$.collapseAABB3(),c=0,f=e.buckets.length;c<f;c++){var p=e.buckets[c];p.positions?$.expandAABB3Points3(u,p.positions):p.positionsCompressed&&$.expandAABB3Points3(u,p.positionsCompressed)}e.positionsDecodeMatrix&&Dn.decompressAABB(u,e.positionsDecodeMatrix),e.aabb=u}e.meshMatrix&&($.AABB3ToOBB3(e.aabb,Hf),$.transformOBB3(e.meshMatrix,Hf),$.OBB3ToAABB3(Hf,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=yn(e.positions,e.indices,null,2):e.edgeIndices=yn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=zf(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){var A=[];Se(e.positions,A,Ff)&&(e.positions=A,e.origin=$.addVec3(e.origin,Ff,$.vec3()))}if(e.positions){var d=$.collapseAABB3();e.meshMatrix&&($.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),$.expandAABB3Points3(d,e.positions),e.aabb=d}else{var v=$.collapseAABB3();$.expandAABB3Points3(v,e.positionsCompressed),Dn.decompressAABB(v,e.positionsDecodeMatrix),e.aabb=v}if(e.meshMatrix&&($.AABB3ToOBB3(e.aabb,Hf),$.transformOBB3(e.meshMatrix,Hf),$.OBB3ToAABB3(Hf,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=yn(e.positions,e.indices,null,2):e.edgeIndices=yn(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: ".concat(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: ".concat(e.geometryId," - ensure that you create it first with createGeometry()"));if(e.origin=e.origin?$.addVec3(this._origin,e.origin,$.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.transformId){if(e.transform=this._transforms[e.transformId],!e.transform)return void this.error("[createMesh] Transform not found: ".concat(e.transformId," - ensure that you create it first with createTransform()"));e.aabb=e.geometry.aabb}else{if(e.matrix)e.meshMatrix=e.matrix.slice();else{var h=e.scale||Uf,I=e.position||Gf,y=e.rotation||kf;$.eulerToQuaternion(y,"XYZ",jf),e.meshMatrix=$.composeMat4(I,jf,h,$.mat4())}$.AABB3ToOBB3(e.geometry.aabb,Hf),$.transformOBB3(e.meshMatrix,Hf),e.aabb=$.OBB3ToAABB3(Hf,$.AABB3())}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])]):Qf,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;var m=this._dtxBuckets[e.geometryId];m||(m=zf(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=m),e.buckets=m}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])]):Qf,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])}return e.numPrimitives=this._getNumPrimitives(e),this._createMesh(e)}this.error("[createMesh] SceneModel already has a mesh with this ID: ".concat(e.id))}else this.error("[createMesh] SceneModel.createMesh() config missing: id")}},{key:"_createMesh",value:function(e){var t=new Ws(this,e.id,e.color,e.opacity,e.transform,e.textureSet);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.solid="solid"===e.primitive,t.origin=$.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(e),this._meshes[e.id]=t,this._meshList.push(t),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<r;n++)t+=e.buckets[n].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/3);case"points":switch(e.type){case 2:for(var i=0,a=e.buckets.length;i<a;i++)t+=e.buckets[i].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:var s=e.geometry;t+=s.positions?s.positions.length:s.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(var o=0,l=e.buckets.length;o<l;o++)t+=e.buckets[o].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}},{key:"_getDTXLayer",value:function(e){var t=e.origin,n="".concat(Math.round(t[0]),".").concat(Math.round(t[1]),".").concat(Math.round(t[2])),r=this._dtxLayers[n];if(r){if(r.canCreatePortion(e))return r;r.finalize(),delete this._dtxLayers[n],r=null}return r=new Cf(this,{layerIndex:0,origin:t}),this._dtxLayers[n]=r,this.layerList.push(r),r}},{key:"_getVBOBatchingLayer",value:function(e){var t=this,n=e.origin,r=e.positionsDecodeMatrix||e.positionsDecodeBoundary?this._createHashStringFromMatrix(e.positionsDecodeMatrix||e.positionsDecodeBoundary):"-",i=e.textureSetId||"-",a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(e.primitive,".").concat(r,".").concat(i),s=this._vboBatchingLayers[a];if(s)return s;for(var o=e.textureSet;!s;){switch(e.primitive){case"triangles":case"solid":case"surface":s=new sl({model:t,textureSet:o,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize,solid:"solid"===e.primitive,autoNormals:!0});break;case"lines":s=new ru({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":s=new gu({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize})}var l=e.positionsCompressed?e.positionsCompressed.length:e.positions.length;("points"===e.primitive?s.canCreatePortion(l):s.canCreatePortion(l,e.indices.length))||(s.finalize(),delete this._vboBatchingLayers[a],s=null)}return this._vboBatchingLayers[a]=s,this.layerList.push(s),s}},{key:"_createHashStringFromMatrix",value:function(e){for(var t=e.join(""),n=0,r=0;r<t.length;r++){n=(n<<5)-n+t.charCodeAt(r),n|=0}return(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":s=new Jl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":s=new Jl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":s=new pu({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":s=new Mu({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;this._visible&&!1!==e.visible&&(t|=Me),this._pickable&&!1!==e.pickable&&(t|=Fe),this._culled&&!1!==e.culled&&(t|=xe),this._clippable&&!1!==e.clippable&&(t|=He),this._collidable&&!1!==e.collidable&&(t|=Ue),this._edges&&!1!==e.edges&&(t|=Ve),this._xrayed&&!1!==e.xrayed&&(t|=Ge),this._highlighted&&!1!==e.highlighted&&(t|=ke),this._selected&&!1!==e.selected&&(t|=je),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],n=0,r=e.meshIds.length;n<r;n++){var i=e.meshIds[n],a=this._meshes[i];a?a.parent?this.error('Mesh with ID "'.concat(i,'" already belongs to object with ID "').concat(a.parent.id,'" - ignoring this mesh')):t.push(a):this.error('Mesh with this ID not found: "'.concat(i,'" - ignoring this mesh'))}var s=new ze(this,e.isObject,e.id,t,e.flags,!0);this._entityList.push(s),this._entities[e.id]=s,this.numEntities++}},{key:"finalize",value:function(){if(!this.destroyed){for(var e=0,t=this.layerList.length;e<t;e++){this.layerList[e].finalize()}this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._dtxLayers={},this._vboInstancingLayers={},this._vboBatchingLayers={};for(var n=0,r=this._entityList.length;n<r;n++){this._entityList[n]._finalize()}for(var i=0,a=this._entityList.length;i<a;i++){this._entityList[i]._finalize2()}this.layerList.sort((function(e,t){return e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0}));for(var s=0,o=this.layerList.length;s<o;s++){this.layerList[s].layerIndex=s}this.glRedraw(),this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position}}},{key:"stateSortCompare",value:function(e,t){}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&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;t<n;t++){var r=this.layerList[t];this._getActiveSectionPlanesForLayer(r)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,n=this.scene._sectionPlanesState.sectionPlanes,r=n.length,i=e.layerIndex*r;if(r>0)for(var a=0;a<r;a++){n[a].active?(t.sectionPlanesActivePerLayer[i+a]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[i+a]=!1}return!0}},{key:"_updateRenderFlags",value:function(){if(0!==this.numVisibleLayerPortions&&this.numCulledLayerPortions!==this.numPortions){var e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(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.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(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;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawColorOpaque(t,e)}}},{key:"drawColorTransparent",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawColorTransparent(t,e)}}},{key:"drawDepth",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawDepth(t,e)}}},{key:"drawNormals",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawNormals(t,e)}}},{key:"drawSilhouetteXRayed",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteXRayed(t,e)}}},{key:"drawSilhouetteHighlighted",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteHighlighted(t,e)}}},{key:"drawSilhouetteSelected",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteSelected(t,e)}}},{key:"drawEdgesColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesColorOpaque(t,e)}}},{key:"drawEdgesColorTransparent",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesColorTransparent(t,e)}}},{key:"drawEdgesXRayed",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesXRayed(t,e)}}},{key:"drawEdgesHighlighted",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesHighlighted(t,e)}}},{key:"drawEdgesSelected",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesSelected(t,e)}}},{key:"drawOcclusion",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawOcclusion(t,e)}}},{key:"drawShadow",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawShadow(t,e)}}},{key:"setPickMatrices",value:function(e,t){if(0!==this._numVisibleLayerPortions)for(var n=this.renderFlags,r=0,i=n.visibleLayers.length;r<i;r++){var a=n.visibleLayers[r],s=this.layerList[a];s.setPickMatrices&&s.setPickMatrices(e,t)}}},{key:"drawPickMesh",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickMesh(t,e)}}},{key:"drawPickDepths",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickDepths(t,e)}}},{key:"drawPickNormals",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickNormals(t,e)}}},{key:"drawSnapInitDepthBuf",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n],a=this.layerList[i];a.drawSnapInitDepthBuf&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,a.drawSnapInitDepthBuf(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}},{key:"drawSnapDepths",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n],a=this.layerList[i];a.drawSnapDepths&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,a.drawSnapDepths(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}},{key:"destroy",value:function(){for(var e in this._vboBatchingLayers)this._vboBatchingLayers.hasOwnProperty(e)&&this._vboBatchingLayers[e].destroy();for(var t in this._vboBatchingLayers={},this._vboInstancingLayers)this._vboInstancingLayers.hasOwnProperty(t)&&this._vboInstancingLayers[t].destroy();this._vboInstancingLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(var r=0,i=this.layerList.length;r<i;r++)this.layerList[r].destroy();this.layerList=[];for(var a=0,s=this._entityList.length;a<s;a++)this._entityList[a]._destroy();this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),0!==Ks&&0==--Ks&&zs._clear(),v(E(n.prototype),"destroy",this).call(this)}}]),n}();function zf(e,t,n){var r,i,a,s;if(t||n){var o=p(Zu({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}),3);r=o[0],i=o[1],a=o[2]}else r=e.positionsCompressed,i=e.indices,a=e.edgeIndices;n?s=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=tc(e.indices||[],t),a=ic(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<<t))return[e];var u=new Int32Array(l);u.fill(-1);var c=[];function f(){u.fill(-1);var e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:c.length};return c.push(e),e}for(var p=f(),A=0,d=i.length;A<d;A+=3){var v=0,h=i[A],I=i[A+1],y=i[A+2];if(-1===u[h]&&v++,-1===u[I]&&v++,-1===u[y]&&v++,v+p.numPositions>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,E=2*r.length+(i.length+a.length)*w,T=0;return r.length,c.forEach((function(e){T+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),T>E?[e]:(n&&ac(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 Kf=function(e){I(n,Wf);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)}(),Yf=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))._skyboxMesh=new Ji(g(r),{geometry:new Cn(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 Nn(g(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Ba(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}(),Xf=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),qf=$.vec4(),Jf=$.vec4(),Zf=$.vec3(),$f=$.vec3(),ep=$.vec3(),tp=$.vec4(),np=$.vec4(),rp=$.vec4(),ip=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"dollyToCanvasPos",value:function(e,t,n){var r=!1,i=this._scene.camera;if(e){var a=$.subVec3(e,i.eye,Zf);r=$.lenVec3(a)<n}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-n;var s=this._unproject(t,tp),o=$.subVec3(s,i.eye,rp),l=$.mulVec3Scalar($.normalizeVec3(o),-n,[]);if(i.eye=[i.eye[0]-l[0],i.eye[1]-l[1],i.eye[2]-l[2]],i.look=[i.look[0]-l[0],i.look[1]-l[1],i.look[2]-l[2]],e){var u=$.subVec3(e,i.eye,Zf),c=$.lenVec3(u),f=$.mulVec3Scalar($.normalizeVec3($.subVec3(i.look,i.eye,$f)),c);i.look=[i.eye[0]+f[0],i.eye[1]+f[1],i.eye[2]+f[2]]}}else if("ortho"===i.projection){var p=this._unproject(t,tp);i.ortho.scale=i.ortho.scale-n,i.ortho._update();var A=this._unproject(t,np),d=$.subVec3(A,p,rp),v=$.mulVec3Scalar($.normalizeVec3($.subVec3(i.look,i.eye,Zf)),-n,$f),h=$.addVec3(d,v,ep);i.eye=[i.eye[0]-h[0],i.eye[1]-h[1],i.eye[2]-h[2]],i.look=[i.look[0]-h[0],i.look[1]-h[1],i.look[2]-h[2]]}return r}},{key:"_unproject",value:function(e,t){var n=this._scene.camera,r=n.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a);return n.project.unproject(e,o,qf,Jf,t),t}},{key:"destroy",value:function(){}}]),e}(),ap=$.vec3(),sp=$.vec3(),op=$.vec3(),lp=$.vec4(),up=$.vec4(),cp=$.vec4(),fp=function(){function e(t,n){var r=this;b(this,e),this._scene=t,this._configs=n,this._pivotWorldPos=$.vec3(),this._cameraOffset=$.vec3(),this._azimuth=0,this._polar=0,this._radius=0,this._pivotPosSet=!1,this._pivoting=!1,this._shown=!1,this._pivotSphereEnabled=!1,this._pivotSphere=null,this._pivotSphereSize=1,this._pivotSphereGeometry=null,this._pivotSphereMaterial=null,this._rtcCenter=$.vec3(),this._rtcPos=$.vec3(),this._pivotViewPos=$.vec4(),this._pivotProjPos=$.vec4(),this._pivotCanvasPos=$.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(function(){r._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(function(){r._cameraDirty=!0})),this._onTick=this._scene.on("tick",(function(){r.updatePivotElement(),r.updatePivotSphere()}))}return P(e,[{key:"createPivotSphere",value:function(){var e=this.getPivotPos(),t=$.vec3();$.decomposeMat4($.inverseMat4(this._scene.viewer.camera.viewMatrix,$.mat4()),t,$.vec4(),$.vec3());var n=$.distVec3(t,e),r=Math.tan(Math.PI/500)*n*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(r/=this._scene.camera.ortho.scale/2),Oe(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new La(this._scene,ea({radius:r})),this._pivotSphere=new Ji(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}},{key:"destroyPivotSphere",value:function(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}},{key:"updatePivotElement",value:function(){var e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){$.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,$.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);var n=t.boundary,r=n[2],i=n[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*r/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);var a=t._lastBoundingClientRect;if(!a||t._canvasSizeChanged){var s=t.canvas;a=t._lastBoundingClientRect=s.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}}},{key:"updatePivotSphere",value:function(){this._pivoting&&this._pivotSphere&&(Oe(this.getPivotPos(),this._rtcCenter,this._rtcPos),$.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}},{key:"setPivotElement",value:function(e){this._pivotElement=e}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&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 Nn(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,ap)),n=$.cross3Vec3(t,e.worldUp,sp);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=lp;t.project.unproject(e,o,up,cp,l);var u=$.normalizeVec3($.subVec3(l,t.eye,ap)),c=$.addVec3(t.eye,$.mulVec3Scalar(u,n,sp),op);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}(),pp=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._lastHash=null,this._needFireEvents=0}return P(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var n=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});n&&(n.snappedToEdge||n.snappedToVertex)?(this.snapPickResult=n,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var r=this.pickResult.canvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,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 i=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(i[0]===this.pickCursorPos[0]&&i[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!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++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}}},{key:"fireEvents",value:function(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new It;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=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=0}}}]),e}(),Ap=$.vec2(),dp=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,Ap);var t=Ap[0],i=Ap[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:Ap,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var E=1/60,T=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==T?t-T:0;T=t,n>.05&&(n=.05),n<E&&(n=E);var s=Math.max(-1,Math.min(1,40*-e.deltaY));if(0!==s){var o=s/Math.abs(s);a.dollyDelta+=-o*n*r.mouseWheelDollyRate,h&&(i.followPointerDirty=!0,h=!1)}}},{passive:!0})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler),document.removeEventListener("keyup",this._documentKeyUpHandler),e.removeEventListener("mousedown",this._mouseDownHandler),document.removeEventListener("mousemove",this._documentMouseMoveHandler),e.removeEventListener("mousemove",this._canvasMouseMoveHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("wheel",this._mouseWheelHandler)}}]),e}(),vp=$.vec3(),hp=$.vec3(),Ip=$.vec3(),yp=$.vec3(),mp=$.vec3(),wp={eye:$.vec3(),look:$.vec3(),up:$.vec3()},gp=function(){function e(t,n,r,i){b(this,e),this._scene=t;var a=n.cameraControl,s=t.camera;this._onSceneKeyDown=t.input.on("keydown",(function(){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var e=a._isKeyDownForAction(a.AXIS_VIEW_RIGHT),o=a._isKeyDownForAction(a.AXIS_VIEW_BACK),l=a._isKeyDownForAction(a.AXIS_VIEW_LEFT),u=a._isKeyDownForAction(a.AXIS_VIEW_FRONT),c=a._isKeyDownForAction(a.AXIS_VIEW_TOP),f=a._isKeyDownForAction(a.AXIS_VIEW_BOTTOM);if(e||o||l||u||c||f){var p=t.aabb,A=$.getAABB3Diag(p);$.getAABB3Center(p,vp);var d=Math.abs(A/Math.tan(n.cameraFlight.fitFOV*$.DEGTORAD)),v=1.1*A;wp.orthoScale=v,e?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldRight,d,hp),mp)),wp.look.set(vp),wp.up.set(s.worldUp)):o?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldForward,d,hp),mp)),wp.look.set(vp),wp.up.set(s.worldUp)):l?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldRight,-d,hp),mp)),wp.look.set(vp),wp.up.set(s.worldUp)):u?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldForward,-d,hp),mp)),wp.look.set(vp),wp.up.set(s.worldUp)):c?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldUp,d,hp),mp)),wp.look.set(vp),wp.up.set($.normalizeVec3($.mulVec3Scalar(s.worldForward,1,Ip),yp))):f&&(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldUp,-d,hp),mp)),wp.look.set(vp),wp.up.set($.normalizeVec3($.mulVec3Scalar(s.worldForward,-1,Ip)))),!r.firstPerson&&r.followPointer&&n.pivotController.setPivotPos(vp),n.cameraFlight.duration>0?n.cameraFlight.flyTo(wp,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(wp),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}(),Ep=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})},d=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverEnter"),l=u.hasSubs("hoverOut"),p=u.hasSubs("hoverOff"),A=u.hasSubs("hoverSurface"),d=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A||d)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=A,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){var v=o.pickResult.entity.id;s._lastPickedEntityId!==v&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=v)}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("mousemove",d),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}(),Tp=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),E=l._isKeyDownForAction(l.PAN_RIGHT,o),T=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||E||T||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:T&&(a.panDeltaY+=-D),E?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}(),bp=$.vec3(),Dp=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,bp)));f=n/r.dollyProximityThreshold}f<r.dollyMinSpeed&&(f=r.dollyMinSpeed)}var A=a.dollyDelta*f;if(0===a.rotateDeltaY&&0===a.rotateDeltaX||(!r.firstPerson&&r.followPointer&&l.getPivoting()?(l.continuePivot(a.rotateDeltaY,a.rotateDeltaX),l.showPivot()):(0!==a.rotateDeltaX&&(r.firstPerson?s.pitch(-a.rotateDeltaX):s.orbitPitch(a.rotateDeltaX)),0!==a.rotateDeltaY&&(r.firstPerson?s.yaw(a.rotateDeltaY):s.orbitYaw(a.rotateDeltaY))),a.rotateDeltaX*=r.rotationInertia,a.rotateDeltaY*=r.rotationInertia,e="grabbing"),Math.abs(a.panDeltaX)<.001&&(a.panDeltaX=0),Math.abs(a.panDeltaY)<.001&&(a.panDeltaY=0),Math.abs(a.panDeltaZ)<.001&&(a.panDeltaZ=0),0!==a.panDeltaX||0!==a.panDeltaY||0!==a.panDeltaZ){var d,v,h=$.vec3();if(h[0]=a.panDeltaX,h[1]=a.panDeltaY,h[2]=a.panDeltaZ,r.constrainVertical){s.xUp?(d=s.eye[0],v=s.look[0]):s.yUp?(d=s.eye[1],v=s.look[1]):s.zUp&&(d=s.eye[2],v=s.look[2]),s.pan(h);var I=s.eye,y=s.look;s.xUp?(I[0]=d,y[0]=v):s.yUp?(I[1]=d,y[1]=v):s.zUp&&(I[2]=d,y[2]=v),s.eye=I,s.look=y}else s.pan(h);e="grabbing"}if(a.panDeltaX*=r.panInertia,a.panDeltaY*=r.panInertia,a.panDeltaZ*=r.panInertia,0!==A){if(e=A<0?"zoom-in":"zoom-out",r.firstPerson){var m,w;if(r.constrainVertical&&(s.xUp?(m=s.eye[0],w=s.look[0]):s.yUp?(m=s.eye[1],w=s.look[1]):s.zUp&&(m=s.eye[2],w=s.look[2])),r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.pan([0,0,A]),s.ortho.scale=s.ortho.scale-A;if(r.constrainVertical){var g=s.eye,E=s.look;s.xUp?(g[0]=m,E[0]=w):s.yUp?(g[1]=m,E[1]=w):s.zUp&&(g[2]=m,E[2]=w),s.eye=g,s.look=E}}else if(r.planView){if(r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.ortho.scale=s.ortho.scale+A,s.zoom(A)}else{if(r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.ortho.scale=s.ortho.scale+A,s.zoom(A)}a.dollyDelta*=r.dollyInertia}o.fireEvents(),document.body.style.cursor=e}}))}return P(e,[{key:"destroy",value:function(){this._scene.off(this._onTick)}}]),e}(),Pp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=this._scene.canvas.canvas;s.addEventListener("mouseenter",this._mouseEnterHandler=function(){i.mouseover=!0}),s.addEventListener("mouseleave",this._mouseLeaveHandler=function(){i.mouseover=!1,s.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=function(e){Rp(e,s,i.pointerCanvasPos)}),s.addEventListener("mousedown",this._mouseDownHandler=function(e){r.active&&r.pointerEnabled&&(Rp(e,s,i.pointerCanvasPos),i.mouseover=!0)}),s.addEventListener("mouseup",this._mouseUpHandler=function(e){r.active&&r.pointerEnabled})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var 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)}}]),e}();function Rp(e,t,n){if(e){var r=t.getBoundingClientRect(),i=r.x,a=r.y;n[0]=e.clientX-i,n[1]=e.clientY-a}else e=window.event,n[0]=e.x,n[1]=e.y;return n}var Cp=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},_p=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=n.pickController,o=n.pivotController,l=$.vec2(),u=$.vec2(),c=$.vec2(),f=$.vec2(),p=[],A=this._scene.canvas.canvas,d=0,v=!1;this._onTick=t.on("tick",(function(){v=!1})),A.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){e.preventDefault();var n=e.touches,a=e.changedTouches;for(i.touchStartTime=Date.now(),1===n.length&&1===a.length&&(Cp(n[0],l),r.followPointer&&(s.pickCursorPos=l,s.schedulePickSurface=!0,s.update(),r.planView||(s.picked&&s.pickedSurface&&s.pickResult&&s.pickResult.worldPos?(o.setPivotPos(s.pickResult.worldPos),!r.firstPerson&&o.startPivot()&&o.showPivot()):(r.smartPivot?o.setCanvasPivotPos(i.pointerCanvasPos):o.setPivotPos(t.camera.look),!r.firstPerson&&o.startPivot()&&o.showPivot()))));p.length<n.length;)p.push($.vec2());for(var u=0,c=n.length;u<c;++u)Cp(n[u],p[u]);d=n.length}}),A.addEventListener("touchend",this._canvasTouchEndHandler=function(){o.getPivoting()&&o.endPivot()}),A.addEventListener("touchmove",this._canvasTouchMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(e.stopPropagation(),e.preventDefault(),!v)){v=!0;var n=t.canvas.boundary,o=n[2],l=n[3],A=e.touches;if(e.touches.length===d){if(1===d){Cp(A[0],u),$.subVec2(u,p[0],f);var h=f[0],I=f[1];if(null!==i.longTouchTimeout&&(Math.abs(h)>r.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];Cp(w,u),Cp(g,c);var E=$.geometricMeanVec2(p[0],p[1]),T=$.geometricMeanVec2(u,c),b=$.vec2();$.subVec2(E,T,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=T}for(var S=0;S<d;++S)Cp(A[S],p[S])}}})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler),e.removeEventListener("touchmove",this._canvasTouchMoveHandler),this._scene.off(this._onTick)}}]),e}(),Bp=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},Op=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o=n.pickController,l=n.cameraControl,u=[],c=new Float32Array(2),f=-1,p=-1,A=this._scene.canvas.canvas,d=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e?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})};A.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null);var t=e.touches,a=e.changedTouches;if(s=Date.now(),1===t.length&&1===a.length){f=s,Bp(t[0],c);var o=c[0],l=c[1],p=t[0].pageX,A=t[0].pageY;i.longTouchTimeout=setTimeout((function(){n.cameraControl.fire("rightClick",{pagePos:[Math.round(p),Math.round(A)],canvasPos:[Math.round(o),Math.round(l)],event:e},!0),i.longTouchTimeout=null}),r.longTapTimeout)}else f=-1;for(;u.length<t.length;)u.push(new Float32Array(2));for(var d=0,v=t.length;d<v;++d)Bp(t[d],u[d]);u.length=t.length}},{passive:!0}),A.addEventListener("touchend",this._canvasTouchEndHandler=function(e){if(r.active&&r.pointerEnabled){var t=Date.now(),n=e.touches,a=e.changedTouches,s=l.hasSubs("pickedSurface");null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),0===n.length&&1===a.length&&f>-1&&t-f<150&&(p>-1&&f-p<325?(Bp(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&&(Bp(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;A<v;++A)u[A][0]=n[A].pageX,u[A][1]=n[A].pageY}},{passive:!0})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}]),e}(),Sp=function(e){I(n,ye);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)).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 pp(g(r),r._configs),pivotController:new fp(a,r._configs),panController:new ip(a),cameraFlight:new ws(g(r),{duration:.5})},r._handlers=[new Pp(r.scene,r._controllers,r._configs,r._states,r._updates),new _p(r.scene,r._controllers,r._configs,r._states,r._updates),new dp(r.scene,r._controllers,r._configs,r._states,r._updates),new gp(r.scene,r._controllers,r._configs,r._states,r._updates),new Ep(r.scene,r._controllers,r._configs,r._states,r._updates),new Op(r.scene,r._controllers,r._configs,r._states,r._updates),new Tp(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new Dp(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",le.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;r<i;r++){if(t[n[r]])return!0}return!1}},{key:"pivotElement",set:function(e){this._controllers.pivotController.setPivotElement(e)}},{key:"active",get:function(){return this._configs.active},set:function(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}},{key:"snapToVertex",get:function(){return this._configs.snapToVertex},set:function(e){this._configs.snapToVertex=!!e}},{key:"snapToEdge",get:function(){return this._configs.snapToEdge},set:function(e){this._configs.snapToEdge=!!e}},{key:"snapRadius",get:function(){return this._configs.snapRadius},set:function(e){e=e||30,this._configs.snapRadius=e}},{key:"navMode",get:function(){return this._configs.navMode},set:function(e){"firstPerson"!==(e=e||"orbit")&&"orbit"!==e&&"planView"!==e&&(this.error("Unsupported value for navMode: "+e+" - supported values are 'orbit', 'firstPerson' and 'planView' - defaulting to 'orbit'"),e="orbit"),this._configs.firstPerson="firstPerson"===e,this._configs.planView="planView"===e,(this._configs.firstPerson||this._configs.planView)&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this._configs.navMode=e}},{key:"pointerEnabled",get:function(){return this._configs.pointerEnabled},set:function(e){this._reset(),this._configs.pointerEnabled=!!e}},{key:"_reset",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.reset&&n.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}},{key:"followPointer",get:function(){return this._configs.followPointer},set:function(e){this._configs.followPointer=!1!==e}},{key:"pivotPos",get:function(){return this._controllers.pivotController.getPivotPos()},set:function(e){this._controllers.pivotController.setPivotPos(e)}},{key:"dollyToPointer",get:function(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer},set:function(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}},{key:"panToPointer",get:function(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1},set:function(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}},{key:"planView",get:function(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView},set:function(e){this._configs.planView=!!e,this._configs.firstPerson=!1,this._configs.planView&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this.warn("planView property is deprecated - replaced with navMode")}},{key:"firstPerson",get:function(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson},set:function(e){this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson=!!e,this._configs.planView=!1,this._configs.firstPerson&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot())}},{key:"constrainVertical",get:function(){return this._configs.constrainVertical},set:function(e){this._configs.constrainVertical=!!e}},{key:"doublePickFlyTo",get:function(){return this._configs.doublePickFlyTo},set:function(e){this._configs.doublePickFlyTo=!1!==e}},{key:"panRightClick",get:function(){return this._configs.panRightClick},set:function(e){this._configs.panRightClick=!1!==e}},{key:"rotationInertia",get:function(){return this._configs.rotationInertia},set:function(e){this._configs.rotationInertia=null!=e?e:0}},{key:"keyboardPanRate",get:function(){return this._configs.keyboardPanRate},set:function(e){this._configs.keyboardPanRate=null!=e?e:5}},{key:"touchPanRate",get:function(){return this._configs.touchPanRate},set:function(e){this._configs.touchPanRate=null!=e?e:1}},{key:"keyboardRotationRate",get:function(){return this._configs.keyboardRotationRate},set:function(e){this._configs.keyboardRotationRate=null!=e?e:90}},{key:"dragRotationRate",get:function(){return this._configs.dragRotationRate},set:function(e){this._configs.dragRotationRate=null!=e?e:360}},{key:"keyboardDollyRate",get:function(){return this._configs.keyboardDollyRate},set:function(e){this._configs.keyboardDollyRate=null!=e?e:15}},{key:"touchDollyRate",get:function(){return this._configs.touchDollyRate},set:function(e){this._configs.touchDollyRate=null!=e?e:.2}},{key:"mouseWheelDollyRate",get:function(){return this._configs.mouseWheelDollyRate},set:function(e){this._configs.mouseWheelDollyRate=null!=e?e:100}},{key:"dollyInertia",get:function(){return this._configs.dollyInertia},set:function(e){this._configs.dollyInertia=null!=e?e:0}},{key:"dollyProximityThreshold",get:function(){return this._configs.dollyProximityThreshold},set:function(e){this._configs.dollyProximityThreshold=null!=e?e:35}},{key:"dollyMinSpeed",get:function(){return this._configs.dollyMinSpeed},set:function(e){this._configs.dollyMinSpeed=null!=e?e:.04}},{key:"panInertia",get:function(){return this._configs.panInertia},set:function(e){this._configs.panInertia=null!=e?e:.5}},{key:"keyboardLayout",get:function(){return this._configs.keyboardLayout},set:function(e){"qwerty"!==(e=e||"qwerty")&&"azerty"!==e&&(this.error("Unsupported value for keyboardLayout - defaulting to 'qwerty'"),e="qwerty"),this._configs.keyboardLayout=e,this.keyMap=this._configs.keyboardLayout}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&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(E(n.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.destroy&&n.destroy()}}},{key:"_destroyControllers",value:function(){for(var e=0,t=this._controllers.length;e<t;e++){var n=this._controllers[e];n.destroy&&n.destroy()}}}]),n}(),Np=P((function e(t,n,r,i,a){b(this,e),this.name=t,this.type=r,this.value=n,this.valueType=i,this.description=a})),Lp=P((function e(t){if(b(this,e),this.id=t.id,this.originalSystemId=t.originalSystemId,this.metaModels=[],this.name=t.name,this.type=t.type,this.properties=[],t.properties)for(var n=t.properties,r=0,i=n.length;r<i;r++){var a=n[r];this.properties.push(new Np(a.name,a.value,a.type,a.valueType,a.description))}})),Mp=function(){function e(t){b(this,e),this.metaModels=[],this.id=t.id,this.parentId=t.parentId,this.parent=null,this.originalSystemId=t.originalSystemId,this.name=t.name,this.type=t.type,this.propertySetIds=t.propertySetIds,this.propertySets=[],this.attributes=t.attributes||{},void 0!==t.external&&null!==t.external&&(this.external=t.external)}return P(e,[{key:"metaModel",get:function(){return 1==this.metaModels.length?this.metaModels[0]:null}},{key:"getObjectIDsInSubtree",value:function(){var e=[];return function t(n){if(n){e.push(n.id);var r=n.children;if(r)for(var i=0,a=r.length;i<a;i++)t(r[i])}}(this),e}},{key:"withMetaObjectsInSubtree",value:function(e){!function t(n){if(n){e(n);var r=n.children;if(r)for(var i=0,a=r.length;i<a;i++)t(r[i])}}(this)}},{key:"getObjectIDsInSubtreeByType",value:function(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=e[n];var i=[];return function e(n){if(n){t[n.type]&&i.push(n.id);var r=n.children;if(r)for(var a=0,s=r.length;a<s;a++)e(r[a])}}(this),i}},{key:"getJSON",value:function(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}]),e}(),xp=function(){function e(t){b(this,e),this.id=t.id,this.projectId=t.projectId,this.revisionId=t.revisionId,this.author=t.author,this.createdAt=t.createdAt,this.creatingApplication=t.creatingApplication,this.schema=t.schema,this.metaScene=t.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects=[],this.graph=t.graph||{},this.metaScene.metaModels[this.id]=this,this.finalized=!1}return P(e,[{key:"rootMetaObject",get:function(){return 1==this.rootMetaObjects.length?this.rootMetaObjects[0]:null}},{key:"loadData",value:function(e){var t=arguments.length>1&&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,r=e.properties;if(e.propertySets)for(var i=0,a=e.propertySets.length;i<a;i++){var s=e.propertySets[i],o=n.propertySets[s.id];o||(r&&this._decompressProperties(r,s.properties),o=new Lp({id:s.id,originalSystemId:s.originalSystemId||s.id,type:s.type,name:s.name,properties:s.properties}),n.propertySets[o.id]=o),o.metaModels.push(this),this.propertySets.push(o)}if(e.metaObjects)for(var l=0,u=e.metaObjects.length;l<u;l++){var c=e.metaObjects[l],f=c.id,p=n.metaObjects[f];if(!p){var A=c.type,d=c.originalSystemId,v=c.propertySets||c.propertySetIds;p=new Mp({id:f,originalSystemId:d,parentId:c.parent,type:A,name:c.name,attributes:c.attributes,propertySetIds:v,external:c.external}),this.metaScene.metaObjects[f]=p}p.metaModels.push(this),c.parent||(this.rootMetaObjects.push(p),n.rootMetaObjects[f]=p),this.metaObjects.push(p)}}},{key:"_decompressProperties",value:function(e,t){for(var n=0,r=t.length;n<r;n++){var i=t[n];if(Number.isInteger(i)){var a=e[i];a&&(t[n]=a)}}}},{key:"finalize",value:function(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";var e=this.metaScene;for(var t in e.metaObjects){var n=e.metaObjects[t];if(n.children&&(n.children=[]),n.propertySets&&(n.propertySets=[]),n.propertySetIds)for(var r=0,i=n.propertySetIds.length;r<i;r++){var a=n.propertySetIds[r],s=e.propertySets[a];n.propertySets.push(s)}}for(var o in e.metaObjects){var l=e.metaObjects[o];if(l.parentId){var u=e.metaObjects[l.parentId];u&&(l.parent=u,(u.children||(u.children=[])).push(l))}}for(var c in e.metaObjectsByType={},e.metaObjects){var f=e.metaObjects[c],p=f.type;(e.metaObjectsByType[p]||(e.metaObjectsByType[p]={}))[c]=f}this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}},{key:"getJSON",value:function(){for(var e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]},t=0,n=this.metaObjects.length;t<n;t++){var r=this.metaObjects[t],i={id:r.id,originalSystemId:r.originalSystemId,extId:r.extId,type:r.type,name:r.name};r.parent&&(i.parent=r.parent.id),r.attributes&&(i.attributes=r.attributes),r.propertySetIds&&(i.propertySetIds=r.propertySetIds),e.metaObjects.push(i)}for(var a=0,s=this.propertySets.length;a<s;a++){for(var o=this.propertySets[a],l={id:o.id,originalSystemId:o.originalSystemId,extId:o.extId,type:o.type,name:o.name,propertyies:[]},u=0,c=o.properties.length;u<c;u++){var f=o.properties[u],p={id:f.id,description:f.description,type:f.type,name:f.name,value:f.value,valueType:f.valueType};l.properties.push(p)}e.propertySets.push(l)}return e}},{key:"_globalizeIDs",value:function(e,t){var n=!!t.globalizeObjectIds;if(e.metaObjects)for(var r=0,i=e.metaObjects.length;r<i;r++){var a=e.metaObjects[r];if(a.originalSystemId=a.id,a.parent&&(a.originalParentSystemId=a.parent),n&&(a.id=$.globalizeObjectId(this.id,a.id),a.parent&&(a.parent=$.globalizeObjectId(this.id,a.parent))),n){var s=a.propertySetIds;if(s){for(var o=[],l=0,u=s.length;l<u;l++)o.push($.globalizeObjectId(this.id,s[l]));a.propertySetIds=o,a.originalSystemPropertySetIds=s}}else a.originalSystemPropertySetIds=a.propertySetIds}if(e.propertySets)for(var c=0,f=e.propertySets.length;c<f;c++){var p=e.propertySets[c];p.originalSystemId=p.id,n&&(p.id=$.globalizeObjectId(this.id,p.id))}}}]),e}(),Fp=function(){function e(t,n){b(this,e),this.viewer=t,this.scene=n,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}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;r<i;r++)n[r](t)}},{key:"off",value:function(e){}},{key:"createMetaModel",value:function(e,t){var n=new xp({metaScene:this,id:e,projectId:t.projectId||"none",revisionId:t.revisionId||"none",author:t.author||"none",createdAt:t.createdAt||"none",creatingApplication:t.creatingApplication||"none",schema:t.schema||"none",propertySets:[]});return n.loadData(t),n.finalize(),n}},{key:"destroyMetaModel",value:function(e){var t=this.metaModels[e];if(t){if(t.propertySets)for(var n=0,r=t.propertySets.length;n<r;n++){var i=t.propertySets[n];if(1===i.metaModels.length)delete this.propertySets[i.id];else{for(var a=[],s=0,o=i.metaModels.length;s<o;s++)i.metaModels[s].id!==e&&a.push(i.metaModels[s]);i.metaModels=a}}if(t.metaObjects)for(var l=0,u=t.metaObjects.length;l<u;l++){var c=t.metaObjects[l];c.type;var f=c.id;if(1===c.metaModels.length)delete this.metaObjects[f],c.parent||delete this.rootMetaObjects[f];else{for(var p=[],A=t.id,d=0,v=c.metaModels.length;d<v;d++)c.metaModels[d].id!==A&&p.push(c.metaModels[d]);c.metaModels=p}}for(var h in this.metaObjects){var I=this.metaObjects[h];if(I.children&&(I.children=[]),I.propertySets&&(I.propertySets=[]),I.propertySetIds)for(var y=0,m=I.propertySetIds.length;y<m;y++){var w=I.propertySetIds[y],g=this.propertySets[w];I.propertySets.push(g)}}for(var E in this.metaObjectsByType={},this.metaObjects){var T=this.metaObjects[E],b=T.type;T.children&&(T.children=null),(this.metaObjectsByType[b]||(this.metaObjectsByType[b]={}))[E]=T}for(var D in this.metaObjects){var P=this.metaObjects[D];if(P.parentId){var R=this.metaObjects[P.parentId];R&&(P.parent=R,(R.children||(R.children=[])).push(P))}}delete this.metaModels[e],this.fire("metaModelDestroyed",e)}}},{key:"getObjectIDsByType",value:function(e){var t=this.metaObjectsByType[e];return t?Object.keys(t):[]}},{key:"getObjectIDsInSubtree",value:function(e,t,n){var r=[],i=this.metaObjects[e],a=t&&t.length>0?Hp(t):null,s=n&&n.length>0?Hp(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<l;o++)e(i[o])}}(i),r}},{key:"withMetaObjectsInSubtree",value:function(e,t){var n=this.metaObjects[e];n&&n.withMetaObjectsInSubtree(t)}}]),e}();function Hp(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=!0;return t}
17
+ **/var $u=null;function ec(e,t){var n,r,i,a,s,o,l=3*e,u=3*t,c=Math.min(n=$u[l],r=$u[l+1],i=$u[l+2]),f=Math.min(a=$u[u],s=$u[u+1],o=$u[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 tc(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r<i;r++)n[r]=r;$u=new Int32Array(e.length);for(var a=0,s=e.length;a<s;a++)$u[a]=e[a]>>t;n.sort(ec);for(var o=new Int32Array(e.length),l=0,u=n.length;l<u;l++)o[3*l+0]=e[3*n[l]+0],o[3*l+1]=e[3*n[l]+1],o[3*l+2]=e[3*n[l]+2];return o}var nc=null;function rc(e,t){var n=nc[2*e]-nc[2*t];return 0!==n?n:nc[2*e+1]-nc[2*t+1]}function ic(e){if(0===(e||[]).length)return[];for(var t=new Int32Array(e.length/2),n=0,r=t.length;n<r;n++)t[n]=n;for(var i=0,a=e.length;i<a;i+=2)if(e[i]>e[i+1]){var s=e[i];e[i]=e[i+1],e[i+1]=s}nc=new Int32Array(e),t.sort(rc);for(var o=new Int32Array(e.length),l=0,u=t.length;l<u;l++)o[2*l+0]=e[2*t[l]+0],o[2*l+1]=e[2*t[l]+1];return o}function ac(e,t){var n={},r={};e.forEach((function(e){for(var t=e.indices,i=e.edgeIndices,a=e.positionsCompressed,s=0,o=t.length;s<o;s+=3){var l=a[3*t[s]]+"_"+a[3*t[s]+1]+"_"+a[3*t[s]+2]+"/"+a[3*t[s+1]]+"_"+a[3*t[s+1]+1]+"_"+a[3*t[s+1]+2]+"/"+a[3*t[s+2]]+"_"+a[3*t[s+2]+1]+"_"+a[3*t[s+2]+2];n[l]=!0}e.edgeIndices.length/2;for(var u=0,c=i.length;u<c;u+=2){var f=a[3*i[u]]+"_"+a[3*i[u]+1]+"_"+a[3*i[u]+2]+"/"+a[3*i[u+1]]+"_"+a[3*i[u+1]+1]+"_"+a[3*i[u+1]+2]+"/";r[f]=!0}}));var i=t.indices;t.edgeIndices;for(var a=t.positionsCompressed,s=0,o=i.length;s<o;s+=3){var l=a[3*i[s]]+"_"+a[3*i[s]+1]+"_"+a[3*i[s]+2]+"/"+a[3*i[s+1]]+"_"+a[3*i[s+1]+1]+"_"+a[3*i[s+1]+2]+"/"+a[3*i[s+2]]+"_"+a[3*i[s+2]+1]+"_"+a[3*i[s+2]+2];if(!(l in n))throw console.log("Not found "+l),"Ohhhh!"}}var sc=$.vec3(),oc=$.vec3(),lc=$.vec3();$.vec3();var uc=$.vec4(),cc=$.mat4(),fc=function(){function e(t,n){b(this,e),this._scene=t,this._withSAO=n,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{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,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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=sc;if(v){var y=$.transformPoint3(f,u,oc);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=Be(i.viewMatrix,I,cc),(d=lc)[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._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),g=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var E=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*g,b=a.renderFlags,D=0;D<w;D++){var P=this._uSectionPlanes[D];if(P)if(D<g){var R=b.sectionPlanesActivePerLayer[T+D];if(s.uniform1i(P.active,R?1:0),R){var C=E[D];if(u){var _=Le(C.dist,C.dir,u,sc);s.uniform3fv(P.pos,_)}else s.uniform3fv(P.pos,C.pos);s.uniform3fv(P.dir,C.dir)}}else s.uniform1i(P.active,0)}o.numIndices8Bits>0&&(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 bt(t,this._buildShader()),this._program.errors)return this.errors=this._program.errors,void console.error(this.errors);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;a<s;a++)switch(i[a].type){case"dir":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=null,this._uLightDir[a]=r.getLocation("lightDir"+a);break;case"point":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=r.getLocation("lightPos"+a),this._uLightDir[a]=null,this._uLightAttenuation[a]=r.getLocation("lightAttenuation"+a);break;case"spot":this._uLightColor[a]=r.getLocation("lightColor"+a),this._uLightPos[a]=r.getLocation("lightPos"+a),this._uLightDir[a]=r.getLocation("lightDir"+a),this._uLightAttenuation[a]=r.getLocation("lightAttenuation"+a)}this._uSceneModelMatrix=r.getLocation("sceneModelMatrix"),this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.getNumAllocatedSectionPlanes();o<l;o++)this._uSectionPlanes.push({active:r.getLocation("sectionPlaneActive"+o),pos:r.getLocation("sectionPlanePos"+o),dir:r.getLocation("sectionPlaneDir"+o)});this._withSAO&&(this._uOcclusionTexture="uOcclusionTexture",this._uSAOParams=r.getLocation("uSAOParams")),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=r.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=r.getLocation("uCameraEyeRtc")}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=this._program,i=t._lightsState.lights,a=t.camera.project;r.bind(),this._uLightAmbient&&n.uniform4fv(this._uLightAmbient,t._lightsState.getAmbientColorAndIntensity());for(var s=0,o=i.length;s<o;s++){var l=i[s];this._uLightColor[s]&&n.uniform4f(this._uLightColor[s],l.color[0],l.color[1],l.color[2],l.intensity),this._uLightPos[s]&&(n.uniform3fv(this._uLightPos[s],l.pos),this._uLightAttenuation[s]&&n.uniform1f(this._uLightAttenuation[s],l.attenuation)),this._uLightDir[s]&&n.uniform3fv(this._uLightDir[s],l.dir)}if(this._withSAO){var u=t.sao;if(u.possible){var c=n.drawingBufferWidth,f=n.drawingBufferHeight;uc[0]=c,uc[1]=f,uc[2]=u.blendCutoff,uc[3]=u.blendFactor,n.uniform4fv(this._uSAOParams,uc),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,10)}}if(t.logarithmicDepthBufferEnabled){var p=2/(Math.log(a.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,p)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e,t=this._scene,n=t._sectionPlanesState,r=t._lightsState,i=n.getNumAllocatedSectionPlanes()>0,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;"),a.push("uniform mat4 sceneModelMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectMatrix;"),a.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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<o;s++)"ambient"!==(e=r.lights[s]).type&&(a.push("uniform vec4 lightColor"+s+";"),"dir"===e.type&&a.push("uniform vec3 lightDir"+s+";"),"point"===e.type&&a.push("uniform vec3 lightPos"+s+";"),"spot"===e.type&&(a.push("uniform vec3 lightPos"+s+";"),a.push("uniform vec3 lightDir"+s+";")));i&&(a.push("out vec4 vWorldPosition;"),a.push("flat out uint vFlags2;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int polygonIndex = gl_VertexID / 3;"),a.push("int h_packed_object_id_index = (polygonIndex >> 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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 = sceneModelMatrix * ((objectDecodeAndInstanceMatrix * vec4(position, 1.0))); "),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;l<u;l++)if("ambient"!==(e=r.lights[l]).type){if("dir"===e.type)"view"===e.space?a.push("viewLightDir = normalize(lightDir"+l+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+l+", 0.0)).xyz);");else if("point"===e.type)"view"===e.space?a.push("viewLightDir = -normalize(lightPos"+l+" - viewPosition.xyz);"):a.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos"+l+", 0.0)).xyz);");else{if("spot"!==e.type)continue;"view"===e.space?a.push("viewLightDir = normalize(lightDir"+l+");"):a.push("viewLightDir = normalize((viewMatrix * vec4(lightDir"+l+", 0.0)).xyz);")}a.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);"),a.push("reflectedColor += lambertian * (lightColor"+l+".rgb * lightColor"+l+".a);")}return a.push("vec3 rgb = vec3(color.rgb) / 255.0;"),a.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),t.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),i&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags2 = flags2.r;")),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.getNumAllocatedSectionPlanes()>0,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.getNumAllocatedSectionPlanes();i<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vColor;"),r.push("out vec4 outColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = vFlags2 > 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.getNumAllocatedSectionPlanes();s<o;s++)r.push("if (sectionPlaneActive"+s+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+s+".xyz, vWorldPosition.xyz - sectionPlanePos"+s+".xyz), 0.0, 1000.0);"),r.push("}");r.push(" if (dist > 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}(),pc=new Float32Array([1,1,1]),Ac=$.vec3(),dc=$.vec3(),vc=$.vec3();$.vec3();var hc=$.mat4(),Ic=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=Ac;if(u){var I=dc;$.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=Be(A,h,hc),(v=vc)[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===Xs.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===Xs.SILHOUETTE_HIGHLIGHTED){var g=r.highlightMaterial._state,E=g.fillColor,T=g.fillAlpha;s.uniform4f(this._uColor,E[0],E[1],E[2],T)}else if(n===Xs.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,pc);if(r.logarithmicDepthBufferEnabled){var R=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,R)}var C=r._sectionPlanesState.getNumAllocatedSectionPlanes(),_=r._sectionPlanesState.sectionPlanes.length;if(C>0)for(var B=r._sectionPlanesState.sectionPlanes,O=t.layerIndex*_,S=a.renderFlags,N=0;N<C;N++){var L=this._uSectionPlanes[N];if(L)if(N<_){var M=S.sectionPlanesActivePerLayer[O+N];if(s.uniform1i(L.active,M?1:0),M){var x=B[N];if(u){var F=Le(x.dist,x.dir,u,Ac);s.uniform3fv(L.pos,F)}else s.uniform3fv(L.pos,x.pos);s.uniform3fv(L.dir,x.dir)}}else s.uniform1i(L.active,0)}o.numIndices8Bits>0&&(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 bt(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("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=t.camera.project;if(this._program.bind(),t.logarithmicDepthBufferEnabled){var i=2/(Math.log(r.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,i)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("uniform vec4 color;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),yc=new Float32Array([0,0,0,1]),mc=$.vec3(),wc=$.vec3();$.vec3();var gc=$.mat4(),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=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=mc;if(v){var y=$.transformPoint3(f,u,wc);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=Be(A,I,gc)}else d=A;if(s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),n===Xs.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===Xs.EDGES_HIGHLIGHTED){var E=i.highlightMaterial._state,T=E.edgeColor,b=E.edgeAlpha;s.uniform4f(this._uColor,T[0],T[1],T[2],b)}else if(n===Xs.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,yc);var C=i._sectionPlanesState.getNumAllocatedSectionPlanes(),_=i._sectionPlanesState.sectionPlanes.length;if(C>0)for(var B=i._sectionPlanesState.sectionPlanes,O=t.layerIndex*_,S=r.renderFlags,N=0;N<C;N++){var L=this._uSectionPlanes[N];if(L)if(N<_){var M=S.sectionPlanesActivePerLayer[O+N];if(s.uniform1i(L.active,M?1:0),M){var x=B[N];if(u){var F=Le(x.dist,x.dir,u,mc);s.uniform3fv(L.pos,F)}else s.uniform3fv(L.pos,x.pos);s.uniform3fv(L.dir,x.dir)}}else s.uniform1i(L.active,0)}o.numEdgeIndices8Bits>0&&(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 bt(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._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix"}}},{key:"_bindProgram",value:function(){var e=this._scene,t=e.canvas.gl,n=this._program,r=e.camera.project;if(n.bind(),e.logarithmicDepthBufferEnabled){var i=2/(Math.log(r.far+1)/Math.LN2);t.uniform1f(this._uLogDepthBufFC,i)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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;"),n.push("uniform mat4 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("mat4 matrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.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("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.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vColor;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Tc=$.vec3(),bc=$.vec3();$.vec3();var Dc=$.mat4(),Pc=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=Tc;if(v){var y=$.transformPoint3(f,u,bc);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=Be(A,I,Dc)}else d=A;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var m=i._sectionPlanesState.getNumAllocatedSectionPlanes(),w=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var g=i._sectionPlanesState.sectionPlanes,E=t.layerIndex*w,T=r.renderFlags,b=0;b<m;b++){var D=this._uSectionPlanes[b];if(D)if(b<w){var P=T.sectionPlanesActivePerLayer[E+b];if(s.uniform1i(D.active,P?1:0),P){var R=g[b];if(u){var C=Le(R.dist,R.dir,u,Tc);s.uniform3fv(D.pos,C)}else s.uniform3fv(D.pos,R.pos);s.uniform3fv(D.dir,R.dir)}}else s.uniform1i(D.active,0)}o.numEdgeIndices8Bits>0&&(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 bt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix"}}},{key:"_bindProgram",value:function(){var e=this._scene,t=e.canvas.gl,n=this._program,r=e.camera.project;if(n.bind(),e.logarithmicDepthBufferEnabled){var i=2/(Math.log(r.far+1)/Math.LN2);t.uniform1f(this._uLogDepthBufFC,i)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform highp sampler2D uObjectPerObjectOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.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.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vColor;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Rc=$.vec3(),Cc=$.vec3(),_c=$.vec3(),Bc=$.mat4(),Oc=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=Rc;if(v){var y=$.transformPoint3(A,f,Cc);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=Be(o.viewMatrix,I,Bc),(i=_c)[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.uniform2f(this._uDrawingBufferSize,l.drawingBufferWidth,l.drawingBufferHeight),l.uniformMatrix4fv(this._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),g=s._sectionPlanesState.sectionPlanes.length;if(w>0)for(var E=s._sectionPlanesState.sectionPlanes,T=t.layerIndex*g,b=a.renderFlags,D=0;D<w;D++){var P=this._uSectionPlanes[D];if(P)if(D<g){var R=b.sectionPlanesActivePerLayer[T+D];if(l.uniform1i(P.active,R?1:0),R){var C=E[D];if(f){var _=Le(C.dist,C.dir,f,Rc);l.uniform3fv(P.pos,_)}else l.uniform3fv(P.pos,C.pos);l.uniform3fv(P.dir,C.dir)}}else l.uniform1i(P.active,0)}u.numIndices8Bits>0&&(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 bt(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._uDrawingBufferSize=n.getLocation("drawingBufferSize"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(e){var t=this._scene.canvas.gl;this._program.bind(),t.uniform1i(this._uPickInvisible,e.pickInvisible)}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("uniform vec2 drawingBufferSize;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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*objectDecodeAndInstanceMatrix)) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uvec4 vFlags2;");for(var r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vPickColor;"),n.push("out vec4 outPickColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = (float(vFlags2.x) > 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push(" if (sectionPlaneActive"+r+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+r+".xyz, vWorldPosition.xyz - sectionPlanePos"+r+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Sc=$.vec3(),Nc=$.vec3(),Lc=$.vec3();$.vec3();var Mc=$.mat4(),xc=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),f||0!==p[0]||0!==p[1]||0!==p[2]){var h=Sc;if(f){var I=Nc;$.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=Be(v,h,Mc),(i=Lc)[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.uniform2f(this._uDrawingBufferSize,l.drawingBufferWidth,l.drawingBufferHeight),l.uniform1f(this._uPickZNear,e.pickZNear),l.uniform1f(this._uPickZFar,e.pickZFar),l.uniformMatrix4fv(this._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),w=s._sectionPlanesState.sectionPlanes.length;if(m>0)for(var g=s._sectionPlanesState.sectionPlanes,E=t.layerIndex*w,T=a.renderFlags,b=0;b<m;b++){var D=this._uSectionPlanes[b];if(D)if(b<w){var P=T.sectionPlanesActivePerLayer[E+b];if(l.uniform1i(D.active,P?1:0),P){var R=g[b];if(f){var C=Le(R.dist,R.dir,f,Sc);l.uniform3fv(D.pos,C)}else l.uniform3fv(D.pos,R.pos);l.uniform3fv(D.dir,R.dir)}}else l.uniform1i(D.active,0)}u.numIndices8Bits>0&&(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 bt(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._uDrawingBufferSize=n.getLocation("drawingBufferSize"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._uPickZNear=n.getLocation("pickZNear"),this._uPickZFar=n.getLocation("pickZFar"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("uniform vec2 drawingBufferSize;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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*objectDecodeAndInstanceMatrix)) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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.getNumAllocatedSectionPlanes()>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;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec4 vViewPosition;"),n.push("vec4 packDepth(const in float depth) {"),n.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),n.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),n.push(" vec4 res = fract(depth * bitShift);"),n.push(" res -= res.xxyz * bitMask;"),n.push(" return res;"),n.push("}"),n.push("out vec4 outPackedDepth;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push(" if (sectionPlaneActive"+r+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+r+".xyz, vWorldPosition.xyz - sectionPlanePos"+r+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Fc=$.vec3(),Hc=$.vec3(),Uc=$.vec3(),Gc=$.vec3();$.vec3();var kc=$.mat4(),jc=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=a.aabb,h=e.pickViewMatrix||o.viewMatrix,I=Fc;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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=Hc;if(y){var g=$.transformPoint3(A,f,Uc);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=Be(h,w,kc),(i=Gc)[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._uSceneModelMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var E=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,E);var T=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(T>0)for(var D=s._sectionPlanesState.sectionPlanes,P=t.layerIndex*b,R=a.renderFlags,C=0;C<T;C++){var _=this._uSectionPlanes[C];if(_)if(C<b){var B=R.sectionPlanesActivePerLayer[P+C];if(l.uniform1i(_.active,B?1:0),B){var O=D[C];if(f){var S=Le(O.dist,O.dir,f,Fc);l.uniform3fv(_.pos,S)}else l.uniform3fv(_.pos,O.pos);l.uniform3fv(_.dir,O.dir)}}else l.uniform1i(_.active,0)}var N="edge"===e.snapMode?l.LINES:l.POINTS;u.numEdgeIndices8Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),l.drawArrays(N,0,u.numEdgeIndices8Bits)),u.numEdgeIndices16Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),l.drawArrays(N,0,u.numEdgeIndices16Bits)),u.numEdgeIndices32Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),l.drawArrays(N,0,u.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new bt(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._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._uLogDepthBufFC=n.getLocation("logDepthBufFC"),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this.uVectorA=n.getLocation("uSnapVectorA"),this.uInverseVectorAB=n.getLocation("uSnapInvVectorAB"),this._uLayerNumber=n.getLocation("uLayerNumber"),this._uCoordinateScaler=n.getLocation("uCoordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("vec4 worldPosition = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>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._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in highp vec3 relativeToOriginPosition;"),n.push("out highp ivec4 outCoords;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0;a<e._sectionPlanesState.getNumAllocatedSectionPlanes();a++)n.push(" if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 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}(),Vc=$.vec3(),Qc=$.vec3(),Wc=$.vec3(),zc=$.vec3();$.vec3();var Kc=$.mat4(),Yc=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=a.aabb,h=e.pickViewMatrix||o.viewMatrix,I=Vc;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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=Qc;if(y){var g=Wc;$.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=Be(h,w,Kc),(i=zc)[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 E=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,E);var T=s._sectionPlanesState.getNumAllocatedSectionPlanes(),b=s._sectionPlanesState.sectionPlanes.length;if(T>0)for(var D=s._sectionPlanesState.sectionPlanes,P=t.layerIndex*b,R=a.renderFlags,C=0;C<T;C++){var _=this._uSectionPlanes[C];if(_)if(C<b){var B=R.sectionPlanesActivePerLayer[P+C];if(l.uniform1i(_.active,B?1:0),B){var O=D[C];if(f){var S=Le(O.dist,O.dir,f,Vc);l.uniform3fv(_.pos,S)}else l.uniform3fv(_.pos,O.pos);l.uniform3fv(_.dir,O.dir)}}else l.uniform1i(_.active,0)}u.numIndices8Bits>0&&(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 bt(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("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._uLogDepthBufFC=n.getLocation("logDepthBufFC"),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc"),this._uVectorA=n.getLocation("uVectorAB"),this._uInverseVectorAB=n.getLocation("uInverseVectorAB"),this._uLayerNumber=n.getLocation("uLayerNumber"),this._uCoordinateScaler=n.getLocation("uCoordinateScaler")}}},{key:"_bindProgram",value:function(){this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("}"),n.push("flat out vec4 vPickColor;"),n.push("out vec4 vWorldPosition;"),t&&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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("uvec4 color = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vWorldPosition = worldPosition;"),t&&n.push("vFlags2 = flags2.r;"),n.push("vPickColor = vec4(texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0));"),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(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>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;"),n.push("in vec4 vWorldPosition;"),n.push("flat in vec4 vPickColor;"),t){n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in highp vec3 relativeToOriginPosition;"),n.push("layout(location = 0) out highp ivec4 outCoords;"),n.push("layout(location = 1) out highp ivec4 outNormal;"),n.push("layout(location = 2) out lowp uvec4 outPickColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0;a<e._sectionPlanesState.getNumAllocatedSectionPlanes();a++)n.push(" if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 0.0) { discard; }"),n.push(" }")}return n.push(" float dx = dFdx(vFragDepth);"),n.push(" float dy = dFdy(vFragDepth);"),n.push(" float diff = sqrt(dx*dx+dy*dy);"),n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth + diff ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz * uCoordinateScaler.xyz, - uLayerNumber);"),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(".concat($.MAX_INT,"), 1.0);")),n.push("outPickColor = uvec4(vPickColor);"),n.push("}"),n}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Xc=$.vec3(),qc=$.vec3(),Jc=$.vec3();$.vec3();var Zc=$.mat4(),$c=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=Xc;if(u){var I=qc;$.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=Be(A,h,Zc),(v=Jc)[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.getNumAllocatedSectionPlanes(),m=i._sectionPlanesState.sectionPlanes.length;if(y>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,E=r.renderFlags,T=0;T<y;T++){var b=this._uSectionPlanes[T];if(b)if(T<m){var D=E.sectionPlanesActivePerLayer[g+T];if(s.uniform1i(b.active,D?1:0),D){var P=w[T];if(u){var R=Le(P.dist,P.dir,u,Xc);s.uniform3fv(b.pos,R)}else s.uniform3fv(b.pos,P.pos);s.uniform3fv(b.dir,P.dir)}}else s.uniform1i(b.active,0)}o.numIndices8Bits>0&&(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 bt(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("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._uPickZNear=n.getLocation("pickZNear"),this._uPickZFar=n.getLocation("pickZFar"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(){var e=this._scene;e.canvas.gl,e.camera.project,this._program.bind()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureOcclusionRenderer 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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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*objectDecodeAndInstanceMatrix)) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),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.getNumAllocatedSectionPlanes()>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("flat in uint vFlags2;");for(var r=0;r<e.getNumAllocatedSectionPlanes();r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("out vec4 outColor;"),n.push("void main(void) {"),t){n.push(" bool clippable = (float(vFlags2) > 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i<e.getNumAllocatedSectionPlanes();i++)n.push(" if (sectionPlaneActive"+i+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 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}(),ef=$.vec3(),tf=$.vec3(),nf=$.vec3();$.vec3();var rf=$.mat4(),af=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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=ef;if(v){var y=$.transformPoint3(f,u,tf);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=Be(i.viewMatrix,I,rf),(d=nf)[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._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),g=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var E=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*g,b=a.renderFlags,D=0;D<w;D++){var P=this._uSectionPlanes[D];if(P)if(D<g){var R=b.sectionPlanesActivePerLayer[T+D];if(s.uniform1i(P.active,R?1:0),R){var C=E[D];if(u){var _=Le(C.dist,C.dir,u,ef);s.uniform3fv(P.pos,_)}else s.uniform3fv(P.pos,C.pos);s.uniform3fv(P.dir,C.dir)}}else s.uniform1i(P.active,0)}o.numIndices8Bits>0&&(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 bt(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("objectDecodeAndInstanceMatrix"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=this._program,i=t.camera.project;if(r.bind(),n.uniformMatrix4fv(this._uProjMatrix,!1,i.matrix),t.logarithmicDepthBufferEnabled){var a=2/(Math.log(i.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,a)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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;"),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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>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;")),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),sf=$.vec3(),of=$.vec3(),lf=$.vec3();$.vec3();var uf=$.mat4(),cf=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=sf;if(v){var y=of;$.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=Be(p,I,uf),(d=lf)[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.getNumAllocatedSectionPlanes(),w=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var g=i._sectionPlanesState.sectionPlanes,E=t.layerIndex*w,T=r.renderFlags,b=0;b<m;b++){var D=this._uSectionPlanes[b];if(D)if(b<w){var P=T.sectionPlanesActivePerLayer[E+b];if(s.uniform1i(D.active,P?1:0),P){var R=g[b];if(l){var C=Le(R.dist,R.dir,l,sf);s.uniform3fv(D.pos,C)}else s.uniform3fv(D.pos,R.pos);s.uniform3fv(D.dir,R.dir)}}else s.uniform1i(D.active,0)}s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,t._state.objectDecodeAndInstanceMatrix),this._aPosition.bindArrayBuffer(o.positionsBuf),this._aOffset.bindArrayBuffer(o.offsetsBuf),this._aNormal.bindArrayBuffer(o.normalsBuf),this._aColor.bindArrayBuffer(o.colorsBuf),this._aFlags.bindArrayBuffer(o.flagsBuf),this._aFlags2&&this._aFlags2.bindArrayBuffer(o.flags2Buf),o.indicesBuf.bind(),s.drawElements(s.TRIANGLES,o.indicesBuf.numItems,o.indicesBuf.itemType,0)}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new bt(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("objectDecodeAndInstanceMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uWorldNormalMatrix=n.getLocation("worldNormalMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uViewNormalMatrix=n.getLocation("viewNormalMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPosition=n.getAttribute("position"),this._aOffset=n.getAttribute("offset"),this._aNormal=n.getAttribute("normal"),this._aColor=n.getAttribute("color"),this._aFlags=n.getAttribute("flags"),this._aFlags2&&(this._aFlags2=n.getAttribute("flags2")),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC"))}}},{key:"_bindProgram",value:function(){var e=this._scene,t=e.canvas.gl,n=e.camera.project;if(this._program.bind(),t.uniformMatrix4fv(this._uProjMatrix,!1,n.matrix),e.logarithmicDepthBufferEnabled){var r=2/(Math.log(n.far+1)/Math.LN2);t.uniform1f(this._uLogDepthBufFC,r)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=[];return n.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&dt.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 objectDecodeAndInstanceMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),dt.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 * (objectDecodeAndInstanceMatrix * 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&&(dt.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.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&dt.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&&dt.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),t){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(var r=0;r<e._sectionPlanesState.getNumAllocatedSectionPlanes();r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("in vec3 vViewNormal;"),n.push("vec3 packNormalToRGB( const in vec3 normal ) {"),n.push(" return normalize( normal ) * 0.5 + 0.5;"),n.push("}"),n.push("void main(void) {"),t){n.push(" bool clippable = (float(vFlags2.x) > 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i<e._sectionPlanesState.getNumAllocatedSectionPlanes();i++)n.push(" if (sectionPlaneActive"+i+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),n.push(" }");n.push(" if (dist > 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&dt.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}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),ff=$.vec3(),pf=$.vec3(),Af=$.vec3();$.vec3(),$.vec4();var df=$.mat4(),vf=function(){function e(t,n){b(this,e),this._scene=t,this._withSAO=n,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{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,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.uTexturePerObjectPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this.uTexturePerObjectColorsAndFlags,this._uTexturePerObjectMatrix);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=ff;if(v){var y=$.transformPoint3(f,u,pf);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=Be(i.viewMatrix,I,df),(d=Af)[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.uniform2fv(this._uPickClipPos,e.pickClipPos),s.uniform2f(this._uDrawingBufferSize,s.drawingBufferWidth,s.drawingBufferHeight),s.uniformMatrix4fv(this._uSceneModelMatrix,!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.getNumAllocatedSectionPlanes(),g=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var E=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*g,b=a.renderFlags,D=0;D<w;D++){var P=this._uSectionPlanes[D];if(P)if(D<g){var R=b.sectionPlanesActivePerLayer[T+D];if(s.uniform1i(P.active,R?1:0),R){var C=E[D];if(u){var _=Le(C.dist,C.dir,u,ff);s.uniform3fv(P.pos,_)}else s.uniform3fv(P.pos,C.pos);s.uniform3fv(P.dir,C.dir)}}else s.uniform1i(P.active,0)}o.numIndices8Bits>0&&(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 bt(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._uDrawingBufferSize=n.getLocation("drawingBufferSize"),this._uSceneModelMatrix=n.getLocation("sceneModelMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this.uTexturePerObjectPositionsDecodeMatrix="uObjectPerObjectPositionsDecodeMatrix",this.uTexturePerObjectColorsAndFlags="uObjectPerObjectColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTexturePerObjectMatrix="uTexturePerObjectMatrix",this._uCameraEyeRtc=n.getLocation("uCameraEyeRtc")}}},{key:"_bindProgram",value:function(e){var t=this._scene,n=t.canvas.gl,r=this._program,i=t.camera.project;if(r.bind(),t.logarithmicDepthBufferEnabled){var a=2/(Math.log(i.far+1)/Math.LN2);n.uniform1f(this._uLogDepthBufFC,a)}}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=[];return n.push("#version 300 es"),n.push("// trianglesDatatextureNormalsRenderer 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 sceneModelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uObjectPerObjectPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uObjectPerObjectColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectMatrix;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),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("uniform vec2 drawingBufferSize;"),n.push("vec4 remapClipPos(vec4 clipPos) {"),n.push(" clipPos.xy /= clipPos.w;"),n.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;"),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("}"),n.push("out vec4 vWorldPosition;"),t&&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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uObjectPerObjectColorsAndFlags, 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 objectInstanceMatrix = mat4 (texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4 (texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uObjectPerObjectPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uObjectPerObjectColorsAndFlags, 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 (uObjectPerObjectColorsAndFlags, 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*objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(sceneModelMatrix * objectDecodeAndInstanceMatrix) * 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("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*objectDecodeAndInstanceMatrix)) * 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 = sceneModelMatrix * (objectDecodeAndInstanceMatrix * vec4(position, 1.0)); "),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));")),n.push("vWorldPosition = worldPosition;"),t&&n.push("vFlags2 = flags2.r;"),n.push("gl_Position = remapClipPos(clipPos);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState.getNumAllocatedSectionPlanes()>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTexturePickNormalsRenderer 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;"),t){n.push("flat in uint vFlags2;");for(var r=0,i=e._sectionPlanesState.getNumAllocatedSectionPlanes();r<i;r++)n.push("uniform bool sectionPlaneActive"+r+";"),n.push("uniform vec3 sectionPlanePos"+r+";"),n.push("uniform vec3 sectionPlaneDir"+r+";")}if(n.push("out highp ivec4 outNormal;"),n.push("void main(void) {"),t){n.push(" bool clippable = vFlags2 > 0u;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var a=0,s=e._sectionPlanesState.getNumAllocatedSectionPlanes();a<s;a++)n.push("if (sectionPlaneActive"+a+") {"),n.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),n.push("}");n.push(" if (dist > 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(" 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(".concat($.MAX_INT,"), 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}(),hf=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:"eagerCreateRenders",value:function(){this._silhouetteRenderer||(this._silhouetteRenderer=new Ic(this._scene)),this._pickMeshRenderer||(this._pickMeshRenderer=new Oc(this._scene)),this._pickDepthRenderer||(this._pickDepthRenderer=new xc(this._scene)),this._pickNormalsRenderer||(this._pickNormalsRenderer=new vf(this._scene)),this._vertexDepthRenderer||(this._vertexDepthRenderer=new jc(this._scene)),this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Yc(this._scene))}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new fc(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new fc(this._scene,!0)),this._colorRendererWithSAO}},{key:"colorQualityRendererWithSAO",get:function(){return this._colorQualityRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Ic(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new af(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new cf(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new Ec(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new Pc(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Oc(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new vf(this._scene)),this._pickNormalsRenderer}},{key:"pickNormalsFlatRenderer",get:function(){return this._pickNormalsFlatRenderer||(this._pickNormalsFlatRenderer=new vf(this._scene)),this._pickNormalsFlatRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new xc(this._scene)),this._pickDepthRenderer}},{key:"vertexDepthRenderer",get:function(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new jc(this._scene)),this._vertexDepthRenderer}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Yc(this._scene)),this._snapDepthBufInitRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new $c(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}(),If={};var yf=P((function e(){b(this,e),this.positionsCompressed=[],this.lenPositionsCompressed=0,this.metallicRoughness=[],this.indices8Bits=[],this.lenIndices8Bits=0,this.indices16Bits=[],this.lenIndices16Bits=0,this.indices32Bits=[],this.lenIndices32Bits=0,this.edgeIndices8Bits=[],this.lenEdgeIndices8Bits=0,this.edgeIndices16Bits=[],this.lenEdgeIndices16Bits=0,this.edgeIndices32Bits=[],this.lenEdgeIndices32Bits=0,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=[]})),mf=function(){function e(){b(this,e),this.texturePerObjectColorsAndFlags=null,this.texturePerObjectOffsets=null,this.texturePerObjectInstanceMatrices=null,this.texturePerObjectPositionsDecodeMatrix=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){this.texturePerObjectPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,n,2),this.texturePerObjectColorsAndFlags.bindTexture(e,r,3),this.texturePerObjectInstanceMatrices.bindTexture(e,i,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}(),wf=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}(),gf={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(gf,null,4));var e=0;Object.keys(gf).forEach((function(t){t.startsWith("size")&&(e+=gf[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/gf.totalPolygons).toFixed(2)));var t={};Object.keys(gf).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((gf[n]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var Ef=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);gf.sizeDataColorsAndFlags+=c.byteLength,gf.numberOfTextures++;for(var f=0;f<o;f++)c.set(t[f],32*f+0),c.set(n[f],32*f+4),c.set([0,0,0,0],32*f+8),c.set([0,0,0,0],32*f+12),c.set([r[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 wf(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);gf.sizeDataTextureOffsets+=i.byteLength,gf.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 wf(e,a,n,r,i)}},{key:"generateTextureForInstancingMatrices",value:function(e,t){var n=t.length;if(0===n)throw"num instance matrices===0";var r=2048,i=Math.ceil(n/512),a=new Float32Array(8192*i);gf.numberOfTextures++;for(var s=0;s<t.length;s++)a.set(t[s],16*s);var o=e.createTexture();return e.bindTexture(e.TEXTURE_2D,o),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGBA,e.FLOAT,a,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 wf(e,o,r,i,a)}},{key:"generateTextureForPositionsDecodeMatrices",value:function(e,t){var n=t.length;if(0===n)throw"num decode+entity matrices===0";var r=2048,i=Math.ceil(n/512),a=new Float32Array(8192*i);gf.sizeDataPositionDecodeMatrices+=a.byteLength,gf.numberOfTextures++;for(var s=0;s<t.length;s++)a.set(t[s],16*s);var o=e.createTexture();return e.bindTexture(e.TEXTURE_2D,o),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGBA,e.FLOAT,a,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 wf(e,o,r,i)}},{key:"generateTextureFor8BitIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/3/r);if(0===i)throw"texture height===0";var a=new Uint8Array(r*i*3);gf.sizeDataTextureIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RGB8UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGB_INTEGER,e.UNSIGNED_BYTE,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor16BitIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/3/r);if(0===i)throw"texture height===0";var a=new Uint16Array(r*i*3);gf.sizeDataTextureIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RGB16UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGB_INTEGER,e.UNSIGNED_SHORT,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor32BitIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/3/r);if(0===i)throw"texture height===0";var a=new Uint32Array(r*i*3);gf.sizeDataTextureIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RGB_INTEGER,e.UNSIGNED_INT,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor8BitsEdgeIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/2/r);if(0===i)throw"texture height===0";var a=new Uint8Array(r*i*2);gf.sizeDataTextureEdgeIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RG8UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RG_INTEGER,e.UNSIGNED_BYTE,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor16BitsEdgeIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/2/r);if(0===i)throw"texture height===0";var a=new Uint16Array(r*i*2);gf.sizeDataTextureEdgeIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RG16UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RG_INTEGER,e.UNSIGNED_SHORT,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureFor32BitsEdgeIndices",value:function(e,t,n){if(0===n)return{texture:null,textureHeight:0};var r=4096,i=Math.ceil(n/2/r);if(0===i)throw"texture height===0";var a=new Uint32Array(r*i*2);gf.sizeDataTextureEdgeIndices+=a.byteLength,gf.numberOfTextures++;for(var s=0,o=0,l=t.length;s<l;s++){var u=t[s];a.set(u,o),o+=u.length}var c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texStorage2D(e.TEXTURE_2D,1,e.RG32UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RG_INTEGER,e.UNSIGNED_INT,a,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new wf(e,c,r,i)}},{key:"generateTextureForPositions",value:function(e,t,n){var r=n/3,i=4096,a=Math.ceil(r/i);if(0===a)throw"texture height===0";var s=new Uint16Array(i*a*3);gf.sizeDataTexturePositions+=s.byteLength,gf.numberOfTextures++;for(var o=0,l=0,u=t.length;o<u;o++){var c=t[o];s.set(c,l),l+=c.length}var f=e.createTexture();return e.bindTexture(e.TEXTURE_2D,f),e.texStorage2D(e.TEXTURE_2D,1,e.RGB16UI,i,a),e.texSubImage2D(e.TEXTURE_2D,0,0,0,i,a,e.RGB_INTEGER,e.UNSIGNED_SHORT,s,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 wf(e,f,i,a)}},{key:"generateTextureForPackedPortionIds",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=t.length,r=4096,i=Math.ceil(n/r);if(0===i)throw"texture height===0";var a=new Uint16Array(r*i);a.set(t,0),gf.sizeDataTexturePortionIds+=a.byteLength,gf.numberOfTextures++;var s=e.createTexture();return e.bindTexture(e.TEXTURE_2D,s),e.texStorage2D(e.TEXTURE_2D,1,e.R16UI,r,i),e.texSubImage2D(e.TEXTURE_2D,0,0,0,r,i,e.RED_INTEGER,e.UNSIGNED_SHORT,a,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 wf(e,s,r,i)}}]),e}();$.vec4([0,0,0,1]),$.vec4([0,0,0,1]),$.vec4([0,0,0,1]);var Tf=new Float32Array(16),bf=new Uint8Array(4),Df=new Float32Array(3);$.AABB3();var Pf=0,Rf=$.identityMat4(),Cf=function(){function e(t,n){var r,i,a;b(this,e),gf.numberOfLayers++,this._layerNumber=Pf++,this.sortId="TriDTX-".concat(this._layerNumber),this.layerIndex=n.layerIndex,this._dataTextureRenderers=(r=t.scene,i=r.id,(a=If[i])||(a=new hf(r),If[i]=a,a._compile(),a.eagerCreateRenders(),r.on("compile",(function(){a._compile(),a.eagerCreateRenders()})),r.on("destroyed",(function(){delete If[i],a._destroy()}))),a),this.model=t,this._buffer=new yf,this._dataTextureState=new mf,this._dataTextureGenerator=new Ef,this._state=new Wt({origin:$.vec3(n.origin),metallicRoughnessBuf:null,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=$.collapseAABB3(),this._numUpdatesInFrame=0,this._finalized=!1}return P(e,[{key:"canCreatePortion",value:function(e){if(this._finalized)throw"Already finalized";var t=e.buckets.length;this._numPortions+t>65536&&gf.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)&&gf.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=[];e.buckets.forEach((function(r,i){var a=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(i):"".concat(e.id,"#").concat(i),s=t._bucketGeometries[a];s||(s=t._createBucketGeometry(e,r),t._bucketGeometries[a]=s);var o=t._createSubPortion(e,s,r);n.push(o)}));var r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(n),this.model.numPortions++,r}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var n=8*Math.ceil(t.indices.length/3/8)*3;gf.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;gf.overheadSizeAlignementEdgeIndices+=2*(i-t.edgeIndices.length);var a=new Uint32Array(i);a.fill(0),a.set(t.edgeIndices),t.edgeIndices=a}var s=t.positionsCompressed,o=t.indices,l=t.edgeIndices,u=this._buffer;u.positionsCompressed.push(s);var c,f=u.lenPositionsCompressed/3,p=s.length/3;u.lenPositionsCompressed+=s.length;var A,d,v=0;o&&(v=o.length/3,p<=256?(A=u.indices8Bits,c=u.lenIndices8Bits/3,u.lenIndices8Bits+=o.length):p<=65536?(A=u.indices16Bits,c=u.lenIndices16Bits/3,u.lenIndices16Bits+=o.length):(A=u.indices32Bits,c=u.lenIndices32Bits/3,u.lenIndices32Bits+=o.length),A.push(o));var h,I=0;l&&(I=l.length/2,p<=256?(h=u.edgeIndices8Bits,d=u.lenEdgeIndices8Bits/2,u.lenEdgeIndices8Bits+=l.length):p<=65536?(h=u.edgeIndices16Bits,d=u.lenEdgeIndices16Bits/2,u.lenEdgeIndices16Bits+=l.length):(h=u.edgeIndices32Bits,d=u.lenEdgeIndices32Bits/2,u.lenEdgeIndices32Bits+=l.length),h.push(l));return this._state.numVertices+=p,gf.numberOfGeometries++,{vertexBase:f,numVertices:p,numTriangles:v,numEdges:I,indicesBase:c,edgeIndicesBase:d,obb:null}}},{key:"_createSubPortion",value:function(e,t,n,r){var i=e.color;e.metallic,e.roughness;var a,s,o=e.colors,l=e.opacity,u=e.meshMatrix,c=e.pickColor,f=this._buffer,p=this._state;f.perObjectPositionsDecodeMatrices.push(e.positionsDecodeMatrix),f.perObjectInstancePositioningMatrices.push(u||Rf),f.perObjectSolid.push(!!e.solid),o?f.perObjectColors.push([255*o[0],255*o[1],255*o[2],255]):i&&f.perObjectColors.push([i[0],i[1],i[2],l]),f.perObjectPickColors.push(c),f.perObjectVertexBases.push(t.vertexBase),a=t.numVertices<=256?p.numIndices8Bits:t.numVertices<=65536?p.numIndices16Bits:p.numIndices32Bits,f.perObjectIndexBaseOffsets.push(a/3-t.indicesBase),s=t.numVertices<=256?p.numEdgeIndices8Bits:t.numVertices<=65536?p.numEdgeIndices16Bits:p.numEdgeIndices32Bits,f.perObjectEdgeIndexBaseOffsets.push(s/2-t.edgeIndicesBase);var A=this._subPortions.length;if(t.numTriangles>0){var d,v=3*t.numTriangles;t.numVertices<=256?(d=f.perTriangleNumberPortionId8Bits,p.numIndices8Bits+=v,gf.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(d=f.perTriangleNumberPortionId16Bits,p.numIndices16Bits+=v,gf.totalPolygons16Bits+=t.numTriangles):(d=f.perTriangleNumberPortionId32Bits,p.numIndices32Bits+=v,gf.totalPolygons32Bits+=t.numTriangles),gf.totalPolygons+=t.numTriangles;for(var h=0;h<t.numTriangles;h+=8)d.push(A)}if(t.numEdges>0){var I,y=2*t.numEdges;t.numVertices<=256?(I=f.perEdgeNumberPortionId8Bits,p.numEdgeIndices8Bits+=y,gf.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(I=f.perEdgeNumberPortionId16Bits,p.numEdgeIndices16Bits+=y,gf.totalEdges16Bits+=t.numEdges):(I=f.perEdgeNumberPortionId32Bits,p.numEdgeIndices32Bits+=y,gf.totalEdges32Bits+=t.numEdges),gf.totalEdges+=t.numEdges;for(var m=0;m<t.numEdges;m+=8)I.push(A)}return this._subPortions.push({numVertices:t.numTriangles}),this._numPortions++,gf.numberOfPortions++,A}},{key:"finalize",value:function(){var e=this;if(!this._finalized){var t=this._state,n=this._dataTextureState,r=this.model.scene.canvas.gl,i=this._buffer;t.gl=r,n.texturePerObjectColorsAndFlags=this._dataTextureGenerator.generateTextureForColorsAndFlags(r,i.perObjectColors,i.perObjectPickColors,i.perObjectVertexBases,i.perObjectIndexBaseOffsets,i.perObjectEdgeIndexBaseOffsets,i.perObjectSolid),n.texturePerObjectInstanceMatrices=this._dataTextureGenerator.generateTextureForInstancingMatrices(r,i.perObjectInstancePositioningMatrices),n.texturePerObjectPositionsDecodeMatrix=this._dataTextureGenerator.generateTextureForPositionsDecodeMatrices(r,i.perObjectPositionsDecodeMatrices),n.texturePerVertexIdCoordinates=this._dataTextureGenerator.generateTextureForPositions(r,i.positionsCompressed,i.lenPositionsCompressed),n.texturePerPolygonIdPortionIds8Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perTriangleNumberPortionId8Bits),n.texturePerPolygonIdPortionIds16Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perTriangleNumberPortionId16Bits),n.texturePerPolygonIdPortionIds32Bits=this._dataTextureGenerator.generateTextureForPackedPortionIds(r,i.perTriangleNumberPortionId32Bits),i.perEdgeNumberPortionId8Bits.length>0&&(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.lenIndices8Bits>0&&(n.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(r,i.indices8Bits,i.lenIndices8Bits)),i.lenIndices16Bits>0&&(n.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(r,i.indices16Bits,i.lenIndices16Bits)),i.lenIndices32Bits>0&&(n.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(r,i.indices32Bits,i.lenIndices32Bits)),i.lenEdgeIndices8Bits>0&&(n.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(r,i.edgeIndices8Bits,i.lenEdgeIndices8Bits)),i.lenEdgeIndices16Bits>0&&(n.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(r,i.edgeIndices16Bits,i.lenEdgeIndices16Bits)),i.lenEdgeIndices32Bits>0&&(n.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(r,i.edgeIndices32Bits,i.lenEdgeIndices32Bits)),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&Me&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&ke&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Ge&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&je&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&He&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Ve&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&Fe&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&xe&&(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&Me?(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&ke?(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&Ge?(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&je?(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&Ve?(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&He?(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.texturePerObjectColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectColorsAndFlags._textureWidth,t.texturePerObjectColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectColorsAndFlags._textureData)}}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&xe?(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&Fe?(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<i;r++)this._subPortionSetColor(n[r],t)}},{key:"_subPortionSetColor",value:function(e,t){if(!this._finalized)throw"Not finalized";var n=this._dataTextureState,r=this.model.scene.canvas.gl;if(bf[0]=t[0],bf[1]=t[1],bf[2]=t[2],bf[3]=t[3],n.texturePerObjectColorsAndFlags._textureData.set(bf,32*e),this._deferredSetFlagsActive)return console.info("_subPortionSetColor defer"),void(this._deferredSetFlagsDirty=!0);++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),console.info("_subPortionSetColor write through"),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectColorsAndFlags._texture),r.texSubImage2D(r.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,r.RGBA_INTEGER,r.UNSIGNED_BYTE,bf)}},{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;a<s;a++)this._subPortionSetFlags(i[a],t,n,r)}},{key:"_subPortionSetFlags",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=!!(t&Me),o=!!(t&Ge),l=!!(t&ke),u=!!(t&je),c=!!(t&Ve),f=!!(t&Fe),p=!!(t&xe);i=!s||p||o?Xs.NOT_RENDERED:n?Xs.COLOR_TRANSPARENT:Xs.COLOR_OPAQUE,a=!s||p?Xs.NOT_RENDERED:u?Xs.SILHOUETTE_SELECTED:l?Xs.SILHOUETTE_HIGHLIGHTED:o?Xs.SILHOUETTE_XRAYED:Xs.NOT_RENDERED;var A=0;A=!s||p?Xs.NOT_RENDERED:u?Xs.EDGES_SELECTED:l?Xs.EDGES_HIGHLIGHTED:o?Xs.EDGES_XRAYED:c?n?Xs.EDGES_COLOR_TRANSPARENT:Xs.EDGES_COLOR_OPAQUE:Xs.NOT_RENDERED;var d=s&&f?Xs.PICK:Xs.NOT_RENDERED,v=this._dataTextureState,h=this.model.scene.canvas.gl;bf[0]=i,bf[1]=a,bf[2]=A,bf[3]=d,v.texturePerObjectColorsAndFlags._textureData.set(bf,32*e+8),this._deferredSetFlagsActive||r?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),h.bindTexture(h.TEXTURE_2D,v.texturePerObjectColorsAndFlags._texture),h.texSubImage2D(h.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,h.RGBA_INTEGER,h.UNSIGNED_BYTE,bf))}},{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;i<a;i++)this._subPortionSetFlags2(r[i],t,n)}},{key:"_subPortionSetFlags2",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!this._finalized)throw"Not finalized";var r=t&He?255:0,i=this._dataTextureState,a=this.model.scene.canvas.gl;bf[0]=r,bf[1]=0,bf[2]=1,bf[3]=2,i.texturePerObjectColorsAndFlags._textureData.set(bf,32*e+12),this._deferredSetFlagsActive||n?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,bf))}},{key:"_setDeferredFlags2",value:function(){}},{key:"setOffset",value:function(e,t){for(var n=this._portionToSubPortionsMap[e],r=0,i=n.length;r<i;r++)this._subPortionSetOffset(n[r],t)}},{key:"_subPortionSetOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";var n=this._dataTextureState,r=this.model.scene.canvas.gl;Df[0]=t[0],Df[1]=t[1],Df[2]=t[2],n.texturePerObjectOffsets._textureData.set(Df,3*e),this._deferredSetFlagsActive?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectOffsets._texture),r.texSubImage2D(r.TEXTURE_2D,0,0,e,1,1,r.RGB,r.FLOAT,Df))}},{key:"setMatrix",value:function(e,t){for(var n=this._portionToSubPortionsMap[e],r=0,i=n.length;r<i;r++)this._subPortionSetMatrix(n[r],t)}},{key:"_subPortionSetMatrix",value:function(e,t){if(!this._finalized)throw"Not finalized";var n=this._dataTextureState,r=this.model.scene.canvas.gl;Tf.set(t),n.texturePerObjectInstanceMatrices._textureData.set(Tf,16*e),this._deferredSetFlagsActive?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectInstanceMatrices._texture),r.texSubImage2D(r.TEXTURE_2D,0,e%512*4,Math.floor(e/512),4,1,r.RGBA,r.FLOAT,Tf))}},{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,Xs.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.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,Xs.PICK))}},{key:"drawPickDepths",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,Xs.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,Xs.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,Xs.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,Xs.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}(),_f=$.vec4(4),Bf=$.vec4(),Of=$.vec4(),Sf=$.vec3([1,0,0]),Nf=$.vec3([0,1,0]),Lf=$.vec3([0,0,1]);$.vec3(3),$.vec3(3);var Mf=$.identityMat4(),xf=function(){function e(t){b(this,e),this._model=t.model,this.id=t.id,this._parentTransform=t.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=$.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=$.identityMat4(new Float32Array(16)),this._worldMatrix=$.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),t.parent&&t.parent._addChildTransform(this)}return P(e,[{key:"_addChildTransform",value:function(e){this._childTransforms.push(e),e._parentTransform=this,e._setWorldMatrixDirty(),e._setAABBDirty()}},{key:"_addMesh",value:function(e){this._meshes.push(e),e.transform=this}},{key:"parentTransform",get:function(){return this._parentTransform}},{key:"meshes",get:function(){return this._meshes}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.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._model.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._model.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.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||Mf),$.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"rotate",value:function(e,t){return _f[0]=e[0],_f[1]=e[1],_f[2]=e[2],_f[3]=t*$.DEGTORAD,$.angleAxisToQuaternion(_f,Bf),$.mulQuaternions(this.quaternion,Bf,Of),this.quaternion=Of,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return _f[0]=e[0],_f[1]=e[1],_f[2]=e[2],_f[3]=t*$.DEGTORAD,$.angleAxisToQuaternion(_f,Bf),$.mulQuaternions(Bf,this.quaternion,Bf),this}},{key:"rotateX",value:function(e){return this.rotate(Sf,e)}},{key:"rotateY",value:function(e){return this.rotate(Nf,e)}},{key:"rotateZ",value:function(e){return this.rotate(Lf,e)}},{key:"translate",value:function(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateX",value:function(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateY",value:function(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateZ",value:function(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._transformDirty()}},{key:"_transformDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._childTransforms.length;e<t;e++){var n=this._childTransforms[e];if(n._transformDirty(),n._meshes&&n._meshes.length>0)for(var r=n._meshes,i=0,a=r.length;i<a;i++)r[i]._transformDirty()}if(this._meshes&&this._meshes.length>0)for(var s=this._meshes,o=0,l=s.length;o<l;o++)s[o]._transformDirty()}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentTransform)$.mulMat4(this._parentTransform.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_setSubtreeAABBsDirty",value:function(e){if(e._aabbDirty=!0,e._childTransforms)for(var t=0,n=e._childTransforms.length;t<n;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}]),e}(),Ff=$.vec3();$.mat4();var Hf=$.OBB3(),Uf=$.vec3([1,1,1]),Gf=$.vec3([0,0,0]),kf=$.vec3([0,0,0]),jf=$.identityQuaternion(),Vf=$.identityMat4(),Qf=new Uint8Array([255,255,255]),Wf=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))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!1,r._vboBatchingLayerScratchMemory=Ys(),r._textureTranscoder=i.textureTranscoder||Yu(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._transforms={},r._meshes={},r._entities={},r._scheduledMeshes={},r.renderFlags=new Gi,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._meshesWithDirtyMatrices=[],r._numMeshesWithDirtyMatrices=0,r._onTick=r.scene.on("tick",(function(){for(;r._numMeshesWithDirtyMatrices>0;)r._meshesWithDirtyMatrices[--r._numMeshesWithDirtyMatrices]._updateMatrix()})),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:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"_createDefaultTextureSet",value:function(){var e=new Fu({id:"defaultColorTexture",texture:new ba({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new Fu({id:"defaultMetalRoughTexture",texture:new ba({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new Fu({id:"defaultNormalsTexture",texture:new ba({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new Fu({id:"defaultEmissiveTexture",texture:new ba({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new Fu({id:"defaultOcclusionTexture",texture:new ba({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 xu({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"transforms",get:function(){return this._transforms}},{key:"textures",get:function(){return this._textures}},{key:"textureSets",get:function(){return this._textureSets}},{key:"meshes",get:function(){return this._meshes}},{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._sceneModelDirty(),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._sceneModelDirty(),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._sceneModelDirty(),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||Vf),$.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._sceneModelDirty(),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,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._sceneModelDirty()}},{key:"worldMatrix",get:function(){return this.matrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrix}},{key:"viewMatrix",get:function(){return this._viewMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&($.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),this._viewMatrix):this.scene.camera.viewMatrix}},{key:"viewNormalMatrix",get:function(){return this._viewNormalMatrix?(this._matrixDirty&&(this._rebuildMatrices(),this._viewMatrixDirty=!0),this._viewMatrixDirty&&($.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),$.inverseMat4(this._viewMatrix,this._viewNormalMatrix),$.transposeMat4(this._viewNormalMatrix),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}},{key:"backfaces",get:function(){return this._backfaces},set:function(e){e=!!e,this._backfaces=e,this.glRedraw()}},{key:"entityList",get:function(){return this._entityList}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return!1}},{key:"aabb",get:function(){if(this._aabbDirty){$.collapseAABB3(this._aabb);for(var e=0,t=this._entityList.length;e<t;e++)$.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"numLines",get:function(){return this._numLines}},{key:"numPoints",get:function(){return this._numPoints}},{key:"visible",get:function(){return this.numVisibleLayerPortions>0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].visible=e;this.glRedraw()}},{key:"xrayed",get:function(){return this.numXRayedLayerPortions>0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].xrayed=e;this.glRedraw()}},{key:"highlighted",get:function(){return this.numHighlightedLayerPortions>0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].highlighted=e;this.glRedraw()}},{key:"selected",get:function(){return this.numSelectedLayerPortions>0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].selected=e;this.glRedraw()}},{key:"edges",get:function(){return this.numEdgesLayerPortions>0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].edges=e;this.glRedraw()}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].culled=e;this.glRedraw()}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].clippable=e;this.glRedraw()}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].collidable=e}},{key:"pickable",get:function(){return this.numPickableLayerPortions>0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].pickable=e}},{key:"colorize",get:function(){return this._colorize},set:function(e){this._colorize=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].colorize=e}},{key:"opacity",get:function(){return this._opacity},set:function(e){this._opacity=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].opacity=e}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}},{key:"saoEnabled",get:function(){return this._saoEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!1}},{key:"xrayMaterial",get:function(){return this.scene.xrayMaterial}},{key:"highlightMaterial",get:function(){return this.scene.highlightMaterial}},{key:"selectedMaterial",get:function(){return this.scene.selectedMaterial}},{key:"edgeMaterial",get:function(){return this.scene.edgeMaterial}},{key:"getPickViewMatrix",value:function(e){return this._viewMatrix?this._viewMatrix:e}},{key:"createQuantizationRange",value:function(e){void 0!==e.id&&null!==e.id?e.aabb?this.error("[createQuantizationRange] Config missing: aabb"):this._quantizationRanges[e.id]?this.error("[createQuantizationRange] QuantizationRange already created: "+e.id):this._quantizationRanges[e.id]={id:e.id,aabb:e.aabb,matrix:No(e.aabb,$.mat4())}:this.error("[createQuantizationRange] Config missing: id")}},{key:"createGeometry",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._geometries[e.id])this.error("[createGeometry] Geometry already created: "+e.id);else 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){if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.positionsDecodeMatrix&&e.positionsDecodeBoundary)return this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')"),null;if(!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error("[createGeometry] Param expected: indices (required for '".concat(e.primitive,"' primitive type)")),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=No(e.positionsDecodeBoundary,$.mat4())),e.positions){var t=$.collapseAABB3();e.positionsDecodeMatrix=$.mat4(),$.expandAABB3Points3(t,e.positions),e.positionsCompressed=So(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){var n=$.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),$.expandAABB3Points3(n,e.positionsCompressed),Dn.decompressAABB(n,e.positionsDecodeMatrix),e.aabb=n}else if(e.buckets){var r=$.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(var i=0,a=e.buckets.length;i<a;i++){var s=e.buckets[i];s.positions?$.expandAABB3Points3(r,s.positions):s.positionsCompressed&&$.expandAABB3Points3(r,s.positionsCompressed)}e.positionsDecodeMatrix&&Dn.decompressAABB(r,e.positionsDecodeMatrix),e.aabb=r}if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var o=e.colors,l=new Uint8Array(o.length),u=0,c=o.length;u<c;u++)l[u]=255*o[u];e.colorsCompressed=l}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=yn(e.positions,e.indices,null,5):e.edgeIndices=yn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){var f=Dn.getUVBounds(e.uv),p=Dn.compressUVs(e.uv,f.min,f.max);e.uvCompressed=p.quantized,e.uvDecodeMatrix=p.decodeMatrix}else e.uvCompressed&&(e.uvCompressed=new Uint16Array(e.uvCompressed),e.uvDecodeMatrix=new Float64Array(e.uvDecodeMatrix));e.normals&&(e.normals=null),this._geometries[e.id]=e,this._numTriangles+=e.indices?Math.round(e.indices.length/3):0,this.numGeometries++}else this.error("[createGeometry] Unsupported value for 'primitive': '".concat(e.primitive,"' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'."));else this.error("[createGeometry] Config missing: id")}},{key:"createTexture",value:function(e){var t=this,n=e.id;if(null!=n)if(this._textures[n])this.error("[createTexture] Texture already created: "+n);else{if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;var r=e.minFilter||1008;1006!==r&&1007!==r&&1008!==r&&1005!==r&&1004!==r&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),r=1008);var i=e.magFilter||1006;1006!==i&&1003!==i&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),i=1006);var a=e.wrapS||1e3;1001!==a&&1002!==a&&1e3!==a&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),a=1e3);var s=e.wrapT||1e3;1001!==s&&1002!==s&&1e3!==s&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),s=1e3);var o=e.wrapR||1e3;1001!==o&&1002!==o&&1e3!==o&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),o=1e3);var l=e.encoding||3e3;3e3!==l&&3001!==l&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),l=3e3);var u=new ba({gl:this.scene.canvas.gl,minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,encoding:l});if(e.preloadColor&&u.setPreloadColor(e.preloadColor),e.image){var c=e.image;c.crossOrigin="Anonymous",u.setImage(c,{minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,flipY:e.flipY,encoding:l})}else if(e.src){var f=e.src.split(".").pop();switch(f){case"jpeg":case"jpg":case"png":case"gif":var p=new Image;p.onload=function(){u.setImage(p,{minFilter:r,magFilter:i,wrapS:a,wrapT:s,wrapR:o,flipY:e.flipY,encoding:l}),t.glRedraw()},p.src=e.src;break;default:this._textureTranscoder?le.loadArraybuffer(e.src,(function(e){e.byteLength?t._textureTranscoder.transcode([e],u).then((function(){t.glRedraw()})):t.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error("[createTexture] Can't create texture from 'src': ".concat(e))})):this.error("[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('".concat(f,"')"))}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,u).then((function(){t.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[n]=new Fu({id:n,texture:u})}else this.error("[createTexture] Config missing: id")}},{key:"createTextureSet",value:function(e){var t=e.id;if(null!=t){if(!this._textureSets[t]){var n,r,i,a,s;if(void 0!==e.colorTextureId&&null!==e.colorTextureId){if(!(n=this._textures[e.colorTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.colorTextureId," - ensure that you create it first with createTexture()"))}else n=this._textures.defaultColorTexture;if(void 0!==e.metallicRoughnessTextureId&&null!==e.metallicRoughnessTextureId){if(!(r=this._textures[e.metallicRoughnessTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.metallicRoughnessTextureId," - ensure that you create it first with createTexture()"))}else r=this._textures.defaultMetalRoughTexture;if(void 0!==e.normalsTextureId&&null!==e.normalsTextureId){if(!(i=this._textures[e.normalsTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(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]))return void this.error("[createTextureSet] Texture not found: ".concat(e.emissiveTextureId," - ensure that you create it first with createTexture()"))}else a=this._textures.defaultEmissiveTexture;if(void 0!==e.occlusionTextureId&&null!==e.occlusionTextureId){if(!(s=this._textures[e.occlusionTextureId]))return void this.error("[createTextureSet] Texture not found: ".concat(e.occlusionTextureId," - ensure that you create it first with createTexture()"))}else s=this._textures.defaultOcclusionTexture;var o=new xu({id:t,model:this,colorTexture:n,metallicRoughnessTexture:r,normalsTexture:i,emissiveTexture:a,occlusionTexture:s});return this._textureSets[t]=o,o}this.error("[createTextureSet] Texture set already created: ".concat(t))}else this.error("[createTextureSet] Config missing: id")}},{key:"createTransform",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._transforms[e.id])this.error("[createTransform] SceneModel already has a transform with this ID: ".concat(e.id));else{var t;if(!this.parentTransformId||(t=this._transforms[e.parentTransformId])){var n=new xf({id:e.id,model:this,parentTransform:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[n.id]=n,n}this.error("[createTransform] SceneModel.createTransform() config missing: id")}else this.error("[createTransform] SceneModel.createTransform() config missing: id")}},{key:"createMesh",value:function(e){if(void 0!==e.id&&null!==e.id){if(!this._scheduledMeshes[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': '".concat(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 '".concat(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;var t=!!this._dtxEnabled&&("triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive);if(e.origin=e.origin?$.addVec3(this._origin,e.origin,$.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){var n=e.scale||Uf,r=e.position||Gf,i=e.rotation||kf;$.eulerToQuaternion(i,"XYZ",jf),e.meshMatrix=$.composeMat4(r,jf,n,$.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=No(e.positionsDecodeBoundary,$.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])]):Qf,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){var a=$.vec3(),s=[];Se(e.positions,s,a)&&(e.positions=s,e.origin=$.addVec3(e.origin,a,a))}if(e.positions){var o=$.collapseAABB3();e.positionsDecodeMatrix=$.mat4(),$.expandAABB3Points3(o,e.positions),e.positionsCompressed=So(e.positions,o,e.positionsDecodeMatrix),e.aabb=o}else if(e.positionsCompressed){var l=$.collapseAABB3();$.expandAABB3Points3(l,e.positionsCompressed),Dn.decompressAABB(l,e.positionsDecodeMatrix),e.aabb=l}if(e.buckets){for(var u=$.collapseAABB3(),c=0,f=e.buckets.length;c<f;c++){var p=e.buckets[c];p.positions?$.expandAABB3Points3(u,p.positions):p.positionsCompressed&&$.expandAABB3Points3(u,p.positionsCompressed)}e.positionsDecodeMatrix&&Dn.decompressAABB(u,e.positionsDecodeMatrix),e.aabb=u}e.meshMatrix&&($.AABB3ToOBB3(e.aabb,Hf),$.transformOBB3(e.meshMatrix,Hf),$.OBB3ToAABB3(Hf,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=yn(e.positions,e.indices,null,2):e.edgeIndices=yn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=zf(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){var A=[];Se(e.positions,A,Ff)&&(e.positions=A,e.origin=$.addVec3(e.origin,Ff,$.vec3()))}if(e.positions){var d=$.collapseAABB3();e.meshMatrix&&($.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),$.expandAABB3Points3(d,e.positions),e.aabb=d}else{var v=$.collapseAABB3();$.expandAABB3Points3(v,e.positionsCompressed),Dn.decompressAABB(v,e.positionsDecodeMatrix),e.aabb=v}if(e.meshMatrix&&($.AABB3ToOBB3(e.aabb,Hf),$.transformOBB3(e.meshMatrix,Hf),$.OBB3ToAABB3(Hf,e.aabb)),e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=yn(e.positions,e.indices,null,2):e.edgeIndices=yn(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: ".concat(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: ".concat(e.geometryId," - ensure that you create it first with createGeometry()"));if(e.origin=e.origin?$.addVec3(this._origin,e.origin,$.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.transformId){if(e.transform=this._transforms[e.transformId],!e.transform)return void this.error("[createMesh] Transform not found: ".concat(e.transformId," - ensure that you create it first with createTransform()"));e.aabb=e.geometry.aabb}else{if(e.matrix)e.meshMatrix=e.matrix.slice();else{var h=e.scale||Uf,I=e.position||Gf,y=e.rotation||kf;$.eulerToQuaternion(y,"XYZ",jf),e.meshMatrix=$.composeMat4(I,jf,h,$.mat4())}$.AABB3ToOBB3(e.geometry.aabb,Hf),$.transformOBB3(e.meshMatrix,Hf),e.aabb=$.OBB3ToAABB3(Hf,$.AABB3())}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])]):Qf,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;var m=this._dtxBuckets[e.geometryId];m||(m=zf(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=m),e.buckets=m}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])]):Qf,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])}return e.numPrimitives=this._getNumPrimitives(e),this._createMesh(e)}this.error("[createMesh] SceneModel already has a mesh with this ID: ".concat(e.id))}else this.error("[createMesh] SceneModel.createMesh() config missing: id")}},{key:"_createMesh",value:function(e){var t=new Ws(this,e.id,e.color,e.opacity,e.transform,e.textureSet);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.solid="solid"===e.primitive,t.origin=$.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e),t.aabb=e.aabb;break;case 1:t.layer=this._getVBOBatchingLayer(e),t.aabb=e.aabb;break;case 0:t.layer=this._getVBOInstancingLayer(e),t.aabb=e.aabb}return e.transform&&(e.meshMatrix=e.transform.worldMatrix),t.portionId=t.layer.createPortion(e),this._meshes[e.id]=t,this._meshList.push(t),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<r;n++)t+=e.buckets[n].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/3);case"points":switch(e.type){case 2:for(var i=0,a=e.buckets.length;i<a;i++)t+=e.buckets[i].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:var s=e.geometry;t+=s.positions?s.positions.length:s.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(var o=0,l=e.buckets.length;o<l;o++)t+=e.buckets[o].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}},{key:"_getDTXLayer",value:function(e){var t=e.origin,n="".concat(Math.round(t[0]),".").concat(Math.round(t[1]),".").concat(Math.round(t[2])),r=this._dtxLayers[n];if(r){if(r.canCreatePortion(e))return r;r.finalize(),delete this._dtxLayers[n],r=null}return r=new Cf(this,{layerIndex:0,origin:t}),this._dtxLayers[n]=r,this.layerList.push(r),r}},{key:"_getVBOBatchingLayer",value:function(e){var t=this,n=e.origin,r=e.positionsDecodeMatrix||e.positionsDecodeBoundary?this._createHashStringFromMatrix(e.positionsDecodeMatrix||e.positionsDecodeBoundary):"-",i=e.textureSetId||"-",a="".concat(Math.round(n[0]),".").concat(Math.round(n[1]),".").concat(Math.round(n[2]),".").concat(e.primitive,".").concat(r,".").concat(i),s=this._vboBatchingLayers[a];if(s)return s;for(var o=e.textureSet;!s;){switch(e.primitive){case"triangles":case"solid":case"surface":s=new sl({model:t,textureSet:o,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize,solid:"solid"===e.primitive,autoNormals:!0});break;case"lines":s=new ru({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":s=new gu({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize})}var l=e.positionsCompressed?e.positionsCompressed.length:e.positions.length;("points"===e.primitive?s.canCreatePortion(l):s.canCreatePortion(l,e.indices.length))||(s.finalize(),delete this._vboBatchingLayers[a],s=null)}return this._vboBatchingLayers[a]=s,this.layerList.push(s),s}},{key:"_createHashStringFromMatrix",value:function(e){for(var t=e.join(""),n=0,r=0;r<t.length;r++){n=(n<<5)-n+t.charCodeAt(r),n|=0}return(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":s=new Jl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":s=new Jl({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":s=new pu({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":s=new Mu({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;this._visible&&!1!==e.visible&&(t|=Me),this._pickable&&!1!==e.pickable&&(t|=Fe),this._culled&&!1!==e.culled&&(t|=xe),this._clippable&&!1!==e.clippable&&(t|=He),this._collidable&&!1!==e.collidable&&(t|=Ue),this._edges&&!1!==e.edges&&(t|=Ve),this._xrayed&&!1!==e.xrayed&&(t|=Ge),this._highlighted&&!1!==e.highlighted&&(t|=ke),this._selected&&!1!==e.selected&&(t|=je),e.flags=t,this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],n=0,r=e.meshIds.length;n<r;n++){var i=e.meshIds[n],a=this._meshes[i];a?a.parent?this.error('Mesh with ID "'.concat(i,'" already belongs to object with ID "').concat(a.parent.id,'" - ignoring this mesh')):t.push(a):this.error('Mesh with this ID not found: "'.concat(i,'" - ignoring this mesh'))}var s=new ze(this,e.isObject,e.id,t,e.flags,!0);this._entityList.push(s),this._entities[e.id]=s,this.numEntities++}},{key:"finalize",value:function(){if(!this.destroyed){for(var e=0,t=this.layerList.length;e<t;e++){this.layerList[e].finalize()}this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._dtxLayers={},this._vboInstancingLayers={},this._vboBatchingLayers={};for(var n=0,r=this._entityList.length;n<r;n++){this._entityList[n]._finalize()}for(var i=0,a=this._entityList.length;i<a;i++){this._entityList[i]._finalize2()}this.layerList.sort((function(e,t){return e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0}));for(var s=0,o=this.layerList.length;s<o;s++){this.layerList[s].layerIndex=s}this.glRedraw(),this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position}}},{key:"stateSortCompare",value:function(e,t){}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&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;t<n;t++){var r=this.layerList[t];this._getActiveSectionPlanesForLayer(r)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,n=this.scene._sectionPlanesState.sectionPlanes,r=n.length,i=e.layerIndex*r;if(r>0)for(var a=0;a<r;a++){n[a].active?(t.sectionPlanesActivePerLayer[i+a]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[i+a]=!1}return!0}},{key:"_updateRenderFlags",value:function(){if(0!==this.numVisibleLayerPortions&&this.numCulledLayerPortions!==this.numPortions){var e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(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.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(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;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawColorOpaque(t,e)}}},{key:"drawColorTransparent",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawColorTransparent(t,e)}}},{key:"drawDepth",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawDepth(t,e)}}},{key:"drawNormals",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawNormals(t,e)}}},{key:"drawSilhouetteXRayed",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteXRayed(t,e)}}},{key:"drawSilhouetteHighlighted",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteHighlighted(t,e)}}},{key:"drawSilhouetteSelected",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawSilhouetteSelected(t,e)}}},{key:"drawEdgesColorOpaque",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesColorOpaque(t,e)}}},{key:"drawEdgesColorTransparent",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesColorTransparent(t,e)}}},{key:"drawEdgesXRayed",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesXRayed(t,e)}}},{key:"drawEdgesHighlighted",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesHighlighted(t,e)}}},{key:"drawEdgesSelected",value:function(e){for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawEdgesSelected(t,e)}}},{key:"drawOcclusion",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawOcclusion(t,e)}}},{key:"drawShadow",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawShadow(t,e)}}},{key:"setPickMatrices",value:function(e,t){if(0!==this._numVisibleLayerPortions)for(var n=this.renderFlags,r=0,i=n.visibleLayers.length;r<i;r++){var a=n.visibleLayers[r],s=this.layerList[a];s.setPickMatrices&&s.setPickMatrices(e,t)}}},{key:"drawPickMesh",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickMesh(t,e)}}},{key:"drawPickDepths",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickDepths(t,e)}}},{key:"drawPickNormals",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n];this.layerList[i].drawPickNormals(t,e)}}},{key:"drawSnapInitDepthBuf",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n],a=this.layerList[i];a.drawSnapInitDepthBuf&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,a.drawSnapInitDepthBuf(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}},{key:"drawSnapDepths",value:function(e){if(0!==this.numVisibleLayerPortions)for(var t=this.renderFlags,n=0,r=t.visibleLayers.length;n<r;n++){var i=t.visibleLayers[n],a=this.layerList[i];a.drawSnapDepths&&(e.snapPickOrigin=[0,0,0],e.snapPickCoordinateScale=[1,1,1],e.snapPickLayerNumber++,a.drawSnapDepths(t,e),e.snapPickLayerParams[e.snapPickLayerNumber]={origin:e.snapPickOrigin.slice(),coordinateScale:e.snapPickCoordinateScale.slice()})}}},{key:"destroy",value:function(){for(var e in this._vboBatchingLayers)this._vboBatchingLayers.hasOwnProperty(e)&&this._vboBatchingLayers[e].destroy();for(var t in this._vboBatchingLayers={},this._vboInstancingLayers)this._vboInstancingLayers.hasOwnProperty(t)&&this._vboInstancingLayers[t].destroy();this._vboInstancingLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(var r=0,i=this.layerList.length;r<i;r++)this.layerList[r].destroy();this.layerList=[];for(var a=0,s=this._entityList.length;a<s;a++)this._entityList[a]._destroy();this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),0!==Ks&&0==--Ks&&zs._clear(),v(E(n.prototype),"destroy",this).call(this)}}]),n}();function zf(e,t,n){var r,i,a,s;if(t||n){var o=p(Zu({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}),3);r=o[0],i=o[1],a=o[2]}else r=e.positionsCompressed,i=e.indices,a=e.edgeIndices;n?s=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=tc(e.indices||[],t),a=ic(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<<t))return[e];var u=new Int32Array(l);u.fill(-1);var c=[];function f(){u.fill(-1);var e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:c.length};return c.push(e),e}for(var p=f(),A=0,d=i.length;A<d;A+=3){var v=0,h=i[A],I=i[A+1],y=i[A+2];if(-1===u[h]&&v++,-1===u[I]&&v++,-1===u[y]&&v++,v+p.numPositions>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,E=2*r.length+(i.length+a.length)*w,T=0;return r.length,c.forEach((function(e){T+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),T>E?[e]:(n&&ac(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 Kf=function(e){I(n,Wf);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)}(),Yf=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))._skyboxMesh=new Ji(g(r),{geometry:new Cn(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 Nn(g(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Ba(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}(),Xf=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),qf=$.vec4(),Jf=$.vec4(),Zf=$.vec3(),$f=$.vec3(),ep=$.vec3(),tp=$.vec4(),np=$.vec4(),rp=$.vec4(),ip=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"dollyToCanvasPos",value:function(e,t,n){var r=!1,i=this._scene.camera;if(e){var a=$.subVec3(e,i.eye,Zf);r=$.lenVec3(a)<n}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-n;var s=this._unproject(t,tp),o=$.subVec3(s,i.eye,rp),l=$.mulVec3Scalar($.normalizeVec3(o),-n,[]);if(i.eye=[i.eye[0]-l[0],i.eye[1]-l[1],i.eye[2]-l[2]],i.look=[i.look[0]-l[0],i.look[1]-l[1],i.look[2]-l[2]],e){var u=$.subVec3(e,i.eye,Zf),c=$.lenVec3(u),f=$.mulVec3Scalar($.normalizeVec3($.subVec3(i.look,i.eye,$f)),c);i.look=[i.eye[0]+f[0],i.eye[1]+f[1],i.eye[2]+f[2]]}}else if("ortho"===i.projection){var p=this._unproject(t,tp);i.ortho.scale=i.ortho.scale-n,i.ortho._update();var A=this._unproject(t,np),d=$.subVec3(A,p,rp),v=$.mulVec3Scalar($.normalizeVec3($.subVec3(i.look,i.eye,Zf)),-n,$f),h=$.addVec3(d,v,ep);i.eye=[i.eye[0]-h[0],i.eye[1]-h[1],i.eye[2]-h[2]],i.look=[i.look[0]-h[0],i.look[1]-h[1],i.look[2]-h[2]]}return r}},{key:"_unproject",value:function(e,t){var n=this._scene.camera,r=n.project.transposedMatrix,i=r.subarray(8,12),a=r.subarray(12),s=[0,0,-1,1],o=$.dotVec4(s,i)/$.dotVec4(s,a);return n.project.unproject(e,o,qf,Jf,t),t}},{key:"destroy",value:function(){}}]),e}(),ap=$.vec3(),sp=$.vec3(),op=$.vec3(),lp=$.vec4(),up=$.vec4(),cp=$.vec4(),fp=function(){function e(t,n){var r=this;b(this,e),this._scene=t,this._configs=n,this._pivotWorldPos=$.vec3(),this._cameraOffset=$.vec3(),this._azimuth=0,this._polar=0,this._radius=0,this._pivotPosSet=!1,this._pivoting=!1,this._shown=!1,this._pivotSphereEnabled=!1,this._pivotSphere=null,this._pivotSphereSize=1,this._pivotSphereGeometry=null,this._pivotSphereMaterial=null,this._rtcCenter=$.vec3(),this._rtcPos=$.vec3(),this._pivotViewPos=$.vec4(),this._pivotProjPos=$.vec4(),this._pivotCanvasPos=$.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(function(){r._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(function(){r._cameraDirty=!0})),this._onTick=this._scene.on("tick",(function(){r.updatePivotElement(),r.updatePivotSphere()}))}return P(e,[{key:"createPivotSphere",value:function(){var e=this.getPivotPos(),t=$.vec3();$.decomposeMat4($.inverseMat4(this._scene.viewer.camera.viewMatrix,$.mat4()),t,$.vec4(),$.vec3());var n=$.distVec3(t,e),r=Math.tan(Math.PI/500)*n*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(r/=this._scene.camera.ortho.scale/2),Oe(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new La(this._scene,ea({radius:r})),this._pivotSphere=new Ji(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}},{key:"destroyPivotSphere",value:function(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}},{key:"updatePivotElement",value:function(){var e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){$.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,$.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);var n=t.boundary,r=n[2],i=n[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*r/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);var a=t._lastBoundingClientRect;if(!a||t._canvasSizeChanged){var s=t.canvas;a=t._lastBoundingClientRect=s.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}}},{key:"updatePivotSphere",value:function(){this._pivoting&&this._pivotSphere&&(Oe(this.getPivotPos(),this._rtcCenter,this._rtcPos),$.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}},{key:"setPivotElement",value:function(e){this._pivotElement=e}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&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 Nn(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,ap)),n=$.cross3Vec3(t,e.worldUp,sp);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=lp;t.project.unproject(e,o,up,cp,l);var u=$.normalizeVec3($.subVec3(l,t.eye,ap)),c=$.addVec3(t.eye,$.mulVec3Scalar(u,n,sp),op);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}(),pp=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._lastHash=null,this._needFireEvents=0}return P(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var n=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});n&&(n.snappedToEdge||n.snappedToVertex)?(this.snapPickResult=n,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var r=this.pickResult.canvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,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 i=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(i[0]===this.pickCursorPos[0]&&i[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!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++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}}},{key:"fireEvents",value:function(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new It;e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=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=0}}}]),e}(),Ap=$.vec2(),dp=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,Ap);var t=Ap[0],i=Ap[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:Ap,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var E=1/60,T=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==T?t-T:0;T=t,n>.05&&(n=.05),n<E&&(n=E);var s=Math.max(-1,Math.min(1,40*-e.deltaY));if(0!==s){var o=s/Math.abs(s);a.dollyDelta+=-o*n*r.mouseWheelDollyRate,h&&(i.followPointerDirty=!0,h=!1)}}},{passive:!0})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler),document.removeEventListener("keyup",this._documentKeyUpHandler),e.removeEventListener("mousedown",this._mouseDownHandler),document.removeEventListener("mousemove",this._documentMouseMoveHandler),e.removeEventListener("mousemove",this._canvasMouseMoveHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("wheel",this._mouseWheelHandler)}}]),e}(),vp=$.vec3(),hp=$.vec3(),Ip=$.vec3(),yp=$.vec3(),mp=$.vec3(),wp={eye:$.vec3(),look:$.vec3(),up:$.vec3()},gp=function(){function e(t,n,r,i){b(this,e),this._scene=t;var a=n.cameraControl,s=t.camera;this._onSceneKeyDown=t.input.on("keydown",(function(){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var e=a._isKeyDownForAction(a.AXIS_VIEW_RIGHT),o=a._isKeyDownForAction(a.AXIS_VIEW_BACK),l=a._isKeyDownForAction(a.AXIS_VIEW_LEFT),u=a._isKeyDownForAction(a.AXIS_VIEW_FRONT),c=a._isKeyDownForAction(a.AXIS_VIEW_TOP),f=a._isKeyDownForAction(a.AXIS_VIEW_BOTTOM);if(e||o||l||u||c||f){var p=t.aabb,A=$.getAABB3Diag(p);$.getAABB3Center(p,vp);var d=Math.abs(A/Math.tan(n.cameraFlight.fitFOV*$.DEGTORAD)),v=1.1*A;wp.orthoScale=v,e?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldRight,d,hp),mp)),wp.look.set(vp),wp.up.set(s.worldUp)):o?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldForward,d,hp),mp)),wp.look.set(vp),wp.up.set(s.worldUp)):l?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldRight,-d,hp),mp)),wp.look.set(vp),wp.up.set(s.worldUp)):u?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldForward,-d,hp),mp)),wp.look.set(vp),wp.up.set(s.worldUp)):c?(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldUp,d,hp),mp)),wp.look.set(vp),wp.up.set($.normalizeVec3($.mulVec3Scalar(s.worldForward,1,Ip),yp))):f&&(wp.eye.set($.addVec3(vp,$.mulVec3Scalar(s.worldUp,-d,hp),mp)),wp.look.set(vp),wp.up.set($.normalizeVec3($.mulVec3Scalar(s.worldForward,-1,Ip)))),!r.firstPerson&&r.followPointer&&n.pivotController.setPivotPos(vp),n.cameraFlight.duration>0?n.cameraFlight.flyTo(wp,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(wp),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}(),Ep=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})},d=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverEnter"),l=u.hasSubs("hoverOut"),p=u.hasSubs("hoverOff"),A=u.hasSubs("hoverSurface"),d=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A||d)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=A,o.scheduleSnapOrPick=d,o.update(),o.pickResult){if(o.pickResult.entity){var v=o.pickResult.entity.id;s._lastPickedEntityId!==v&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=v)}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("mousemove",d),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}(),Tp=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),E=l._isKeyDownForAction(l.PAN_RIGHT,o),T=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||E||T||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:T&&(a.panDeltaY+=-D),E?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}(),bp=$.vec3(),Dp=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,bp)));f=n/r.dollyProximityThreshold}f<r.dollyMinSpeed&&(f=r.dollyMinSpeed)}var A=a.dollyDelta*f;if(0===a.rotateDeltaY&&0===a.rotateDeltaX||(!r.firstPerson&&r.followPointer&&l.getPivoting()?(l.continuePivot(a.rotateDeltaY,a.rotateDeltaX),l.showPivot()):(0!==a.rotateDeltaX&&(r.firstPerson?s.pitch(-a.rotateDeltaX):s.orbitPitch(a.rotateDeltaX)),0!==a.rotateDeltaY&&(r.firstPerson?s.yaw(a.rotateDeltaY):s.orbitYaw(a.rotateDeltaY))),a.rotateDeltaX*=r.rotationInertia,a.rotateDeltaY*=r.rotationInertia,e="grabbing"),Math.abs(a.panDeltaX)<.001&&(a.panDeltaX=0),Math.abs(a.panDeltaY)<.001&&(a.panDeltaY=0),Math.abs(a.panDeltaZ)<.001&&(a.panDeltaZ=0),0!==a.panDeltaX||0!==a.panDeltaY||0!==a.panDeltaZ){var d,v,h=$.vec3();if(h[0]=a.panDeltaX,h[1]=a.panDeltaY,h[2]=a.panDeltaZ,r.constrainVertical){s.xUp?(d=s.eye[0],v=s.look[0]):s.yUp?(d=s.eye[1],v=s.look[1]):s.zUp&&(d=s.eye[2],v=s.look[2]),s.pan(h);var I=s.eye,y=s.look;s.xUp?(I[0]=d,y[0]=v):s.yUp?(I[1]=d,y[1]=v):s.zUp&&(I[2]=d,y[2]=v),s.eye=I,s.look=y}else s.pan(h);e="grabbing"}if(a.panDeltaX*=r.panInertia,a.panDeltaY*=r.panInertia,a.panDeltaZ*=r.panInertia,0!==A){if(e=A<0?"zoom-in":"zoom-out",r.firstPerson){var m,w;if(r.constrainVertical&&(s.xUp?(m=s.eye[0],w=s.look[0]):s.yUp?(m=s.eye[1],w=s.look[1]):s.zUp&&(m=s.eye[2],w=s.look[2])),r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.pan([0,0,A]),s.ortho.scale=s.ortho.scale-A;if(r.constrainVertical){var g=s.eye,E=s.look;s.xUp?(g[0]=m,E[0]=w):s.yUp?(g[1]=m,E[1]=w):s.zUp&&(g[2]=m,E[2]=w),s.eye=g,s.look=E}}else if(r.planView){if(r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.ortho.scale=s.ortho.scale+A,s.zoom(A)}else{if(r.followPointer)u.dollyToCanvasPos(p,i.pointerCanvasPos,-A)&&(i.followPointerDirty=!0);else s.ortho.scale=s.ortho.scale+A,s.zoom(A)}a.dollyDelta*=r.dollyInertia}o.fireEvents(),document.body.style.cursor=e}}))}return P(e,[{key:"destroy",value:function(){this._scene.off(this._onTick)}}]),e}(),Pp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=this._scene.canvas.canvas;s.addEventListener("mouseenter",this._mouseEnterHandler=function(){i.mouseover=!0}),s.addEventListener("mouseleave",this._mouseLeaveHandler=function(){i.mouseover=!1,s.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=function(e){Rp(e,s,i.pointerCanvasPos)}),s.addEventListener("mousedown",this._mouseDownHandler=function(e){r.active&&r.pointerEnabled&&(Rp(e,s,i.pointerCanvasPos),i.mouseover=!0)}),s.addEventListener("mouseup",this._mouseUpHandler=function(e){r.active&&r.pointerEnabled})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var 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)}}]),e}();function Rp(e,t,n){if(e){var r=t.getBoundingClientRect(),i=r.x,a=r.y;n[0]=e.clientX-i,n[1]=e.clientY-a}else e=window.event,n[0]=e.x,n[1]=e.y;return n}var Cp=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},_p=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=n.pickController,o=n.pivotController,l=$.vec2(),u=$.vec2(),c=$.vec2(),f=$.vec2(),p=[],A=this._scene.canvas.canvas,d=0,v=!1;this._onTick=t.on("tick",(function(){v=!1})),A.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){e.preventDefault();var n=e.touches,a=e.changedTouches;for(i.touchStartTime=Date.now(),1===n.length&&1===a.length&&(Cp(n[0],l),r.followPointer&&(s.pickCursorPos=l,s.schedulePickSurface=!0,s.update(),r.planView||(s.picked&&s.pickedSurface&&s.pickResult&&s.pickResult.worldPos?(o.setPivotPos(s.pickResult.worldPos),!r.firstPerson&&o.startPivot()&&o.showPivot()):(r.smartPivot?o.setCanvasPivotPos(i.pointerCanvasPos):o.setPivotPos(t.camera.look),!r.firstPerson&&o.startPivot()&&o.showPivot()))));p.length<n.length;)p.push($.vec2());for(var u=0,c=n.length;u<c;++u)Cp(n[u],p[u]);d=n.length}}),A.addEventListener("touchend",this._canvasTouchEndHandler=function(){o.getPivoting()&&o.endPivot()}),A.addEventListener("touchmove",this._canvasTouchMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(e.stopPropagation(),e.preventDefault(),!v)){v=!0;var n=t.canvas.boundary,o=n[2],l=n[3],A=e.touches;if(e.touches.length===d){if(1===d){Cp(A[0],u),$.subVec2(u,p[0],f);var h=f[0],I=f[1];if(null!==i.longTouchTimeout&&(Math.abs(h)>r.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];Cp(w,u),Cp(g,c);var E=$.geometricMeanVec2(p[0],p[1]),T=$.geometricMeanVec2(u,c),b=$.vec2();$.subVec2(E,T,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=T}for(var S=0;S<d;++S)Cp(A[S],p[S])}}})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler),e.removeEventListener("touchmove",this._canvasTouchMoveHandler),this._scene.off(this._onTick)}}]),e}(),Bp=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},Op=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s,o=n.pickController,l=n.cameraControl,u=[],c=new Float32Array(2),f=-1,p=-1,A=this._scene.canvas.canvas,d=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e?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})};A.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null);var t=e.touches,a=e.changedTouches;if(s=Date.now(),1===t.length&&1===a.length){f=s,Bp(t[0],c);var o=c[0],l=c[1],p=t[0].pageX,A=t[0].pageY;i.longTouchTimeout=setTimeout((function(){n.cameraControl.fire("rightClick",{pagePos:[Math.round(p),Math.round(A)],canvasPos:[Math.round(o),Math.round(l)],event:e},!0),i.longTouchTimeout=null}),r.longTapTimeout)}else f=-1;for(;u.length<t.length;)u.push(new Float32Array(2));for(var d=0,v=t.length;d<v;++d)Bp(t[d],u[d]);u.length=t.length}},{passive:!0}),A.addEventListener("touchend",this._canvasTouchEndHandler=function(e){if(r.active&&r.pointerEnabled){var t=Date.now(),n=e.touches,a=e.changedTouches,s=l.hasSubs("pickedSurface");null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),0===n.length&&1===a.length&&f>-1&&t-f<150&&(p>-1&&f-p<325?(Bp(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&&(Bp(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;A<v;++A)u[A][0]=n[A].pageX,u[A][1]=n[A].pageY}},{passive:!0})}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}]),e}(),Sp=function(e){I(n,ye);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)).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 pp(g(r),r._configs),pivotController:new fp(a,r._configs),panController:new ip(a),cameraFlight:new ws(g(r),{duration:.5})},r._handlers=[new Pp(r.scene,r._controllers,r._configs,r._states,r._updates),new _p(r.scene,r._controllers,r._configs,r._states,r._updates),new dp(r.scene,r._controllers,r._configs,r._states,r._updates),new gp(r.scene,r._controllers,r._configs,r._states,r._updates),new Ep(r.scene,r._controllers,r._configs,r._states,r._updates),new Op(r.scene,r._controllers,r._configs,r._states,r._updates),new Tp(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new Dp(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",le.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;r<i;r++){if(t[n[r]])return!0}return!1}},{key:"pivotElement",set:function(e){this._controllers.pivotController.setPivotElement(e)}},{key:"active",get:function(){return this._configs.active},set:function(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}},{key:"snapToVertex",get:function(){return this._configs.snapToVertex},set:function(e){this._configs.snapToVertex=!!e}},{key:"snapToEdge",get:function(){return this._configs.snapToEdge},set:function(e){this._configs.snapToEdge=!!e}},{key:"snapRadius",get:function(){return this._configs.snapRadius},set:function(e){e=e||30,this._configs.snapRadius=e}},{key:"navMode",get:function(){return this._configs.navMode},set:function(e){"firstPerson"!==(e=e||"orbit")&&"orbit"!==e&&"planView"!==e&&(this.error("Unsupported value for navMode: "+e+" - supported values are 'orbit', 'firstPerson' and 'planView' - defaulting to 'orbit'"),e="orbit"),this._configs.firstPerson="firstPerson"===e,this._configs.planView="planView"===e,(this._configs.firstPerson||this._configs.planView)&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this._configs.navMode=e}},{key:"pointerEnabled",get:function(){return this._configs.pointerEnabled},set:function(e){this._reset(),this._configs.pointerEnabled=!!e}},{key:"_reset",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.reset&&n.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}},{key:"followPointer",get:function(){return this._configs.followPointer},set:function(e){this._configs.followPointer=!1!==e}},{key:"pivotPos",get:function(){return this._controllers.pivotController.getPivotPos()},set:function(e){this._controllers.pivotController.setPivotPos(e)}},{key:"dollyToPointer",get:function(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer},set:function(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}},{key:"panToPointer",get:function(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1},set:function(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}},{key:"planView",get:function(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView},set:function(e){this._configs.planView=!!e,this._configs.firstPerson=!1,this._configs.planView&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this.warn("planView property is deprecated - replaced with navMode")}},{key:"firstPerson",get:function(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson},set:function(e){this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson=!!e,this._configs.planView=!1,this._configs.firstPerson&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot())}},{key:"constrainVertical",get:function(){return this._configs.constrainVertical},set:function(e){this._configs.constrainVertical=!!e}},{key:"doublePickFlyTo",get:function(){return this._configs.doublePickFlyTo},set:function(e){this._configs.doublePickFlyTo=!1!==e}},{key:"panRightClick",get:function(){return this._configs.panRightClick},set:function(e){this._configs.panRightClick=!1!==e}},{key:"rotationInertia",get:function(){return this._configs.rotationInertia},set:function(e){this._configs.rotationInertia=null!=e?e:0}},{key:"keyboardPanRate",get:function(){return this._configs.keyboardPanRate},set:function(e){this._configs.keyboardPanRate=null!=e?e:5}},{key:"touchPanRate",get:function(){return this._configs.touchPanRate},set:function(e){this._configs.touchPanRate=null!=e?e:1}},{key:"keyboardRotationRate",get:function(){return this._configs.keyboardRotationRate},set:function(e){this._configs.keyboardRotationRate=null!=e?e:90}},{key:"dragRotationRate",get:function(){return this._configs.dragRotationRate},set:function(e){this._configs.dragRotationRate=null!=e?e:360}},{key:"keyboardDollyRate",get:function(){return this._configs.keyboardDollyRate},set:function(e){this._configs.keyboardDollyRate=null!=e?e:15}},{key:"touchDollyRate",get:function(){return this._configs.touchDollyRate},set:function(e){this._configs.touchDollyRate=null!=e?e:.2}},{key:"mouseWheelDollyRate",get:function(){return this._configs.mouseWheelDollyRate},set:function(e){this._configs.mouseWheelDollyRate=null!=e?e:100}},{key:"dollyInertia",get:function(){return this._configs.dollyInertia},set:function(e){this._configs.dollyInertia=null!=e?e:0}},{key:"dollyProximityThreshold",get:function(){return this._configs.dollyProximityThreshold},set:function(e){this._configs.dollyProximityThreshold=null!=e?e:35}},{key:"dollyMinSpeed",get:function(){return this._configs.dollyMinSpeed},set:function(e){this._configs.dollyMinSpeed=null!=e?e:.04}},{key:"panInertia",get:function(){return this._configs.panInertia},set:function(e){this._configs.panInertia=null!=e?e:.5}},{key:"keyboardLayout",get:function(){return this._configs.keyboardLayout},set:function(e){"qwerty"!==(e=e||"qwerty")&&"azerty"!==e&&(this.error("Unsupported value for keyboardLayout - defaulting to 'qwerty'"),e="qwerty"),this._configs.keyboardLayout=e,this.keyMap=this._configs.keyboardLayout}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&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(E(n.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.destroy&&n.destroy()}}},{key:"_destroyControllers",value:function(){for(var e=0,t=this._controllers.length;e<t;e++){var n=this._controllers[e];n.destroy&&n.destroy()}}}]),n}(),Np=P((function e(t,n,r,i,a){b(this,e),this.name=t,this.type=r,this.value=n,this.valueType=i,this.description=a})),Lp=P((function e(t){if(b(this,e),this.id=t.id,this.originalSystemId=t.originalSystemId,this.metaModels=[],this.name=t.name,this.type=t.type,this.properties=[],t.properties)for(var n=t.properties,r=0,i=n.length;r<i;r++){var a=n[r];this.properties.push(new Np(a.name,a.value,a.type,a.valueType,a.description))}})),Mp=function(){function e(t){b(this,e),this.metaModels=[],this.id=t.id,this.parentId=t.parentId,this.parent=null,this.originalSystemId=t.originalSystemId,this.name=t.name,this.type=t.type,this.propertySetIds=t.propertySetIds,this.propertySets=[],this.attributes=t.attributes||{},void 0!==t.external&&null!==t.external&&(this.external=t.external)}return P(e,[{key:"metaModel",get:function(){return 1==this.metaModels.length?this.metaModels[0]:null}},{key:"getObjectIDsInSubtree",value:function(){var e=[];return function t(n){if(n){e.push(n.id);var r=n.children;if(r)for(var i=0,a=r.length;i<a;i++)t(r[i])}}(this),e}},{key:"withMetaObjectsInSubtree",value:function(e){!function t(n){if(n){e(n);var r=n.children;if(r)for(var i=0,a=r.length;i<a;i++)t(r[i])}}(this)}},{key:"getObjectIDsInSubtreeByType",value:function(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=e[n];var i=[];return function e(n){if(n){t[n.type]&&i.push(n.id);var r=n.children;if(r)for(var a=0,s=r.length;a<s;a++)e(r[a])}}(this),i}},{key:"getJSON",value:function(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}]),e}(),xp=function(){function e(t){b(this,e),this.id=t.id,this.projectId=t.projectId,this.revisionId=t.revisionId,this.author=t.author,this.createdAt=t.createdAt,this.creatingApplication=t.creatingApplication,this.schema=t.schema,this.metaScene=t.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects=[],this.graph=t.graph||{},this.metaScene.metaModels[this.id]=this,this.finalized=!1}return P(e,[{key:"rootMetaObject",get:function(){return 1==this.rootMetaObjects.length?this.rootMetaObjects[0]:null}},{key:"loadData",value:function(e){var t=arguments.length>1&&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,r=e.properties;if(e.propertySets)for(var i=0,a=e.propertySets.length;i<a;i++){var s=e.propertySets[i],o=n.propertySets[s.id];o||(r&&this._decompressProperties(r,s.properties),o=new Lp({id:s.id,originalSystemId:s.originalSystemId||s.id,type:s.type,name:s.name,properties:s.properties}),n.propertySets[o.id]=o),o.metaModels.push(this),this.propertySets.push(o)}if(e.metaObjects)for(var l=0,u=e.metaObjects.length;l<u;l++){var c=e.metaObjects[l],f=c.id,p=n.metaObjects[f];if(!p){var A=c.type,d=c.originalSystemId,v=c.propertySets||c.propertySetIds;p=new Mp({id:f,originalSystemId:d,parentId:c.parent,type:A,name:c.name,attributes:c.attributes,propertySetIds:v,external:c.external}),this.metaScene.metaObjects[f]=p}p.metaModels.push(this),c.parent||(this.rootMetaObjects.push(p),n.rootMetaObjects[f]=p),this.metaObjects.push(p)}}},{key:"_decompressProperties",value:function(e,t){for(var n=0,r=t.length;n<r;n++){var i=t[n];if(Number.isInteger(i)){var a=e[i];a&&(t[n]=a)}}}},{key:"finalize",value:function(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";var e=this.metaScene;for(var t in e.metaObjects){var n=e.metaObjects[t];if(n.children&&(n.children=[]),n.propertySets&&(n.propertySets=[]),n.propertySetIds)for(var r=0,i=n.propertySetIds.length;r<i;r++){var a=n.propertySetIds[r],s=e.propertySets[a];n.propertySets.push(s)}}for(var o in e.metaObjects){var l=e.metaObjects[o];if(l.parentId){var u=e.metaObjects[l.parentId];u&&(l.parent=u,(u.children||(u.children=[])).push(l))}}for(var c in e.metaObjectsByType={},e.metaObjects){var f=e.metaObjects[c],p=f.type;(e.metaObjectsByType[p]||(e.metaObjectsByType[p]={}))[c]=f}this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}},{key:"getJSON",value:function(){for(var e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]},t=0,n=this.metaObjects.length;t<n;t++){var r=this.metaObjects[t],i={id:r.id,originalSystemId:r.originalSystemId,extId:r.extId,type:r.type,name:r.name};r.parent&&(i.parent=r.parent.id),r.attributes&&(i.attributes=r.attributes),r.propertySetIds&&(i.propertySetIds=r.propertySetIds),e.metaObjects.push(i)}for(var a=0,s=this.propertySets.length;a<s;a++){for(var o=this.propertySets[a],l={id:o.id,originalSystemId:o.originalSystemId,extId:o.extId,type:o.type,name:o.name,propertyies:[]},u=0,c=o.properties.length;u<c;u++){var f=o.properties[u],p={id:f.id,description:f.description,type:f.type,name:f.name,value:f.value,valueType:f.valueType};l.properties.push(p)}e.propertySets.push(l)}return e}},{key:"_globalizeIDs",value:function(e,t){var n=!!t.globalizeObjectIds;if(e.metaObjects)for(var r=0,i=e.metaObjects.length;r<i;r++){var a=e.metaObjects[r];if(a.originalSystemId=a.id,a.parent&&(a.originalParentSystemId=a.parent),n&&(a.id=$.globalizeObjectId(this.id,a.id),a.parent&&(a.parent=$.globalizeObjectId(this.id,a.parent))),n){var s=a.propertySetIds;if(s){for(var o=[],l=0,u=s.length;l<u;l++)o.push($.globalizeObjectId(this.id,s[l]));a.propertySetIds=o,a.originalSystemPropertySetIds=s}}else a.originalSystemPropertySetIds=a.propertySetIds}if(e.propertySets)for(var c=0,f=e.propertySets.length;c<f;c++){var p=e.propertySets[c];p.originalSystemId=p.id,n&&(p.id=$.globalizeObjectId(this.id,p.id))}}}]),e}(),Fp=function(){function e(t,n){b(this,e),this.viewer=t,this.scene=n,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}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;r<i;r++)n[r](t)}},{key:"off",value:function(e){}},{key:"createMetaModel",value:function(e,t){var n=new xp({metaScene:this,id:e,projectId:t.projectId||"none",revisionId:t.revisionId||"none",author:t.author||"none",createdAt:t.createdAt||"none",creatingApplication:t.creatingApplication||"none",schema:t.schema||"none",propertySets:[]});return n.loadData(t),n.finalize(),n}},{key:"destroyMetaModel",value:function(e){var t=this.metaModels[e];if(t){if(t.propertySets)for(var n=0,r=t.propertySets.length;n<r;n++){var i=t.propertySets[n];if(1===i.metaModels.length)delete this.propertySets[i.id];else{for(var a=[],s=0,o=i.metaModels.length;s<o;s++)i.metaModels[s].id!==e&&a.push(i.metaModels[s]);i.metaModels=a}}if(t.metaObjects)for(var l=0,u=t.metaObjects.length;l<u;l++){var c=t.metaObjects[l];c.type;var f=c.id;if(1===c.metaModels.length)delete this.metaObjects[f],c.parent||delete this.rootMetaObjects[f];else{for(var p=[],A=t.id,d=0,v=c.metaModels.length;d<v;d++)c.metaModels[d].id!==A&&p.push(c.metaModels[d]);c.metaModels=p}}for(var h in this.metaObjects){var I=this.metaObjects[h];if(I.children&&(I.children=[]),I.propertySets&&(I.propertySets=[]),I.propertySetIds)for(var y=0,m=I.propertySetIds.length;y<m;y++){var w=I.propertySetIds[y],g=this.propertySets[w];I.propertySets.push(g)}}for(var E in this.metaObjectsByType={},this.metaObjects){var T=this.metaObjects[E],b=T.type;T.children&&(T.children=null),(this.metaObjectsByType[b]||(this.metaObjectsByType[b]={}))[E]=T}for(var D in this.metaObjects){var P=this.metaObjects[D];if(P.parentId){var R=this.metaObjects[P.parentId];R&&(P.parent=R,(R.children||(R.children=[])).push(P))}}delete this.metaModels[e],this.fire("metaModelDestroyed",e)}}},{key:"getObjectIDsByType",value:function(e){var t=this.metaObjectsByType[e];return t?Object.keys(t):[]}},{key:"getObjectIDsInSubtree",value:function(e,t,n){var r=[],i=this.metaObjects[e],a=t&&t.length>0?Hp(t):null,s=n&&n.length>0?Hp(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<l;o++)e(i[o])}}(i),r}},{key:"withMetaObjectsInSubtree",value:function(e,t){var n=this.metaObjects[e];n&&n.withMetaObjectsInSubtree(t)}}]),e}();function Hp(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=!0;return t}
18
18
  /*!
19
19
  * html2canvas 1.4.1 <https://html2canvas.hertzen.com>
20
20
  * Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>