@xeokit/xeokit-sdk 2.4.0-alpha-84 → 2.4.0-alpha-85

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.
@@ -23,7 +23,7 @@ function Kn(e,t){t.length;for(var n=e.length,r=[],i=[],a=function(n){var a=e[n];
23
23
  /**
24
24
  * @author https://github.com/tmarti, with support from https://tribia.com/
25
25
  * @license MIT
26
- **/var yc=null;function mc(e,t){var n,r,i,a,s,o,l=3*e,u=3*t,c=Math.min(n=yc[l],r=yc[l+1],i=yc[l+2]),f=Math.min(a=yc[u],s=yc[u+1],o=yc[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 wc(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r<i;r++)n[r]=r;yc=new Int32Array(e.length);for(var a=0,s=e.length;a<s;a++)yc[a]=e[a]>>t;n.sort(mc);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 gc=null;function Tc(e,t){var n=gc[2*e]-gc[2*t];return 0!==n?n:gc[2*e+1]-gc[2*t+1]}function Ec(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}gc=new Int32Array(e),t.sort(Tc);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 bc(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 Dc=Z.vec3(),Pc=Z.vec3(),Rc=Z.vec3(),Cc=Z.vec3(),_c=Z.vec4(),Bc=Z.mat4(),Oc=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._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Dc;if(v){var y=Z.transformPoint3(f,u,Pc);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=Ie(i.viewMatrix,I,Bc),(d=Rc)[0]=i.eye[0]-I[0],d[1]=i.eye[1]-I[1],d[2]=i.eye[2]-I[2]}else A=i.viewMatrix,d=i.eye;if(s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s.uniform3fv(this._uCameraEyeRtc,d),s.uniform1i(this._uRenderPass,n),r.logarithmicDepthBufferEnabled){var m=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,m)}var w=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b<w;b++){var D=this._uSectionPlanes[b];if(D){var P=E.sectionPlanesActivePerLayer[T+b];if(s.uniform1i(D.active,P?1:0),P){var R=g[b];if(u){var C=ge(R.dist,R.dir,u,Cc);s.uniform3fv(D.pos,C)}else s.uniform3fv(D.pos,R.pos);s.uniform3fv(D.dir,R.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uRenderPass=r.getLocation("renderPass"),this._uLightAmbient=r.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var i=n.lights,a=0,s=i.length;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._uSceneModelWorldMatrix=r.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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;_c[0]=c,_c[1]=f,_c[2]=u.blendCutoff,_c[3]=u.blendFactor,n.uniform4fv(this._uSAOParams,_c),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.sectionPlanes.length>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;"),t.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("uniform mat4 sceneModelWorldMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),a.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),a.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),a.push("uniform highp sampler2D uTextureModelMatrices;"),a.push("uniform vec3 uCameraEyeRtc;"),a.push("vec3 positions[3];"),t.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("out float isPerspective;")),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("uniform vec4 lightAmbient;");for(var s=0,o=r.lights.length;s<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 (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),a.push("if (int(flags.x) != renderPass) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("} else {"),a.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),a.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),a.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),a.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),a.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),a.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),a.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),a.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),a.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),a.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),a.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),a.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),a.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),a.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),a.push("if (color.a == 0u) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("};"),a.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),a.push("vec3 position;"),a.push("position = positions[gl_VertexID % 3];"),a.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),a.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("} else {"),a.push("if (viewNormal.z < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("}"),a.push("}"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),a.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),a.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(var l=0,u=r.lights.length;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.sectionPlanes.length>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.sectionPlanes.length;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.sectionPlanes.length;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}(),Sc=new Float32Array([1,1,1]),Nc=Z.vec3(),Lc=Z.vec3(),xc=Z.vec3(),Mc=Z.vec3(),Fc=Z.mat4(),Hc=function(){function e(t,n){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=this._scene,i=r.camera,a=t.model,s=r.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=a.position,f=a.rotationMatrix,p=a.rotationMatrixConjugate,A=i.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var d,v;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,o)),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=Nc;if(u){var I=Lc;Z.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=Ie(A,h,Fc),(v=xc)[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===to.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===to.SILHOUETTE_HIGHLIGHTED){var g=r.highlightMaterial._state,T=g.fillColor,E=g.fillAlpha;s.uniform4f(this._uColor,T[0],T[1],T[2],E)}else if(n===to.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,Sc);if(r.logarithmicDepthBufferEnabled){var R=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,R)}var C=r._sectionPlanesState.sectionPlanes.length;if(C>0)for(var _=r._sectionPlanesState.sectionPlanes,B=t.layerIndex*C,O=a.renderFlags,S=0;S<C;S++){var N=this._uSectionPlanes[S];if(N){var L=O.sectionPlanesActivePerLayer[B+S];if(s.uniform1i(N.active,L?1:0),L){var x=_[S];if(u){var M=ge(x.dist,x.dir,u,Mc);s.uniform3fv(N.pos,M)}else s.uniform3fv(N.pos,x.pos);s.uniform3fv(N.dir,x.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uColor=n.getLocation("color"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.y) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("uniform vec4 color;"),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.sectionPlanes.length;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;"),r.push(" outColor = color;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Uc=new Float32Array([0,0,0,1]),Gc=Z.vec3(),kc=Z.vec3();Z.vec3();var jc=Z.vec3(),Vc=Z.mat4(),Qc=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Gc;if(v){var y=kc;Z.transformPoint3(f,u,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],d=Ie(A,I,Vc)}else d=A;if(s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),n===to.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===to.EDGES_HIGHLIGHTED){var T=i.highlightMaterial._state,E=T.edgeColor,b=T.edgeAlpha;s.uniform4f(this._uColor,E[0],E[1],E[2],b)}else if(n===to.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,Uc);var C=i._sectionPlanesState.sectionPlanes.length;if(C>0)for(var _=i._sectionPlanesState.sectionPlanes,B=t.layerIndex*C,O=r.renderFlags,S=0;S<C;S++){var N=this._uSectionPlanes[S];if(N){var L=O.sectionPlanesActivePerLayer[B+S];if(s.uniform1i(N.active,L?1:0),L){var x=_[S];if(u){var M=ge(x.dist,x.dir,u,jc);s.uniform3fv(N.pos,M)}else s.uniform3fv(N.pos,x.pos);s.uniform3fv(N.dir,x.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uColor=n.getLocation("color"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets"}}},{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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.z) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),e.logarithmicDepthBufferEnabled&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i<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.sectionPlanes.length;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) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Wc=Z.vec3(),zc=Z.vec3(),Kc=Z.vec3(),Yc=Z.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=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=a.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Wc;if(v){var y=zc;Z.transformPoint3(f,u,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],d=Ie(A,I,Yc)}else d=A;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var m=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=r.renderFlags,E=0;E<m;E++){var b=this._uSectionPlanes[E];if(b){var D=T.sectionPlanesActivePerLayer[g+E];if(s.uniform1i(b.active,D?1:0),D){var P=w[E];if(u){var R=ge(P.dist,P.dir,u,Kc);s.uniform3fv(b.pos,R)}else s.uniform3fv(b.pos,P.pos);s.uniform3fv(b.dir,P.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets"}}},{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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.z) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vec4 rgb = vec4(color.rgba);"),n.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// TrianglesDataTextureEdgesColorRenderer"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i<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.sectionPlanes.length;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) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),qc=Z.vec3(),Jc=Z.vec3(),Zc=Z.vec3(),$c=Z.mat4(),ef=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate;c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==f[0]||0!==f[1]||0!==f[2],h=0!==p[0]||0!==p[1]||0!==p[2];if(v||h){var I=qc;if(v){var y=Z.transformPoint3(A,f,Jc);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=Ie(o.viewMatrix,I,$c),(i=Zc)[0]=o.eye[0]-I[0],i[1]=o.eye[1]-I[1],i[2]=o.eye[2]-I[2]}else r=o.viewMatrix,i=o.eye;if(l.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix),l.uniform3fv(this._uCameraEyeRtc,i),l.uniform1i(this._uRenderPass,n),s.logarithmicDepthBufferEnabled){var m=2/(Math.log(o.project.far+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,m)}var w=s._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=s._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b<w;b++){var D=this._uSectionPlanes[b];if(D){var P=E.sectionPlanesActivePerLayer[T+b];if(l.uniform1i(D.active,P?1:0),P){var R=g[b];if(f){var C=ge(R.dist,R.dir,f,qc);l.uniform3fv(D.pos,C)}else l.uniform3fv(D.pos,R.pos);l.uniform3fv(D.dir,R.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._withSAO&&(this._uOcclusionTexture="uOcclusionTexture",this._uSAOParams=n.getLocation("uSAOParams")),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("smooth out vec4 vWorldPosition;"),n.push("flat out uvec4 vFlags2;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uvec4 vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outPickColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (float(vFlags2.x) > 0.0);"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i<t.sectionPlanes.length;i++)r.push(" if (sectionPlaneActive"+i+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outPickColor = vPickColor; "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),tf=Z.vec3(),nf=Z.vec3(),rf=Z.vec3(),af=Z.vec3(),sf=Z.mat4(),of=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate,v=e.pickViewMatrix||o.viewMatrix;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),f||0!==p[0]||0!==p[1]||0!==p[2]){var h=tf;if(f){var I=nf;Z.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=Ie(v,h,sf),(i=rf)[0]=o.eye[0]-h[0],i[1]=o.eye[1]-h[1],i[2]=o.eye[2]-h[2],e.snapPickOrigin[0]=h[0],e.snapPickOrigin[1]=h[1],e.snapPickOrigin[2]=h[2]}else r=v,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(l.uniform3fv(this._uCameraEyeRtc,i),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniform1f(this._uPickZNear,e.pickZNear),l.uniform1f(this._uPickZFar,e.pickZFar),l.uniformMatrix4fv(this._uWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix),s.logarithmicDepthBufferEnabled){var y=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,y)}var m=s._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=s._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=a.renderFlags,E=0;E<m;E++){var b=this._uSectionPlanes[E];if(b){var D=T.sectionPlanesActivePerLayer[g+E];if(l.uniform1i(b.active,D?1:0),D){var P=w[E];if(f){var R=ge(P.dist,P.dir,f,af);l.uniform3fv(b.pos,R)}else l.uniform3fv(b.pos,P.pos);l.uniform3fv(b.dir,P.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureCameraMatrices="uTextureCameraMatrices",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outPackedDepth;"),r.push("void main(void) {"),n){r.push(" bool clippable = vFlags2 > 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i<t.sectionPlanes.length;i++)r.push(" if (sectionPlaneActive"+i+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outPackedDepth = packDepth(zNormalizedDepth); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),lf=Z.vec3(),uf=Z.vec3(),cf=Z.vec3(),ff=Z.vec3(),pf=Z.vec3(),Af=Z.mat4(),df=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=lf;I[0]=Z.safeInv(v[3]-v[0])*Z.MAX_INT,I[1]=Z.safeInv(v[4]-v[1])*Z.MAX_INT,I[2]=Z.safeInv(v[5]-v[2])*Z.MAX_INT,e.snapPickCoordinateScale[0]=Z.safeInv(I[0]),e.snapPickCoordinateScale[1]=Z.safeInv(I[1]),e.snapPickCoordinateScale[2]=Z.safeInv(I[2]),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var y=0!==f[0]||0!==f[1]||0!==f[2],m=0!==p[0]||0!==p[1]||0!==p[2];if(y||m){var w=uf;if(y){var g=Z.transformPoint3(A,f,cf);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=Ie(h,w,Af),(i=ff)[0]=o.eye[0]-w[0],i[1]=o.eye[1]-w[1],i[2]=o.eye[2]-w[2],e.snapPickOrigin[0]=w[0],e.snapPickOrigin[1]=w[1],e.snapPickOrigin[2]=w[2]}else r=h,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,i),l.uniform2fv(this.uVectorA,e.snapVectorA),l.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,I),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var T=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,T);var E=s._sectionPlanesState.sectionPlanes.length;if(E>0)for(var b=s._sectionPlanesState.sectionPlanes,D=t.layerIndex*E,P=a.renderFlags,R=0;R<E;R++){var C=this._uSectionPlanes[R];if(C){var _=P.sectionPlanesActivePerLayer[D+R];if(l.uniform1i(C.active,_?1:0),_){var B=b[R];if(f){var O=ge(B.dist,B.dir,f,pf);l.uniform3fv(C.pos,O)}else l.uniform3fv(C.pos,B.pos);l.uniform3fv(C.dir,B.dir)}}}var S="edge"===e.snapMode?l.LINES:l.POINTS;u.numEdgeIndices8Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),l.drawArrays(S,0,u.numEdgeIndices8Bits)),u.numEdgeIndices16Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),l.drawArrays(S,0,u.numEdgeIndices16Bits)),u.numEdgeIndices32Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),l.drawArrays(S,0,u.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 uSnapVectorA;"),n.push("uniform vec2 uSnapInvVectorAB;"),n.push("vec3 positions[3];"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),n.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vViewPosition;"),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),n.push("vViewPosition = clipPos;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("gl_PointSize = 1.0;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int uLayerNumber;"),n.push("uniform vec3 uCoordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e.sectionPlanes.length;r<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.sectionPlanes.length;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}(),vf=Z.vec3(),hf=Z.vec3(),If=Z.vec3(),yf=Z.vec3(),mf=Z.vec3(),wf=Z.mat4(),gf=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=vf;I[0]=Z.safeInv(v[3]-v[0])*Z.MAX_INT,I[1]=Z.safeInv(v[4]-v[1])*Z.MAX_INT,I[2]=Z.safeInv(v[5]-v[2])*Z.MAX_INT,e.snapPickCoordinateScale[0]=Z.safeInv(I[0]),e.snapPickCoordinateScale[1]=Z.safeInv(I[1]),e.snapPickCoordinateScale[2]=Z.safeInv(I[2]),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var y=0!==f[0]||0!==f[1]||0!==f[2],m=0!==p[0]||0!==p[1]||0!==p[2];if(y||m){var w=hf;if(y){var g=If;Z.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=Ie(h,w,wf),(i=yf)[0]=o.eye[0]-w[0],i[1]=o.eye[1]-w[1],i[2]=o.eye[2]-w[2],e.snapPickOrigin[0]=w[0],e.snapPickOrigin[1]=w[1],e.snapPickOrigin[2]=w[2]}else r=h,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,i),l.uniform2fv(this._uVectorA,e.snapVectorA),l.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,I),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var T=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,T);var E=s._sectionPlanesState.sectionPlanes.length;if(E>0)for(var b=s._sectionPlanesState.sectionPlanes,D=t.layerIndex*E,P=a.renderFlags,R=0;R<E;R++){var C=this._uSectionPlanes[R];if(C){var _=P.sectionPlanesActivePerLayer[D+R];if(l.uniform1i(C.active,_?1:0),_){var B=b[R];if(f){var O=ge(B.dist,B.dir,f,mf);l.uniform3fv(C.pos,O)}else l.uniform3fv(C.pos,B.pos);l.uniform3fv(C.dir,B.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 uVectorAB;"),n.push("uniform vec2 uInverseVectorAB;"),n.push("vec3 positions[3];"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),n.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" viewNormal = -viewNormal;"),n.push(" }"),n.push(" } else {"),n.push(" if (viewNormal.z < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" viewNormal = -viewNormal;"),n.push(" }"),n.push(" }"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureSnapDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int uLayerNumber;"),n.push("uniform vec3 uCoordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e.sectionPlanes.length;r<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.sectionPlanes.length;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}(),Tf=Z.vec3(),Ef=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var c=a.eye;e.pickViewMatrix&&(l.bindPickCameraTexture(this._program,this._uTextureCameraMatrices),c=e.pickOrigin||c);var f=[c[0]-u[0],c[1]-u[1],c[2]-u[2]];if(s.uniform3fv(this._uCameraEyeRtc,f),s.uniform1i(this._uRenderPass,n),s.uniform3fv(this._uCameraEyeRtc,f),s.uniform1i(this._uPickInvisible,e.pickInvisible),i.logarithmicDepthBufferEnabled){var p=2/(Math.log(a.project.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,p)}var A=i._sectionPlanesState.sectionPlanes.length;if(A>0)for(var d=i._sectionPlanesState.sectionPlanes,v=t.layerIndex*A,h=r.renderFlags,I=0;I<A;I++){var y=this._uSectionPlanes[I];if(y){var m=h.sectionPlanesActivePerLayer[v+I];if(s.uniform1i(y.active,m?1:0),m){var w=d[I];if(u){var g=ge(w.dist,w.dir,u,Tf);s.uniform3fv(y.pos,g)}else s.uniform3fv(y.pos,w.pos);s.uniform3fv(y.dir,w.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureCameraMatrices="uTextureCameraMatrices",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick normals vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureCameraMatrices;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec3 vWorldNormal;"),n.push("void main(void) {"),n.push("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));"),n.push("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));"),n.push("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("normal = -normal;"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("normal = -normal;"),n.push("}"),n.push("}"),n.push("}"),n.push("normal = -normal;"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vWorldNormal = normal.xyz;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.w;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vWorldNormal;"),r.push("out vec4 outNormal;"),r.push("void main(void) {"),n){r.push(" bool clippable = vFlags2 > 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i<t.sectionPlanes.length;i++)r.push(" if (sectionPlaneActive"+i+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outNormal = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),bf=Z.vec3(),Df=Z.vec3(),Pf=Z.vec3(),Rf=Z.vec3(),Cf=Z.mat4(),_f=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=e.pickViewMatrix||a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d,v;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=bf;if(u){var I=Df;Z.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=Ie(A,h,Cf),(v=Pf)[0]=a.eye[0]-h[0],v[1]=a.eye[1]-h[1],v[2]=a.eye[2]-h[2]}else d=A,v=a.eye;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var y=i._sectionPlanesState.sectionPlanes.length;if(y>0)for(var m=i._sectionPlanesState.sectionPlanes,w=t.layerIndex*y,g=r.renderFlags,T=0;T<y;T++){var E=this._uSectionPlanes[T];if(E){var b=g.sectionPlanesActivePerLayer[w+T];if(s.uniform1i(E.active,b?1:0),b){var D=m[T];if(u){var P=ge(D.dist,D.dir,u,Rf);s.uniform3fv(E.pos,P)}else s.uniform3fv(E.pos,D.pos);s.uniform3fv(E.dir,D.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureCameraMatrices="uTextureCameraMatrices",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out vec4 vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" }"),n.push(" } else {"),n.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push(" if (viewNormal.z < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" }"),n.push(" }"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(var r=0;r<e.sectionPlanes.length;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.x) > 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i<e.sectionPlanes.length;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}(),Bf=Z.vec3(),Of=Z.vec3(),Sf=Z.vec3(),Nf=Z.vec3(),Lf=Z.mat4(),xf=function(){function e(t){b(this,e),this._scene=t,this._allocate(),this._hash=this._getHash()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=this._scene,i=r.camera,a=t.model,s=r.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=a.position,f=a.rotationMatrix,p=a.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var A,d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,o)),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Bf;if(v){var y=Z.transformPoint3(f,u,Of);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=Ie(i.viewMatrix,I,Lf),(d=Sf)[0]=i.eye[0]-I[0],d[1]=i.eye[1]-I[1],d[2]=i.eye[2]-I[2]}else A=i.viewMatrix,d=i.eye;if(s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s.uniform3fv(this._uCameraEyeRtc,d),s.uniform1i(this._uRenderPass,n),r.logarithmicDepthBufferEnabled){var m=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,m)}var w=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b<w;b++){var D=this._uSectionPlanes[b];if(D){var P=E.sectionPlanesActivePerLayer[T+b];if(s.uniform1i(D.active,P?1:0),P){var R=g[b];if(u){var C=ge(R.dist,R.dir,u,Nf);s.uniform3fv(D.pos,C)}else s.uniform3fv(D.pos,R.pos);s.uniform3fv(D.dir,R.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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;e._lightsState;var n=t.sectionPlanes.length>0,r=[];return r.push("#version 300 es"),r.push("// Triangles dataTexture draw vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("precision highp usampler2D;"),r.push("precision highp isampler2D;"),r.push("precision highp sampler2D;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("precision mediump usampler2D;"),r.push("precision mediump isampler2D;"),r.push("precision mediump sampler2D;"),r.push("#endif"),r.push("uniform int renderPass;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("uniform mat4 sceneModelWorldMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),r.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),r.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),r.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),r.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),r.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),r.push("uniform highp sampler2D uTextureModelMatrices;"),r.push("uniform vec3 uCameraEyeRtc;"),r.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("out float isPerspective;")),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out highp vec2 vHighPrecisionZW;"),n&&(r.push("out vec4 vWorldPosition;"),r.push("flat out uint vFlags2;")),r.push("void main(void) {"),r.push("int polygonIndex = gl_VertexID / 3;"),r.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),r.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),r.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),r.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),r.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),r.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),r.push("if (int(flags.x) != renderPass) {"),r.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),r.push(" return;"),r.push("} else {"),r.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),r.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),r.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),r.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),r.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),r.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),r.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),r.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),r.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),r.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),r.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),r.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),r.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),r.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),r.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),r.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),r.push("if (color.a == 0u) {"),r.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),r.push(" return;"),r.push("};"),r.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),r.push("vec3 position;"),r.push("position = positions[gl_VertexID % 3];"),r.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),r.push("if (solid != 1u) {"),r.push("if (isPerspectiveMatrix(projMatrix)) {"),r.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),r.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),r.push("position = positions[2 - (gl_VertexID % 3)];"),r.push("viewNormal = -viewNormal;"),r.push("}"),r.push("} else {"),r.push("if (viewNormal.z < 0.0) {"),r.push("position = positions[2 - (gl_VertexID % 3)];"),r.push("viewNormal = -viewNormal;"),r.push("}"),r.push("}"),r.push("}"),r.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),r.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),r.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags2 = flags2.r;")),r.push("gl_Position = clipPos;"),r.push("vHighPrecisionZW = gl_Position.zw;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),r.push("in highp vec2 vHighPrecisionZW;"),r.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(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.sectionPlanes.length;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;"),r.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),r.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Mf=Z.vec3(),Ff=Z.vec3(),Hf=Z.vec3(),Uf=Z.vec3(),Gf=Z.mat4(),kf=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=Mf;if(v){var y=Ff;Z.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=Ie(p,I,Gf),(d=Hf)[0]=a.eye[0]-I[0],d[1]=a.eye[1]-I[1],d[2]=a.eye[2]-I[2]}else A=p,d=a.eye;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,f),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),s.uniformMatrix4fv(this._uViewNormalMatrix,!1,a.viewNormalMatrix),s.uniformMatrix4fv(this._uWorldNormalMatrix,!1,r.worldNormalMatrix);var m=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=r.renderFlags,E=0;E<m;E++){var b=this._uSectionPlanes[E];if(b){var D=T.sectionPlanesActivePerLayer[g+E];if(s.uniform1i(b.active,D?1:0),D){var P=w[E];if(l){var R=ge(P.dist,P.dir,l,Uf);s.uniform3fv(b.pos,R)}else s.uniform3fv(b.pos,P.pos);s.uniform3fv(b.dir,P.dir)}}}s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,t._state.positionsDecodeMatrix),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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._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.sectionPlanes.length;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.sectionPlanes.length>0,n=[];return n.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("uniform int renderPass;"),n.push("attribute vec3 position;"),e.entityOffsetsEnabled&&n.push("attribute vec3 offset;"),n.push("attribute vec3 normal;"),n.push("attribute vec4 color;"),n.push("attribute vec4 flags;"),n.push("attribute vec4 flags2;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 worldNormalMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 viewNormalMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("varying float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out vec4 vFlags2;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&($e.SUPPORTED_EXTENSIONS.EXT_frag_depth?n.push("vFragDepth = 1.0 + clipPos.w;"):(n.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),n.push("clipPos.z *= clipPos.w;")),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in vec4 vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("void main(void) {"),n){r.push(" bool clippable = (float(vFlags2.x) > 0.0);"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&r.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),jf=Z.vec3(),Vf=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerObjectIdPositionsDecodeMatrix),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},1),this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerVertexIdCoordinates),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},2),this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerObjectIdColorsAndFlags),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},3),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible),s.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix);var u=e.pickViewMatrix||a.viewMatrix,c=l?Ie(u,l):u;if(s.uniformMatrix4fv(this._uViewMatrix,!1,c),s.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),i.logarithmicDepthBufferEnabled){var f=2/(Math.log(a.project.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,f)}var p=i._sectionPlanesState.sectionPlanes.length;if(p>0)for(var A=i._sectionPlanesState.sectionPlanes,d=t.layerIndex*p,v=r.renderFlags,h=0;h<p;h++){var I=this._uSectionPlanes[h],y=v.sectionPlanesActivePerLayer[d+h];if(s.uniform1i(I.active,y?1:0),y){var m=A[h];if(l){var w=ge(m.dist,m.dir,l,jf);s.uniform3fv(I.pos,w)}else s.uniform3fv(I.pos,m.pos);s.uniform3fv(I.dir,m.dir)}}o.numIndices8Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds8Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices8Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds16Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices16Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds32Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices32Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPackedVertexId=n.getAttribute("packedVertexId"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds"}}},{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.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick flat normals vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in uvec3 packedVertexId;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform isampler2D uTexturePerPolygonIdNormals;"),n.push("uniform usampler2D uTexturePerPolygonIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("out vec4 vWorldPosition;"),t&&n.push("out int vFlags2;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_normal_index = polygonIndex & 4095;"),n.push("int v_normal_index = polygonIndex >> 12;"),n.push("int h_packed_object_id_index = ((polygonIndex >> 3) / 2) & 4095;"),n.push("int v_packed_object_id_index = ((polygonIndex >> 3) / 2) >> 12;"),n.push("ivec3 packedObjectId = ivec3(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).rgb);"),n.push("int objectIndex;"),n.push("if (((polygonIndex >> 3) % 2) == 0) {"),n.push(" objectIndex = (packedObjectId.r << 4) + (packedObjectId.g >> 4);"),n.push("} else {"),n.push(" objectIndex = ((packedObjectId.g & 15) << 8) + packedObjectId.b;"),n.push("}"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("int h_index = polygonIndex & 4095;"),n.push("int v_index = polygonIndex >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position1 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("vec3 position2 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("vec3 position3 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(position3 - position1, position2 - position1));"),n.push("int vertexNumber = gl_VertexID % 3;"),n.push("vec3 position;"),n.push("if (vertexNumber == 0) position = position1;"),n.push("else if (vertexNumber == 1) position = position2;"),n.push("else position = position3;"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),t&&n.push(" vFlags2 = flags2.r;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick flat normals fragment shader"),r.push("#extension GL_OES_standard_derivatives : enable"),e.logarithmicDepthBufferEnabled&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in int vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outNormal;"),r.push("void main(void) {"),n){r.push(" bool clippable = vFlags2 > 0;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i<t.sectionPlanes.length;i++)r.push(" if (sectionPlaneActive"+i+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outNormal = vec4((worldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Qf=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._vertexDepthRenderer&&!this._vertexDepthRenderer.getValid()&&(this._vertexDepthRenderer.destroy(),this._vertexDepthRenderer=null),this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Oc(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new Oc(this._scene,!0)),this._colorRendererWithSAO}},{key:"colorQualityRendererWithSAO",get:function(){return this._colorQualityRendererWithSAO||(this._colorQualityRendererWithSAO=new TrianglesDataTextureColorQualityRenderer(this._scene,!0)),this._colorQualityRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Hc(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new xf(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new kf(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new Qc(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new Xc(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new ef(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Ef(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 of(this._scene)),this._pickDepthRenderer}},{key:"vertexDepthRenderer",get:function(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new df(this._scene)),this._vertexDepthRenderer}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new gf(this._scene)),this._snapDepthBufInitRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new _f(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}(),Wf={};var zf=P((function e(){b(this,e),this.positionsCompressed=[],this.metallicRoughness=[],this.indices8Bits=[],this.indices16Bits=[],this.indices32Bits=[],this.edgeIndices8Bits=[],this.edgeIndices16Bits=[],this.edgeIndices32Bits=[],this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]})),Kf=function(){function e(){b(this,e),this.texturePerObjectIdColorsAndFlags=null,this.texturePerObjectIdOffsets=null,this.texturePerObjectIdPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}return P(e,[{key:"finalize",value:function(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}},{key:"bindCommonTextures",value:function(e,t,n,r,i,a){this.texturePerObjectIdPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,n,2),this.texturePerObjectIdColorsAndFlags.bindTexture(e,r,3),this.textureModelMatrices.bindTexture(e,i,4),this.texturePerObjectIdOffsets.bindTexture(e,a,5)}},{key:"bindPickCameraTexture",value:function(e,t){}},{key:"bindTriangleIndicesTextures",value:function(e,t,n,r){this.indicesPortionIdsPerBitnessTextures[r].bindTexture(e,t,6),this.indicesPerBitnessTextures[r].bindTexture(e,n,7)}},{key:"bindEdgeIndicesTextures",value:function(e,t,n,r){this.edgeIndicesPortionIdsPerBitnessTextures[r].bindTexture(e,t,6),this.edgeIndicesPerBitnessTextures[r].bindTexture(e,n,7)}}]),e}(),Yf=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}(),Xf={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(Xf,null,4));var e=0;Object.keys(Xf).forEach((function(t){t.startsWith("size")&&(e+=Xf[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/Xf.totalPolygons).toFixed(2)));var t={};Object.keys(Xf).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((Xf[n]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var qf=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:"generateCameraDataTexture",value:function(e,t,n,r){var i=e.createTexture();e.bindTexture(e.TEXTURE_2D,i),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,4,3),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null);var a=new Yf(e,i,4,3),s=!0;a.updateViewMatrix=function(n,i){e.bindTexture(e.TEXTURE_2D,a._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,4,1,e.RGBA,e.FLOAT,new Float32Array(r?Ie(n,r):n)),e.texSubImage2D(e.TEXTURE_2D,0,0,1,4,1,e.RGBA,e.FLOAT,new Float32Array(t.viewNormalMatrix)),e.texSubImage2D(e.TEXTURE_2D,0,0,2,4,1,e.RGBA,e.FLOAT,new Float32Array(i))};var o=function(){s&&(s=!1,a.updateViewMatrix(t.viewMatrix,t.project.matrix))};return t.on("matrix",(function(){return s=!0})),n.on("rendering",o),o(),a}},{key:"generatePickCameraDataTexture",value:function(e,t,n){var r=e.createTexture();e.bindTexture(e.TEXTURE_2D,r),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,4,3),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null);var i=new Yf(e,r,4,3);return i.updateViewMatrix=function(r,a){e.bindTexture(e.TEXTURE_2D,i._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,4,1,e.RGBA,e.FLOAT,new Float32Array(n?Ie(r,n):r)),e.texSubImage2D(e.TEXTURE_2D,0,0,1,4,1,e.RGBA,e.FLOAT,new Float32Array(t.viewNormalMatrix)),e.texSubImage2D(e.TEXTURE_2D,0,0,2,4,1,e.RGBA,e.FLOAT,new Float32Array(a))},i}},{key:"generateModelTexture",value:function(e,t){var n=e.createTexture();return e.bindTexture(e.TEXTURE_2D,n),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,4,2),e.texSubImage2D(e.TEXTURE_2D,0,0,0,4,1,e.RGBA,e.FLOAT,new Float32Array(t.worldMatrix)),e.texSubImage2D(e.TEXTURE_2D,0,0,1,4,1,e.RGBA,e.FLOAT,new Float32Array(t.worldNormalMatrix)),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,n,4,2)}},{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);Xf.sizeDataColorsAndFlags+=c.byteLength,Xf.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 Yf(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);Xf.sizeDataTextureOffsets+=i.byteLength,Xf.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 Yf(e,a,n,r,i)}},{key:"generateTextureForPositionsDecodeMatrices",value:function(e,t,n){var r=t.length;if(0===r)throw"num decode+entity matrices===0";var i=2048,a=Math.ceil(r/512),s=new Float32Array(8192*a);Xf.sizeDataPositionDecodeMatrices+=s.byteLength,Xf.numberOfTextures++;for(var o=Z.mat4(),l=0;l<t.length;l++)s.set(Z.mulMat4(n[l],t[l],o),16*l);var u=e.createTexture();return e.bindTexture(e.TEXTURE_2D,u),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,i,a),e.texSubImage2D(e.TEXTURE_2D,0,0,0,i,a,e.RGBA,e.FLOAT,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 Yf(e,u,i,a)}},{key:"generateTextureFor8BitIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/3/n);if(0===r)throw"texture height===0";var i=new Uint8Array(n*r*3);Xf.sizeDataTextureIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB8UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RGB_INTEGER,e.UNSIGNED_BYTE,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor16BitIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/3/n);if(0===r)throw"texture height===0";var i=new Uint16Array(n*r*3);Xf.sizeDataTextureIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB16UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RGB_INTEGER,e.UNSIGNED_SHORT,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor32BitIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/3/n);if(0===r)throw"texture height===0";var i=new Uint32Array(n*r*3);Xf.sizeDataTextureIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RGB_INTEGER,e.UNSIGNED_INT,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor8BitsEdgeIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/2/n);if(0===r)throw"texture height===0";var i=new Uint8Array(n*r*2);Xf.sizeDataTextureEdgeIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RG8UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RG_INTEGER,e.UNSIGNED_BYTE,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor16BitsEdgeIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/2/n);if(0===r)throw"texture height===0";var i=new Uint16Array(n*r*2);Xf.sizeDataTextureEdgeIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RG16UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RG_INTEGER,e.UNSIGNED_SHORT,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor32BitsEdgeIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/2/n);if(0===r)throw"texture height===0";var i=new Uint32Array(n*r*2);Xf.sizeDataTextureEdgeIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RG32UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RG_INTEGER,e.UNSIGNED_INT,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureForPositions",value:function(e,t){var n=t.length/3,r=4096,i=Math.ceil(n/r);if(0===i)throw"texture height===0";var a=new Uint16Array(r*i*3);Xf.sizeDataTexturePositions+=a.byteLength,Xf.numberOfTextures++,a.fill(0),a.set(t,0);var s=e.createTexture();return e.bindTexture(e.TEXTURE_2D,s),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),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 Yf(e,s,r,i)}},{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),Xf.sizeDataTexturePortionIds+=a.byteLength,Xf.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 Yf(e,s,r,i)}}]),e}(),Jf=Z.vec4([0,0,0,1]),Zf=Z.vec4([0,0,0,1]);Z.vec4([0,0,0,1]);var $f=new Uint8Array(4),ep=new Float32Array(3),tp=Z.AABB3(),np=0,rp=Z.identityMat4(),ip=function(){function e(t,n){var r,i,a;b(this,e),Xf.numberOfLayers++,this._layerNumber=np++,this.sortId="TriDTX-".concat(this._layerNumber),this.layerIndex=n.layerIndex,this._dataTextureRenderers=(r=t.scene,i=r.id,(a=Wf[i])||(a=new Qf(r),Wf[i]=a,a._compile(),r.on("compile",(function(){a._compile()})),r.on("destroyed",(function(){delete Wf[i],a._destroy()}))),a),this.model=t,this._buffer=new zf,this._dataTextureState=new Kf,this._dataTextureGenerator=new qf,this._state=new Nt({origin:Z.vec3(n.origin),metallicRoughnessBuf:null,positionsDecodeMatrix:Z.mat4(),textureState:this._dataTextureState,numIndices8Bits:0,numIndices16Bits:0,numIndices32Bits:0,numEdgeIndices8Bits:0,numEdgeIndices16Bits:0,numEdgeIndices32Bits:0,numVertices:0}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._subPortions=[],this._portionToSubPortionsMap=[],this._bucketGeometries={},this.aabb=Z.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&&Xf.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)&&Xf.cannotCreatePortion.becauseTextureSize++,n&&(n=this._state.numVertices+a<=16777216&&i+s<=16777216)}return n}},{key:"createPortion",value:function(e){var t=this;if(this._finalized)throw"Already finalized";var n=[],r=e.worldAABB;e.buckets.forEach((function(i,a){var s=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(a):"".concat(e.id,"#").concat(a),o=t._bucketGeometries[s];o||(o=t._createBucketGeometry(e,i),t._bucketGeometries[s]=o);var l=Z.collapseAABB3(tp),u=t._createSubPortion(e,o,i,l);Z.expandAABB3(r,l),n.push(u)}));var i=this._state.origin;0===i[0]&&0===i[1]&&0===i[2]||(r[0]+=i[0],r[1]+=i[1],r[2]+=i[2],r[3]+=i[0],r[4]+=i[1],r[5]+=i[2]),Z.expandAABB3(this.aabb,r);var a=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(n),this.model.numPortions++,a}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var n=8*Math.ceil(t.indices.length/3/8)*3;Xf.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;Xf.overheadSizeAlignementEdgeIndices+=2*(i-t.edgeIndices.length);var a=new Uint32Array(i);a.fill(0),a.set(t.edgeIndices),t.edgeIndices=a}for(var s,o=t.positionsCompressed,l=t.indices,u=t.edgeIndices,c=this._buffer,f=c.positionsCompressed.length/3,p=o.length/3,A=0,d=o.length;A<d;A++)c.positionsCompressed.push(o[A]);var v,h=0;if(l){var I;h=l.length/3,s=(I=p<=256?c.indices8Bits:p<=65536?c.indices16Bits:c.indices32Bits).length/3;for(var y=0,m=l.length;y<m;y++)I.push(l[y])}var w=0;if(u){var g;w=u.length/2,v=(g=p<=256?c.edgeIndices8Bits:p<=65536?c.edgeIndices16Bits:c.edgeIndices32Bits).length/2;for(var T=0,E=u.length;T<E;T++)g.push(u[T])}this._state.numVertices+=p,Xf.numberOfGeometries++;var b=Z.collapseAABB3();return Z.expandAABB3Points3(b,t.positionsCompressed),An.decompressAABB(b,e.positionsDecodeMatrix),{vertexBase:f,numVertices:p,numTriangles:h,numEdges:w,indicesBase:s,edgeIndicesBase:v,aabb:b,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;if(f.perObjectPositionsDecodeMatrices.push(e.positionsDecodeMatrix),f.perObjectInstancePositioningMatrices.push(u||rp),u){t.obb||(t.obb=Z.AABB3ToOBB3(t.aabb));for(var A=t.obb,d=0,v=A.length;d<v;d+=4)Jf[0]=A[d+0],Jf[1]=A[d+1],Jf[2]=A[d+2],Jf[3]=1,u&&Z.transformPoint4(u,Jf,Zf),Z.expandAABB3Point3(r,Zf)}else Z.expandAABB3(r,t.aabb);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 h=this._subPortions.length;if(t.numTriangles>0){var I,y=3*t.numTriangles;t.numVertices<=256?(I=f.perTriangleNumberPortionId8Bits,p.numIndices8Bits+=y,Xf.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(I=f.perTriangleNumberPortionId16Bits,p.numIndices16Bits+=y,Xf.totalPolygons16Bits+=t.numTriangles):(I=f.perTriangleNumberPortionId32Bits,p.numIndices32Bits+=y,Xf.totalPolygons32Bits+=t.numTriangles),Xf.totalPolygons+=t.numTriangles;for(var m=0;m<t.numTriangles;m+=8)I.push(h)}if(t.numEdges>0){var w,g=2*t.numEdges;t.numVertices<=256?(w=f.perEdgeNumberPortionId8Bits,p.numEdgeIndices8Bits+=g,Xf.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(w=f.perEdgeNumberPortionId16Bits,p.numEdgeIndices16Bits+=g,Xf.totalEdges16Bits+=t.numEdges):(w=f.perEdgeNumberPortionId32Bits,p.numEdgeIndices32Bits+=g,Xf.totalEdges32Bits+=t.numEdges),Xf.totalEdges+=t.numEdges;for(var T=0;T<t.numEdges;T+=8)w.push(h)}return this._subPortions.push({numVertices:t.numTriangles}),this._numPortions++,Xf.numberOfPortions++,h}},{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.texturePerObjectIdColorsAndFlags=this._dataTextureGenerator.generateTextureForColorsAndFlags(r,i.perObjectColors,i.perObjectPickColors,i.perObjectVertexBases,i.perObjectIndexBaseOffsets,i.perObjectEdgeIndexBaseOffsets,i.perObjectSolid),n.texturePerObjectIdOffsets=this._dataTextureGenerator.generateTextureForObjectOffsets(r,this._numPortions),n.texturePerObjectIdPositionsDecodeMatrix=this._dataTextureGenerator.generateTextureForPositionsDecodeMatrices(r,i.perObjectPositionsDecodeMatrices,i.perObjectInstancePositioningMatrices),n.texturePerVertexIdCoordinates=this._dataTextureGenerator.generateTextureForPositions(r,i.positionsCompressed),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.indices8Bits.length>0&&(n.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(r,i.indices8Bits)),i.indices16Bits.length>0&&(n.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(r,i.indices16Bits)),i.indices32Bits.length>0&&(n.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(r,i.indices32Bits)),i.edgeIndices8Bits.length>0&&(n.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(r,i.edgeIndices8Bits)),i.edgeIndices16Bits.length>0&&(n.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(r,i.edgeIndices16Bits)),i.edgeIndices32Bits.length>0&&(n.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(r,i.edgeIndices32Bits)),this.model._modelMatricesTexture||(this.model._modelMatricesTexture=this._dataTextureGenerator.generateModelTexture(r,this.model)),n.textureModelMatrices=this.model._modelMatricesTexture,n.cameraTexture=this._dataTextureGenerator.generateCameraDataTexture(this.model.scene.canvas.gl,this.model.scene.camera,this.model.scene,this._state.origin.slice()),n.textureCameraMatrices=n.cameraTexture,n.texturePickCameraMatrices=this._dataTextureGenerator.generatePickCameraDataTexture(this.model.scene.canvas.gl,this.model.scene.camera,this._state.origin.slice()),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&Te&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&Ce&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Re&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&_e&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&De&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Be&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&be&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ee&&(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&Te?(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&Ce?(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&Re?(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&_e?(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&Be?(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&De?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}},{key:"_beginDeferredFlags",value:function(){this._deferredSetFlagsActive=!0}},{key:"_uploadDeferredFlags",value:function(){if(console.info("_uploadDeferredFlags"),this._deferredSetFlagsActive=!1,this._deferredSetFlagsDirty){this._deferredSetFlagsDirty=!1;var e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdColorsAndFlags._textureWidth,t.texturePerObjectIdColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectIdColorsAndFlags._textureData),e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdOffsets._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdOffsets._textureWidth,t.texturePerObjectIdOffsets._textureHeight,e.RGB,e.FLOAT,t.texturePerObjectIdOffsets._textureData)}}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(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&be?(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($f[0]=t[0],$f[1]=t[1],$f[2]=t[2],$f[3]=t[3],n.texturePerObjectIdColorsAndFlags._textureData.set($f,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.texturePerObjectIdColorsAndFlags._texture),r.texSubImage2D(r.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,r.RGBA_INTEGER,r.UNSIGNED_BYTE,$f)}},{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&Te),o=!!(t&Re),l=!!(t&Ce),u=!!(t&_e),c=!!(t&Be),f=!!(t&be),p=!!(t&Ee);i=!s||p||o?to.NOT_RENDERED:n?to.COLOR_TRANSPARENT:to.COLOR_OPAQUE,a=!s||p?to.NOT_RENDERED:u?to.SILHOUETTE_SELECTED:l?to.SILHOUETTE_HIGHLIGHTED:o?to.SILHOUETTE_XRAYED:to.NOT_RENDERED;var A=0;A=!s||p?to.NOT_RENDERED:u?to.EDGES_SELECTED:l?to.EDGES_HIGHLIGHTED:o?to.EDGES_XRAYED:c?n?to.EDGES_COLOR_TRANSPARENT:to.EDGES_COLOR_OPAQUE:to.NOT_RENDERED;var d=s&&f?to.PICK:to.NOT_RENDERED,v=this._dataTextureState,h=this.model.scene.canvas.gl;if($f[0]=i,$f[1]=a,$f[2]=A,$f[3]=d,v.texturePerObjectIdColorsAndFlags._textureData.set($f,32*e+8),this._deferredSetFlagsActive||r)return console.info("_subPortionSetFlags set flags defer"),void(this._deferredSetFlagsDirty=!0);++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),console.info("_subPortionSetFlags set flags write through"),h.bindTexture(h.TEXTURE_2D,v.texturePerObjectIdColorsAndFlags._texture),h.texSubImage2D(h.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,h.RGBA_INTEGER,h.UNSIGNED_BYTE,$f)}},{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&De?255:0,i=this._dataTextureState,a=this.model.scene.canvas.gl;$f[0]=r,$f[1]=0,$f[2]=1,$f[3]=2,i.texturePerObjectIdColorsAndFlags._textureData.set($f,32*e+12),this._deferredSetFlagsActive||n?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),console.info("_subPortionSetFlags2 set flags write through"),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectIdColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,$f))}},{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;ep[0]=t[0],ep[1]=t[1],ep[2]=t[2],n.texturePerObjectIdOffsets._textureData.set(ep,3*e),this._deferredSetFlagsActive?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectIdOffsets._texture),r.texSubImage2D(r.TEXTURE_2D,0,0,e,1,1,r.RGB,r.FLOAT,ep))}},{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,to.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.COLOR_OPAQUE))}},{key:"setPickMatrices",value:function(e,t){0!==this._numVisibleLayerPortions&&this._dataTextureState.texturePickCameraMatrices.updateViewMatrix(e,t)}},{key:"drawPickMesh",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickMeshRenderer&&this._dataTextureRenderers.pickMeshRenderer.drawLayer(t,this,to.PICK))}},{key:"drawPickDepths",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,to.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,to.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,to.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,to.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}(),ap=Z.vec3();Z.mat4();var sp=Z.vec3([1,1,1]),op=Z.vec3([0,0,0]),lp=Z.vec3([0,0,0]),up=Z.identityQuaternion(),cp=Z.identityMat4(),fp=new Uint8Array([255,255,255]),pp=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!0,r._vboBatchingLayerScratchMemory=eo(),r._textureTranscoder=i.textureTranscoder||Ac(r.scene.viewer),r._maxGeometryBatchSize=i.maxGeometryBatchSize,r._aabb=Z.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r._meshList=[],r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._meshes={},r._entities={},r._scheduledMeshes={},r.renderFlags=new ea,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=Z.vec3(i.origin||[0,0,0]),r._position=Z.vec3(i.position||[0,0,0]),r._rotation=Z.vec3(i.rotation||[0,0,0]),r._quaternion=Z.vec4(i.quaternion||[0,0,0,1]),r._conjugateQuaternion=Z.vec4(i.quaternion||[0,0,0,1]),i.rotation&&Z.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=Z.vec3(i.scale||[1,1,1]),r._worldRotationMatrix=Z.mat4(),r._worldRotationMatrixConjugate=Z.mat4(),r._matrix=Z.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=Z.mat4(),Z.inverseMat4(r._matrix,r._worldNormalMatrix),Z.transposeMat4(r._worldNormalMatrix),(i.matrix||i.position||i.rotation||i.scale||i.quaternion)&&(r._viewMatrix=Z.mat4(),r._viewNormalMatrix=Z.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==i.saoEnabled,r._pbrEnabled=!1!==i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r._onCameraViewMatrix=r.scene.camera.on("matrix",(function(){r._viewMatrixDirty=!0})),r.scene.vfc.enabled&&(r._vfcManager=r.scene.vfc.getVFCManager(g(r))),r._createDefaultTextureSet(),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.backfaces=i.backfaces,r}return P(n,[{key:"_createDefaultTextureSet",value:function(){var e=new nc({id:"defaultColorTexture",texture:new Ha({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new nc({id:"defaultMetalRoughTexture",texture:new Ha({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new nc({id:"defaultNormalsTexture",texture:new Ha({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new nc({id:"defaultEmissiveTexture",texture:new Ha({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new nc({id:"defaultOcclusionTexture",texture:new Ha({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 tc({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),Z.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),Z.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||cp),Z.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),Z.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),Z.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),Z.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&(Z.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),Z.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),Z.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),Z.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0}},{key:"_setLocalAABBDirty",value:function(){for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._setLocalAABBDirty()}},{key:"_setWorldAABBDirty",value:function(){this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._setWorldAABBDirty()}},{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&&(Z.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),Z.inverseMat4(this._viewMatrix,this._viewNormalMatrix),Z.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&&(Z.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),Z.inverseMat4(this._viewMatrix,this._viewNormalMatrix),Z.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),Z.inverseMat4(this._viewMatrix,this._viewNormalMatrix),Z.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){Z.collapseAABB3(this._aabb);for(var e=0,t=this._entityList.length;e<t;e++)Z.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:Uo(e.aabb,Z.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=Uo(e.positionsDecodeBoundary,Z.mat4())),e.positions){var t=Z.collapseAABB3();e.positionsDecodeMatrix=Z.mat4(),Z.expandAABB3Points3(t,e.positions),e.positionsCompressed=Ho(e.positions,t,e.positionsDecodeMatrix)}else e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed);if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var n=e.colors,r=new Uint8Array(n.length),i=0,a=n.length;i<a;i++)r[i]=255*n[i];e.colorsCompressed=r}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=sn(e.positions,e.indices,null,5):e.edgeIndices=sn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets&&(this._dtxBuckets[e.id]=e.buckets),e.uv){var s=An.getUVBounds(e.uv),o=An.compressUVs(e.uv,s.min,s.max);e.uvCompressed=o.quantized,e.uvDecodeMatrix=o.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(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 Ha({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?ae.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 nc({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])this.error("[createTextureSet] Texture set already created: ".concat(t));else{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 tc({id:t,model:this,colorTexture:n,metallicRoughnessTexture:r,normalsTexture:i,emissiveTexture:a,occlusionTexture:s});this._textureSets[t]=o}else this.error("[createTextureSet] Config missing: id")}},{key:"createMesh",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._scheduledMeshes[e.id])this.error("[createMesh] SceneModel already has a mesh with this ID: ".concat(e.id));else{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?Z.addVec3(this._origin,e.origin,Z.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){var n=e.scale||sp,r=e.position||op,i=e.rotation||lp;Z.eulerToQuaternion(i,"XYZ",up),e.meshMatrix=Z.composeMat4(r,up,n,Z.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Uo(e.positionsDecodeBoundary,Z.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])]):fp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){var a=Z.vec3(),s=[];me(e.positions,s,a)&&(e.positions=s,e.origin=Z.addVec3(e.origin,a,a))}if(e.positions){var o=Z.collapseAABB3();e.positionsDecodeMatrix=Z.mat4(),Z.expandAABB3Points3(o,e.positions),e.positionsCompressed=Ho(e.positions,o,e.positionsDecodeMatrix)}e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=sn(e.positions,e.indices,null,2):e.edgeIndices=sn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=Ap(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 l=[];me(e.positions,l,ap)&&(e.positions=l,e.origin=Z.addVec3(e.origin,ap,Z.vec3()))}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=sn(e.positions,e.indices,null,2):e.edgeIndices=sn(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?Z.addVec3(this._origin,e.origin,Z.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.matrix)e.meshMatrix=e.matrix.slice();else{var u=e.scale||sp,c=e.position||op,f=e.rotation||lp;Z.eulerToQuaternion(f,"XYZ",up),e.meshMatrix=Z.composeMat4(c,up,u,Z.mat4())}if(!!this._dtxEnabled&&("triangles"===e.geometry.primitive||"solid"===e.geometry.primitive||"surface"===e.geometry.primitive)){e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):fp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;var p=this._dtxBuckets[e.geometryId];p||(p=Ap(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=p),e.buckets=p}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])]):fp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId]),function(e){if(e.obb=Z.OBB3(),e.positionsCompressed&&e.positionsCompressed.length>0){var t=Z.collapseAABB3();Z.expandAABB3Points3(t,e.positionsCompressed),An.decompressAABB(t,e.positionsDecodeMatrix),Z.AABB3ToOBB3(t,e.obb)}else if(e.positions&&e.positions.length>0){var n=Z.collapseAABB3();Z.expandAABB3Points3(n,e.positions),Z.AABB3ToOBB3(n,e.obb)}}(e.geometry)}e.numPrimitives=this._getNumPrimitives(e),this._vfcManager&&!this._vfcManager.finalized?this._vfcManager.addMesh(e):this._createMesh(e)}else this.error("[createMesh] SceneModel.createMesh() config missing: id")}},{key:"_createMesh",value:function(e){var t=new Js(this,e.id,e.color,e.opacity);t.pickId=this.scene._renderer.getPickID(t);var n=t.pickId,r=n>>24&255,i=n>>16&255,a=n>>8&255,s=255&n;switch(e.pickColor=new Uint8Array([s,a,i,r]),e.worldAABB=Z.collapseAABB3(),e.aabb=e.worldAABB,e.solid="solid"===e.primitive,t.origin=Z.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e);break;case 1:t.layer=this._getVBOBatchingLayer(e);break;case 0:t.layer=this._getVBOInstancingLayer(e)}t.portionId=t.layer.createPortion(e),t.aabb=e.worldAABB,t.numPrimitives=e.numPrimitives,Z.expandAABB3(this._aabb,t.aabb),this._meshes[e.id]=t,this._meshList.push(t)}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var n=0,r=e.buckets.length;n<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:case 0:t+=e.positions?e.positions.length:e.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(var s=0,o=e.buckets.length;s<o;s++)t+=e.buckets[s].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 console.info("[SceneModel ".concat(this.id,"]: creating TrianglesDataTextureLayer")),r=new ip(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":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesBatchingLayer")),s=new vl({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":console.info("[SceneModel ".concat(this.id,"]: creating LinesBatchingLayer")),s=new hu({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":console.info("[SceneModel ".concat(this.id,"]: creating PointsBatchingLayer")),s=new Uu({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":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesInstancingLayer")),s=new lu({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesInstancingLayer")),s=new lu({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":console.info("[SceneModel ".concat(this.id,"]: creating LinesInstancingLayer")),s=new Pu({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":console.info("[SceneModel ".concat(this.id,"]: creating PointsInstancingLayer")),s=new ec({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=Z.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=Z.createUUID()),void 0!==e.meshIds){var t=0;if(this._visible&&!1!==e.visible&&(t|=Te),this._pickable&&!1!==e.pickable&&(t|=be),this._culled&&!1!==e.culled&&(t|=Ee),this._clippable&&!1!==e.clippable&&(t|=De),this._collidable&&!1!==e.collidable&&(t|=Pe),this._edges&&!1!==e.edges&&(t|=Be),this._xrayed&&!1!==e.xrayed&&(t|=Re),this._highlighted&&!1!==e.highlighted&&(t|=Ce),this._selected&&!1!==e.selected&&(t|=_e),e.flags=t,this._vfcManager&&!this._vfcManager.finalized){for(var n=0,r=e.meshIds.length;n<r;n++){var i=e.meshIds[n];if(this._scheduledMeshes[i])return void this.error("[createEntity] Mesh not found: ".concat(i))}this._vfcManager.addEntity(e)}else this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],n=Z.collapseAABB3(),r=0,i=e.meshIds.length;r<i;r++){var a=e.meshIds[r],s=this._meshes[a];s?s.parent?this.error('Mesh with ID "'.concat(a,'" already belongs to object with ID "').concat(s.parent.id,'" - ignoring this mesh')):(Z.expandAABB3(n,s.aabb),t.push(s)):this.error('Mesh with this ID not found: "'.concat(a,'" - ignoring this mesh'))}var o=new Le(this,e.isObject,e.id,t,e.flags,n,!0);this._entityList.push(o),this._entities[e.id]=o,this.numEntities++}},{key:"finalize",value:function(){if(!this.destroyed){this._vfcManager&&this._vfcManager.finalize((function(){}));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.scene.lod.enabled&&(this._lodManager=this.scene.lod.getLODManager(this)),this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),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);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!==$s&&0==--$s&&Zs._clear(),this._vfcManager&&this.scene.vfc.putVFCManager(this._vfcManager),this._lodManager&&this.scene.lod.putLODManager(this._lodManager),v(T(n.prototype),"destroy",this).call(this)}}]),n}();function Ap(e,t,n){var r,i,a,s;if(t){var o=p(Ic({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=wc(e.indices||[],t),a=Ec(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,T=2*r.length+(i.length+a.length)*w,E=0;return r.length,c.forEach((function(e){E+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),E>T?[e]:(n&&bc(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 dp=function(e){I(n,pp);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)}(),vp=function(e){I(n,ve);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 fa(g(r),{geometry:new hn(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 gn(g(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Qa(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}(),hp=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),Ip=Z.vec4(),yp=Z.vec4(),mp=Z.vec3(),wp=Z.vec3(),gp=Z.vec3(),Tp=Z.vec4(),Ep=Z.vec4(),bp=Z.vec4(),Dp=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=Z.subVec3(e,i.eye,mp);r=Z.lenVec3(a)<n}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-n;var s=this._unproject(t,Tp),o=Z.subVec3(s,i.eye,bp),l=Z.mulVec3Scalar(Z.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=Z.subVec3(e,i.eye,mp),c=Z.lenVec3(u),f=Z.mulVec3Scalar(Z.normalizeVec3(Z.subVec3(i.look,i.eye,wp)),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,Ep),d=Z.subVec3(A,p,bp),v=Z.mulVec3Scalar(Z.normalizeVec3(Z.subVec3(i.look,i.eye,mp)),-n,wp),h=Z.addVec3(d,v,gp);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=Z.dotVec4(s,i)/Z.dotVec4(s,a);return n.project.unproject(e,o,Ip,yp,t),t}},{key:"destroy",value:function(){}}]),e}(),Pp=Z.vec3(),Rp=Z.vec3(),Cp=Z.vec3(),_p=Z.vec4(),Bp=Z.vec4(),Op=Z.vec4(),Sp=function(){function e(t,n){var r=this;b(this,e),this._scene=t,this._configs=n,this._pivotWorldPos=Z.vec3(),this._cameraOffset=Z.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=Z.vec3(),this._rtcPos=Z.vec3(),this._pivotViewPos=Z.vec4(),this._pivotProjPos=Z.vec4(),this._pivotCanvasPos=Z.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=Z.vec3();Z.decomposeMat4(Z.inverseMat4(this._scene.viewer.camera.viewMatrix,Z.mat4()),t,Z.vec4(),Z.vec3());var n=Z.distVec3(t,e),r=Math.tan(Math.PI/500)*n*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(r/=this._scene.camera.ortho.scale/2),ye(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Ya(this._scene,da({radius:r})),this._pivotSphere=new fa(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){Z.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,Z.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&&(ye(this.getPivotPos(),this._rtcCenter,this._rtcPos),Z.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 gn(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=Z.lookAtMat4v(e.eye,e.look,e.worldUp);Z.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var n=this.getPivotPos();this._cameraOffset[2]+=Z.distVec3(e.eye,n),t=Z.inverseMat4(t);var r=Z.transformVec3(t,this._cameraOffset),i=Z.vec3();if(Z.subVec3(e.eye,n,i),Z.addVec3(i,r),e.zUp){var a=i[1];i[1]=i[2],i[2]=a}this._radius=Z.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=Z.normalizeVec3(Z.subVec3(e.look,e.eye,Pp)),n=Z.cross3Vec3(t,e.worldUp,Rp);return Z.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(Z.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=Z.dotVec4(s,i)/Z.dotVec4(s,a),l=_p;t.project.unproject(e,o,Bp,Op,l);var u=Z.normalizeVec3(Z.subVec3(l,t.eye,Pp)),c=Z.addVec3(t.eye,Z.mulVec3Scalar(u,n,Rp),Cp);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=Z.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=Z.lenVec3(Z.subVec3(n.look,n.eye,Z.vec3())),l=this.getPivotPos();Z.addVec3(a,l);var u=Z.lookAtMat4v(a,l,n.worldUp);u=Z.inverseMat4(u);var c=Z.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]],Z.subVec3(n.eye,Z.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}(),Np=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=Z.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._needFireEvents=!1}return P(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1,this._needFireEvents=!1;var e=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var t=this._scene.snapPick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapMode:this._configs.snapMode});t&&t.snappedWorldPos?(this.snapPickResult=t,this.snappedOrPicked=!0,this._needFireEvents=!0):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var n=this.pickResult.canvasPos;if(n[0]===this.pickCursorPos[0]&&n[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents=e,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var r=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents=!0):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents=!0)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!0)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}},{key:"fireEvents",value:function(){if(this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new at;e.worldPos=this.snapPickResult.snappedWorldPos,e.canvasPos=this.snapPickResult.snappedCanvasPos,"vertex"===this._configs.snapMode?e.snappedToVertex=!0:e.snappedToEdge=!0,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=!1}}},{key:"destroy",value:function(){}}]),e}(),Lp=Z.vec2(),xp=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=Z.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?Z.lenVec3(Z.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,Lp);var t=Lp[0],i=Lp[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:Lp,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var T=1/60,E=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==E?t-E:0;E=t,n>.05&&(n=.05),n<T&&(n=T);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}(),Mp=Z.vec3(),Fp=Z.vec3(),Hp=Z.vec3(),Up=Z.vec3(),Gp=Z.vec3(),kp={eye:Z.vec3(),look:Z.vec3(),up:Z.vec3()},jp=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=Z.getAABB3Diag(p);Z.getAABB3Center(p,Mp);var d=Math.abs(A/Math.tan(n.cameraFlight.fitFOV*Z.DEGTORAD)),v=1.1*A;kp.orthoScale=v,e?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldRight,d,Fp),Gp)),kp.look.set(Mp),kp.up.set(s.worldUp)):o?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldForward,d,Fp),Gp)),kp.look.set(Mp),kp.up.set(s.worldUp)):l?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldRight,-d,Fp),Gp)),kp.look.set(Mp),kp.up.set(s.worldUp)):u?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldForward,-d,Fp),Gp)),kp.look.set(Mp),kp.up.set(s.worldUp)):c?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldUp,d,Fp),Gp)),kp.look.set(Mp),kp.up.set(Z.normalizeVec3(Z.mulVec3Scalar(s.worldForward,1,Hp),Up))):f&&(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldUp,-d,Fp),Gp)),kp.look.set(Mp),kp.up.set(Z.normalizeVec3(Z.mulVec3Scalar(s.worldForward,-1,Hp)))),!r.firstPerson&&r.followPointer&&n.pivotController.setPivotPos(Mp),n.cameraFlight.duration>0?n.cameraFlight.flyTo(kp,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(kp),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}(),Vp=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;Z.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})};p.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverOut"),l=u.hasSubs("hoverOff"),p=u.hasSubs("hoverSurface"),A=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=p,o.scheduleSnapOrPick=A,o.update(),o.pickResult){if(o.pickResult.entity){var d=o.pickResult.entity.id;s._lastPickedEntityId!==d&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=d)}u.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&u.fire("hoverSurface",o.pickResult,!0)}else void 0!==s._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),s._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)}}),p.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(c=!0),3===e.which&&(f=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===e.which))){var n=o.pickResult;n&&n.worldPos?(l.setPivotPos(n.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(i.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(c=!1),3===e.which&&(f=!1),l.getPivoting()&&l.endPivot()}),p.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var a=u.hasSubs("picked"),c=u.hasSubs("pickedNothing"),f=u.hasSubs("pickedSurface"),p=u.hasSubs("doublePicked"),d=u.hasSubs("doublePickedSurface"),v=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||p||d||v))return(a||c||f)&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=f,o.update(),o.pickResult?(u.fire("picked",o.pickResult,!0),o.pickedSurface&&u.fire("pickedSurface",o.pickResult,!0)):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(s._clicks=0);if(s._clicks++,1===s._clicks){o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo,o.schedulePickSurface=f,o.update();var h=o.pickResult,I=o.pickedSurface;s._timeout=setTimeout((function(){h?(u.fire("picked",h,!0),I&&(u.fire("pickedSurface",h,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(h.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),s._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==s._timeout&&(window.clearTimeout(s._timeout),s._timeout=null),o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo||p||d,o.schedulePickSurface=o.schedulePickEntity&&d,o.update(),o.pickResult){if(u.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&u.fire("doublePickedSurface",o.pickResult,!0),r.doublePickFlyTo&&(A(o.pickResult),!r.firstPerson&&r.followPointer)){var y=o.pickResult.entity.aabb,m=Z.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=Z.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}(),Qp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.input,o=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=s.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=s.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover&&(o[e]=!0,e===s.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=s.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(o[e]=!1,e===s.KEY_SHIFT&&(l.style.cursor=null),n.pivotController.getPivoting()&&n.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var l=n.cameraControl,c=e.deltaTime/1e3;if(!r.planView){var f=l._isKeyDownForAction(l.ROTATE_Y_POS,o),p=l._isKeyDownForAction(l.ROTATE_Y_NEG,o),A=l._isKeyDownForAction(l.ROTATE_X_POS,o),d=l._isKeyDownForAction(l.ROTATE_X_NEG,o),v=c*r.keyboardRotationRate;(f||p||A||d)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),f?a.rotateDeltaY+=v:p&&(a.rotateDeltaY-=v),A?a.rotateDeltaX+=v:d&&(a.rotateDeltaX-=v),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!o[s.KEY_CTRL]&&!o[s.KEY_ALT]){var h=l._isKeyDownForAction(l.DOLLY_BACKWARDS,o),I=l._isKeyDownForAction(l.DOLLY_FORWARDS,o);if(h||I){var y=c*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),I?a.dollyDelta-=y:h&&(a.dollyDelta+=y),u&&(i.followPointerDirty=!0,u=!1)}}var m=l._isKeyDownForAction(l.PAN_FORWARDS,o),w=l._isKeyDownForAction(l.PAN_BACKWARDS,o),g=l._isKeyDownForAction(l.PAN_LEFT,o),T=l._isKeyDownForAction(l.PAN_RIGHT,o),E=l._isKeyDownForAction(l.PAN_UP,o),b=l._isKeyDownForAction(l.PAN_DOWN,o),D=(o[s.KEY_ALT]?.3:1)*c*r.keyboardPanRate;(m||w||g||T||E||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:E&&(a.panDeltaY+=-D),T?a.panDeltaX+=-D:g&&(a.panDeltaX+=D),w?a.panDeltaZ+=D:m&&(a.panDeltaZ+=-D))}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),Wp=Z.vec3(),zp=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(Z.lenVec3(Z.subVec3(p,t.camera.eye,Wp)));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=Z.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,T=s.look;s.xUp?(g[0]=m,T[0]=w):s.yUp?(g[1]=m,T[1]=w):s.zUp&&(g[2]=m,T[2]=w),s.eye=g,s.look=T}}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}(),Kp=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){Yp(e,s,i.pointerCanvasPos)}),s.addEventListener("mousedown",this._mouseDownHandler=function(e){r.active&&r.pointerEnabled&&(Yp(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 Yp(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 Xp=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},qp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=n.pickController,o=n.pivotController,l=Z.vec2(),u=Z.vec2(),c=Z.vec2(),f=Z.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&&(Xp(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(Z.vec2());for(var u=0,c=n.length;u<c;++u)Xp(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){Xp(A[0],u),Z.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];Xp(w,u),Xp(g,c);var T=Z.geometricMeanVec2(p[0],p[1]),E=Z.geometricMeanVec2(u,c),b=Z.vec2();Z.subVec2(T,E,b);var D=b[0],P=b[1],R=t.camera,C=Z.distVec2([w.pageX,w.pageY],[g.pageX,g.pageY]),_=(Z.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(Z.lenVec3(Z.subVec3(B,t.camera.eye,[])))*Math.tan(R.perspective.fov/2*Math.PI/180);a.panDeltaX-=D*O/l*r.touchPanRate,a.panDeltaY-=P*O/l*r.touchPanRate}else a.panDeltaX-=.5*R.ortho.scale*(D/l)*r.touchPanRate,a.panDeltaY-=.5*R.ortho.scale*(P/l)*r.touchPanRate;i.pointerCanvasPos=E}for(var S=0;S<d;++S)Xp(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}(),Jp=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},Zp=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;Z.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,Jp(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)Jp(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?(Jp(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):Z.distVec2(u[0],c)<4&&(Jp(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}(),$p=function(e){I(n,ve);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,snapMode:"vertex",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:Z.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:Z.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 Np(g(r),r._configs),pivotController:new Sp(a,r._configs),panController:new Dp(a),cameraFlight:new _s(g(r),{duration:.5})},r._handlers=[new Kp(r.scene,r._controllers,r._configs,r._states,r._updates),new qp(r.scene,r._controllers,r._configs,r._states,r._updates),new xp(r.scene,r._controllers,r._configs,r._states,r._updates),new jp(r.scene,r._controllers,r._configs,r._states,r._updates),new Vp(r.scene,r._controllers,r._configs,r._states,r._updates),new Zp(r.scene,r._controllers,r._configs,r._states,r._updates),new Qp(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new zp(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",ae.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){this._configs.active=!1!==e}},{key:"snapMode",get:function(){return this._configs.snapMode},set:function(e){"vertex"!==(e=e||"vertex")&&"edge"!==e&&(this.error("Unsupported value for snapMode: "+e+" - supported values are 'vertex' and 'edge' - defaulting to 'vertex'"),e="vertex"),this._configs.snapMode=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(T(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}(),eA=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})),tA=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 eA(a.name,a.value,a.type,a.valueType,a.description))}})),nA=function(){function e(t){b(this,e),this.metaModel=null,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||{}}return P(e,[{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}(),rA=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.rootMetaObject=null,this.rootMetaObjects=[],this.metaObjects=[],this.graph=t.graph||{},this.metaScene.metaModels[this.id]=this,this.finalized=!1}return P(e,[{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;if(e.propertySets)for(var r=0,i=e.propertySets.length;r<i;r++){var a=e.propertySets[r],s=n.propertySets[a.id];s||(s=new tA({id:a.id,originalSystemId:a.originalSystemId||a.id,type:a.type,name:a.name,properties:a.properties}),n.propertySets[s.id]=s),s.metaModels.push(this),this.propertySets.push(s)}if(e.metaObjects)for(var o=0,l=e.metaObjects.length;o<l;o++){var u=e.metaObjects[o],c=u.id,f=n.metaObjects[c];if(!f){var p=u.type,A=u.originalSystemId,d=u.propertySets||u.propertySetIds;f=new nA({id:c,originalSystemId:A,parentId:u.parent,type:p,name:u.name,attributes:u.attributes,propertySetIds:d}),this.metaScene.metaObjects[c]=f}f.metaModels.push(this),u.parent||(this.rootMetaObjects.push(f),n.rootMetaObjects[c]=f),this.metaObjects.push(f)}}},{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.originalParentSystemId=a.parent,n&&(a.id=Z.globalizeObjectId(this.id,a.id),a.parent=Z.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(Z.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=Z.globalizeObjectId(mothis.id,p.id))}}}]),e}(),iA=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 rA({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 T in this.metaObjectsByType={},this.metaObjects){var E=this.metaObjects[T],b=E.type;E.children&&(E.children=null),(this.metaObjectsByType[b]||(this.metaObjectsByType[b]={}))[T]=E}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?aA(t):null,s=n&&n.length>0?aA(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 aA(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=!0;return t}
26
+ **/var yc=null;function mc(e,t){var n,r,i,a,s,o,l=3*e,u=3*t,c=Math.min(n=yc[l],r=yc[l+1],i=yc[l+2]),f=Math.min(a=yc[u],s=yc[u+1],o=yc[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 wc(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r<i;r++)n[r]=r;yc=new Int32Array(e.length);for(var a=0,s=e.length;a<s;a++)yc[a]=e[a]>>t;n.sort(mc);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 gc=null;function Tc(e,t){var n=gc[2*e]-gc[2*t];return 0!==n?n:gc[2*e+1]-gc[2*t+1]}function Ec(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}gc=new Int32Array(e),t.sort(Tc);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 bc(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 Dc=Z.vec3(),Pc=Z.vec3(),Rc=Z.vec3(),Cc=Z.vec3(),_c=Z.vec4(),Bc=Z.mat4(),Oc=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._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Dc;if(v){var y=Z.transformPoint3(f,u,Pc);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=Ie(i.viewMatrix,I,Bc),(d=Rc)[0]=i.eye[0]-I[0],d[1]=i.eye[1]-I[1],d[2]=i.eye[2]-I[2]}else A=i.viewMatrix,d=i.eye;if(s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s.uniform3fv(this._uCameraEyeRtc,d),s.uniform1i(this._uRenderPass,n),r.logarithmicDepthBufferEnabled){var m=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,m)}var w=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b<w;b++){var D=this._uSectionPlanes[b];if(D){var P=E.sectionPlanesActivePerLayer[T+b];if(s.uniform1i(D.active,P?1:0),P){var R=g[b];if(u){var C=ge(R.dist,R.dir,u,Cc);s.uniform3fv(D.pos,C)}else s.uniform3fv(D.pos,R.pos);s.uniform3fv(D.dir,R.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uRenderPass=r.getLocation("renderPass"),this._uLightAmbient=r.getLocation("lightAmbient"),this._uLightColor=[],this._uLightDir=[],this._uLightPos=[],this._uLightAttenuation=[];for(var i=n.lights,a=0,s=i.length;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._uSceneModelWorldMatrix=r.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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;_c[0]=c,_c[1]=f,_c[2]=u.blendCutoff,_c[3]=u.blendFactor,n.uniform4fv(this._uSAOParams,_c),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.sectionPlanes.length>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;"),t.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("uniform mat4 sceneModelWorldMatrix;"),a.push("uniform mat4 viewMatrix;"),a.push("uniform mat4 projMatrix;"),a.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),a.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),a.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),a.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),a.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),a.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),a.push("uniform highp sampler2D uTextureModelMatrices;"),a.push("uniform vec3 uCameraEyeRtc;"),a.push("vec3 positions[3];"),t.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("out float isPerspective;")),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("uniform vec4 lightAmbient;");for(var s=0,o=r.lights.length;s<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 (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),a.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),a.push("if (int(flags.x) != renderPass) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("} else {"),a.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),a.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),a.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),a.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),a.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),a.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),a.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),a.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),a.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),a.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),a.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),a.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),a.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),a.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),a.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),a.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),a.push("if (color.a == 0u) {"),a.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),a.push(" return;"),a.push("};"),a.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),a.push("vec3 position;"),a.push("position = positions[gl_VertexID % 3];"),a.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),a.push("if (solid != 1u) {"),a.push("if (isPerspectiveMatrix(projMatrix)) {"),a.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),a.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("} else {"),a.push("if (viewNormal.z < 0.0) {"),a.push("position = positions[2 - (gl_VertexID % 3)];"),a.push("viewNormal = -viewNormal;"),a.push("}"),a.push("}"),a.push("}"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),a.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),a.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(var l=0,u=r.lights.length;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.sectionPlanes.length>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.sectionPlanes.length;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.sectionPlanes.length;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}(),Sc=new Float32Array([1,1,1]),Nc=Z.vec3(),Lc=Z.vec3(),xc=Z.vec3(),Mc=Z.vec3(),Fc=Z.mat4(),Hc=function(){function e(t,n){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=this._scene,i=r.camera,a=t.model,s=r.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=a.position,f=a.rotationMatrix,p=a.rotationMatrixConjugate,A=i.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var d,v;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,o)),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=Nc;if(u){var I=Lc;Z.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=Ie(A,h,Fc),(v=xc)[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===to.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===to.SILHOUETTE_HIGHLIGHTED){var g=r.highlightMaterial._state,T=g.fillColor,E=g.fillAlpha;s.uniform4f(this._uColor,T[0],T[1],T[2],E)}else if(n===to.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,Sc);if(r.logarithmicDepthBufferEnabled){var R=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,R)}var C=r._sectionPlanesState.sectionPlanes.length;if(C>0)for(var _=r._sectionPlanesState.sectionPlanes,B=t.layerIndex*C,O=a.renderFlags,S=0;S<C;S++){var N=this._uSectionPlanes[S];if(N){var L=O.sectionPlanesActivePerLayer[B+S];if(s.uniform1i(N.active,L?1:0),L){var x=_[S];if(u){var M=ge(x.dist,x.dir,u,Mc);s.uniform3fv(N.pos,M)}else s.uniform3fv(N.pos,x.pos);s.uniform3fv(N.dir,x.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uColor=n.getLocation("color"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.y) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("} else {"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("viewNormal = -viewNormal;"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("uniform vec4 color;"),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.sectionPlanes.length;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;"),r.push(" outColor = color;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Uc=new Float32Array([0,0,0,1]),Gc=Z.vec3(),kc=Z.vec3();Z.vec3();var jc=Z.vec3(),Vc=Z.mat4(),Qc=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Gc;if(v){var y=kc;Z.transformPoint3(f,u,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],d=Ie(A,I,Vc)}else d=A;if(s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),n===to.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===to.EDGES_HIGHLIGHTED){var T=i.highlightMaterial._state,E=T.edgeColor,b=T.edgeAlpha;s.uniform4f(this._uColor,E[0],E[1],E[2],b)}else if(n===to.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,Uc);var C=i._sectionPlanesState.sectionPlanes.length;if(C>0)for(var _=i._sectionPlanesState.sectionPlanes,B=t.layerIndex*C,O=r.renderFlags,S=0;S<C;S++){var N=this._uSectionPlanes[S];if(N){var L=O.sectionPlanesActivePerLayer[B+S];if(s.uniform1i(N.active,L?1:0),L){var x=_[S];if(u){var M=ge(x.dist,x.dir,u,jc);s.uniform3fv(N.pos,M)}else s.uniform3fv(N.pos,x.pos);s.uniform3fv(N.dir,x.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uColor=n.getLocation("color"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets"}}},{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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.z) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),e.logarithmicDepthBufferEnabled&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i<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.sectionPlanes.length;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) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Wc=Z.vec3(),zc=Z.vec3(),Kc=Z.vec3(),Yc=Z.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=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=a.viewMatrix;if(this._program||(this._allocate(),!this.errors)){var d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Wc;if(v){var y=zc;Z.transformPoint3(f,u,y),I[0]=y[0],I[1]=y[1],I[2]=y[2]}else I[0]=0,I[1]=0,I[2]=0;I[0]+=c[0],I[1]+=c[1],I[2]+=c[2],d=Ie(A,I,Yc)}else d=A;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var m=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=r.renderFlags,E=0;E<m;E++){var b=this._uSectionPlanes[E];if(b){var D=T.sectionPlanesActivePerLayer[g+E];if(s.uniform1i(b.active,D?1:0),D){var P=w[E];if(u){var R=ge(P.dist,P.dir,u,Kc);s.uniform3fv(b.pos,R)}else s.uniform3fv(b.pos,P.pos);s.uniform3fv(b.dir,P.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets"}}},{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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.z) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vec4 rgb = vec4(color.rgba);"),n.push("vColor = vec4(float(rgb.r*0.5) / 255.0, float(rgb.g*0.5) / 255.0, float(rgb.b*0.5) / 255.0, float(rgb.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// TrianglesDataTextureEdgesColorRenderer"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i<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.sectionPlanes.length;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) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vColor;"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),qc=Z.vec3(),Jc=Z.vec3(),Zc=Z.vec3(),$c=Z.mat4(),ef=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){if(this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e));var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate;c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==f[0]||0!==f[1]||0!==f[2],h=0!==p[0]||0!==p[1]||0!==p[2];if(v||h){var I=qc;if(v){var y=Z.transformPoint3(A,f,Jc);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=Ie(o.viewMatrix,I,$c),(i=Zc)[0]=o.eye[0]-I[0],i[1]=o.eye[1]-I[1],i[2]=o.eye[2]-I[2]}else r=o.viewMatrix,i=o.eye;if(l.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix),l.uniform3fv(this._uCameraEyeRtc,i),l.uniform1i(this._uRenderPass,n),s.logarithmicDepthBufferEnabled){var m=2/(Math.log(o.project.far+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,m)}var w=s._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=s._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b<w;b++){var D=this._uSectionPlanes[b];if(D){var P=E.sectionPlanesActivePerLayer[T+b];if(l.uniform1i(D.active,P?1:0),P){var R=g[b];if(f){var C=ge(R.dist,R.dir,f,qc);l.uniform3fv(D.pos,C)}else l.uniform3fv(D.pos,R.pos);l.uniform3fv(D.dir,R.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._withSAO&&(this._uOcclusionTexture="uOcclusionTexture",this._uSAOParams=n.getLocation("uSAOParams")),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("smooth out vec4 vWorldPosition;"),n.push("flat out uvec4 vFlags2;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vPickColor = vec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0)) / 255.0;"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uvec4 vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vPickColor;"),r.push("out vec4 outPickColor;"),r.push("void main(void) {"),n){r.push(" bool clippable = (float(vFlags2.x) > 0.0);"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i<t.sectionPlanes.length;i++)r.push(" if (sectionPlaneActive"+i+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outPickColor = vPickColor; "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),tf=Z.vec3(),nf=Z.vec3(),rf=Z.vec3(),af=Z.vec3(),sf=Z.mat4(),of=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r,i,a=t.model,s=a.scene,o=s.camera,l=s.canvas.gl,u=t._state,c=u.textureState,f=t._state.origin,p=a.position,A=a.rotationMatrix,d=a.rotationMatrixConjugate,v=e.pickViewMatrix||o.viewMatrix;if(this._program||this._allocate(),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),f||0!==p[0]||0!==p[1]||0!==p[2]){var h=tf;if(f){var I=nf;Z.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=Ie(v,h,sf),(i=rf)[0]=o.eye[0]-h[0],i[1]=o.eye[1]-h[1],i[2]=o.eye[2]-h[2],e.snapPickOrigin[0]=h[0],e.snapPickOrigin[1]=h[1],e.snapPickOrigin[2]=h[2]}else r=v,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;if(l.uniform3fv(this._uCameraEyeRtc,i),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniform1f(this._uPickZNear,e.pickZNear),l.uniform1f(this._uPickZFar,e.pickZFar),l.uniformMatrix4fv(this._uWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix),s.logarithmicDepthBufferEnabled){var y=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,y)}var m=s._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=s._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=a.renderFlags,E=0;E<m;E++){var b=this._uSectionPlanes[E];if(b){var D=T.sectionPlanesActivePerLayer[g+E];if(l.uniform1i(b.active,D?1:0),D){var P=w[E];if(f){var R=ge(P.dist,P.dir,f,af);l.uniform3fv(b.pos,R)}else l.uniform3fv(b.pos,P.pos);l.uniform3fv(b.dir,P.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureCameraMatrices="uTextureCameraMatrices",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("}"),n.push("}"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec4 vViewPosition;"),r.push("vec4 packDepth(const in float depth) {"),r.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),r.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),r.push(" vec4 res = fract(depth * bitShift);"),r.push(" res -= res.xxyz * bitMask;"),r.push(" return res;"),r.push("}"),r.push("out vec4 outPackedDepth;"),r.push("void main(void) {"),n){r.push(" bool clippable = vFlags2 > 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i<t.sectionPlanes.length;i++)r.push(" if (sectionPlaneActive"+i+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outPackedDepth = packDepth(zNormalizedDepth); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),lf=Z.vec3(),uf=Z.vec3(),cf=Z.vec3(),ff=Z.vec3(),pf=Z.vec3(),Af=Z.mat4(),df=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=lf;I[0]=Z.safeInv(v[3]-v[0])*Z.MAX_INT,I[1]=Z.safeInv(v[4]-v[1])*Z.MAX_INT,I[2]=Z.safeInv(v[5]-v[2])*Z.MAX_INT,e.snapPickCoordinateScale[0]=Z.safeInv(I[0]),e.snapPickCoordinateScale[1]=Z.safeInv(I[1]),e.snapPickCoordinateScale[2]=Z.safeInv(I[2]),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var y=0!==f[0]||0!==f[1]||0!==f[2],m=0!==p[0]||0!==p[1]||0!==p[2];if(y||m){var w=uf;if(y){var g=Z.transformPoint3(A,f,cf);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=Ie(h,w,Af),(i=ff)[0]=o.eye[0]-w[0],i[1]=o.eye[1]-w[1],i[2]=o.eye[2]-w[2],e.snapPickOrigin[0]=w[0],e.snapPickOrigin[1]=w[1],e.snapPickOrigin[2]=w[2]}else r=h,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,i),l.uniform2fv(this.uVectorA,e.snapVectorA),l.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,I),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var T=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,T);var E=s._sectionPlanesState.sectionPlanes.length;if(E>0)for(var b=s._sectionPlanesState.sectionPlanes,D=t.layerIndex*E,P=a.renderFlags,R=0;R<E;R++){var C=this._uSectionPlanes[R];if(C){var _=P.sectionPlanesActivePerLayer[D+R];if(l.uniform1i(C.active,_?1:0),_){var B=b[R];if(f){var O=ge(B.dist,B.dir,f,pf);l.uniform3fv(C.pos,O)}else l.uniform3fv(C.pos,B.pos);l.uniform3fv(C.dir,B.dir)}}}var S="edge"===e.snapMode?l.LINES:l.POINTS;u.numEdgeIndices8Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,8),l.drawArrays(S,0,u.numEdgeIndices8Bits)),u.numEdgeIndices16Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,16),l.drawArrays(S,0,u.numEdgeIndices16Bits)),u.numEdgeIndices32Bits>0&&(c.bindEdgeIndicesTextures(this._program,this._uTexturePerEdgeIdPortionIds,this._uTexturePerPolygonIdEdgeIndices,32),l.drawArrays(S,0,u.numEdgeIndices32Bits)),e.drawElements++}}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdEdgeIndices="uTexturePerPolygonIdEdgeIndices",this._uTexturePerEdgeIdPortionIds="uTexturePerEdgeIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdEdgeIndices;"),n.push("uniform mediump usampler2D uTexturePerEdgeIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 uSnapVectorA;"),n.push("uniform vec2 uSnapInvVectorAB;"),n.push("vec3 positions[3];"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - uSnapVectorA.x) * uSnapInvVectorAB.x;"),n.push(" float y = (clipPos.y - uSnapVectorA.y) * uSnapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec4 vViewPosition;"),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int edgeIndex = gl_VertexID / 2;"),n.push("int h_packed_object_id_index = (edgeIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (edgeIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerEdgeIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedEdgeIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0));"),n.push("int edgeIndexBaseOffset = (packedEdgeIndexBaseOffset.r << 24) + (packedEdgeIndexBaseOffset.g << 16) + (packedEdgeIndexBaseOffset.b << 8) + packedEdgeIndexBaseOffset.a;"),n.push("int h_index = (edgeIndex - edgeIndexBaseOffset) & 4095;"),n.push("int v_index = (edgeIndex - edgeIndexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdEdgeIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),n.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH, indexPositionV), 0));"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.r;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),n.push("vViewPosition = clipPos;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push("gl_PointSize = 1.0;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles dataTexture pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int uLayerNumber;"),n.push("uniform vec3 uCoordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e.sectionPlanes.length;r<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.sectionPlanes.length;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}(),vf=Z.vec3(),hf=Z.vec3(),If=Z.vec3(),yf=Z.vec3(),mf=Z.vec3(),wf=Z.mat4(),gf=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=vf;I[0]=Z.safeInv(v[3]-v[0])*Z.MAX_INT,I[1]=Z.safeInv(v[4]-v[1])*Z.MAX_INT,I[2]=Z.safeInv(v[5]-v[2])*Z.MAX_INT,e.snapPickCoordinateScale[0]=Z.safeInv(I[0]),e.snapPickCoordinateScale[1]=Z.safeInv(I[1]),e.snapPickCoordinateScale[2]=Z.safeInv(I[2]),c.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var y=0!==f[0]||0!==f[1]||0!==f[2],m=0!==p[0]||0!==p[1]||0!==p[2];if(y||m){var w=hf;if(y){var g=If;Z.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=Ie(h,w,wf),(i=yf)[0]=o.eye[0]-w[0],i[1]=o.eye[1]-w[1],i[2]=o.eye[2]-w[2],e.snapPickOrigin[0]=w[0],e.snapPickOrigin[1]=w[1],e.snapPickOrigin[2]=w[2]}else r=h,i=o.eye,e.snapPickOrigin[0]=0,e.snapPickOrigin[1]=0,e.snapPickOrigin[2]=0;l.uniform3fv(this._uCameraEyeRtc,i),l.uniform2fv(this._uVectorA,e.snapVectorA),l.uniform2fv(this._uInverseVectorAB,e.snapInvVectorAB),l.uniform1i(this._uLayerNumber,e.snapPickLayerNumber),l.uniform3fv(this._uCoordinateScaler,I),l.uniform1i(this._uRenderPass,n),l.uniform1i(this._uPickInvisible,e.pickInvisible),l.uniformMatrix4fv(this._uSceneWorldModelMatrix,!1,d),l.uniformMatrix4fv(this._uViewMatrix,!1,r),l.uniformMatrix4fv(this._uProjMatrix,!1,o.projMatrix);var T=2/(Math.log(e.pickZFar+1)/Math.LN2);l.uniform1f(this._uLogDepthBufFC,T);var E=s._sectionPlanesState.sectionPlanes.length;if(E>0)for(var b=s._sectionPlanesState.sectionPlanes,D=t.layerIndex*E,P=a.renderFlags,R=0;R<E;R++){var C=this._uSectionPlanes[R];if(C){var _=P.sectionPlanesActivePerLayer[D+R];if(l.uniform1i(C.active,_?1:0),_){var B=b[R];if(f){var O=ge(B.dist,B.dir,f,mf);l.uniform3fv(C.pos,O)}else l.uniform3fv(C.pos,B.pos);l.uniform3fv(C.dir,B.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSceneWorldModelMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>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 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 uVectorAB;"),n.push("uniform vec2 uInverseVectorAB;"),n.push("vec3 positions[3];"),n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - uVectorAB.x) * uInverseVectorAB.x;"),n.push(" float y = (clipPos.y - uVectorAB.y) * uInverseVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("{"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" viewNormal = -viewNormal;"),n.push(" }"),n.push(" } else {"),n.push(" if (viewNormal.z < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" viewNormal = -viewNormal;"),n.push(" }"),n.push(" }"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureSnapDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;"),n.push("uniform int uLayerNumber;"),n.push("uniform vec3 uCoordinateScaler;"),t){n.push("in vec4 vWorldPosition;"),n.push("flat in uint vFlags2;");for(var r=0,i=e.sectionPlanes.length;r<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.sectionPlanes.length;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}(),Tf=Z.vec3(),Ef=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureCameraMatrices,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var c=a.eye;e.pickViewMatrix&&(l.bindPickCameraTexture(this._program,this._uTextureCameraMatrices),c=e.pickOrigin||c);var f=[c[0]-u[0],c[1]-u[1],c[2]-u[2]];if(s.uniform3fv(this._uCameraEyeRtc,f),s.uniform1i(this._uRenderPass,n),s.uniform3fv(this._uCameraEyeRtc,f),s.uniform1i(this._uPickInvisible,e.pickInvisible),i.logarithmicDepthBufferEnabled){var p=2/(Math.log(a.project.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,p)}var A=i._sectionPlanesState.sectionPlanes.length;if(A>0)for(var d=i._sectionPlanesState.sectionPlanes,v=t.layerIndex*A,h=r.renderFlags,I=0;I<A;I++){var y=this._uSectionPlanes[I];if(y){var m=h.sectionPlanesActivePerLayer[v+I];if(s.uniform1i(y.active,m?1:0),m){var w=d[I];if(u){var g=ge(w.dist,w.dir,u,Tf);s.uniform3fv(y.pos,g)}else s.uniform3fv(y.pos,w.pos);s.uniform3fv(y.dir,w.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureCameraMatrices="uTextureCameraMatrices",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick normals vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform bool pickInvisible;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureCameraMatrices;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("flat out uint vFlags2;")),n.push("out vec3 vWorldNormal;"),n.push("void main(void) {"),n.push("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));"),n.push("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));"),n.push("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("} else {"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push("if (isPerspectiveMatrix(projMatrix)) {"),n.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("normal = -normal;"),n.push("}"),n.push("} else {"),n.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push("if (viewNormal.z < 0.0) {"),n.push("position = positions[2 - (gl_VertexID % 3)];"),n.push("normal = -normal;"),n.push("}"),n.push("}"),n.push("}"),n.push("normal = -normal;"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vWorldNormal = normal.xyz;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2.w;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vWorldNormal;"),r.push("out vec4 outNormal;"),r.push("void main(void) {"),n){r.push(" bool clippable = vFlags2 > 0u;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i<t.sectionPlanes.length;i++)r.push(" if (sectionPlaneActive"+i+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outNormal = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),bf=Z.vec3(),Df=Z.vec3(),Pf=Z.vec3(),Rf=Z.vec3(),Cf=Z.mat4(),_f=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=r.position,f=r.rotationMatrix,p=r.rotationMatrixConjugate,A=e.pickViewMatrix||a.viewMatrix;if(this._program||(this._allocate(t),!this.errors)){var d,v;if(e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets),u||0!==c[0]||0!==c[1]||0!==c[2]){var h=bf;if(u){var I=Df;Z.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=Ie(A,h,Cf),(v=Pf)[0]=a.eye[0]-h[0],v[1]=a.eye[1]-h[1],v[2]=a.eye[2]-h[2]}else d=A,v=a.eye;s.uniform3fv(this._uCameraEyeRtc,v),s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix);var y=i._sectionPlanesState.sectionPlanes.length;if(y>0)for(var m=i._sectionPlanesState.sectionPlanes,w=t.layerIndex*y,g=r.renderFlags,T=0;T<y;T++){var E=this._uSectionPlanes[T];if(E){var b=g.sectionPlanesActivePerLayer[w+T];if(s.uniform1i(E.active,b?1:0),b){var D=m[T];if(u){var P=ge(D.dist,D.dir,u,Rf);s.uniform3fv(E.pos,P)}else s.uniform3fv(E.pos,D.pos);s.uniform3fv(E.dir,D.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureCameraMatrices="uTextureCameraMatrices",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform mat4 sceneModelWorldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),n.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),n.push("uniform highp sampler2D uTextureModelMatrices;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("vec3 positions[3];"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out vec4 vFlags2;")),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),n.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),n.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),n.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),n.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),n.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),n.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),n.push("if (color.a == 0u) {"),n.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),n.push(" return;"),n.push("};"),n.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),n.push("vec3 position;"),n.push("position = positions[gl_VertexID % 3];"),n.push("if (solid != 1u) {"),n.push(" if (isPerspectiveMatrix(projMatrix)) {"),n.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),n.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" }"),n.push(" } else {"),n.push(" vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),n.push(" if (viewNormal.z < 0.0) {"),n.push(" position = positions[2 - (gl_VertexID % 3)];"),n.push(" }"),n.push(" }"),n.push("}"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),n.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),n.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags2 = flags2.r;")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// TrianglesDataTextureColorRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in vec4 vFlags2;");for(var r=0;r<e.sectionPlanes.length;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.x) > 0.0);"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i<e.sectionPlanes.length;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}(),Bf=Z.vec3(),Of=Z.vec3(),Sf=Z.vec3(),Nf=Z.vec3(),Lf=Z.mat4(),xf=function(){function e(t){b(this,e),this._scene=t,this._allocate(),this._hash=this._getHash()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=this._scene,i=r.camera,a=t.model,s=r.canvas.gl,o=t._state,l=o.textureState,u=t._state.origin,c=a.position,f=a.rotationMatrix,p=a.rotationMatrixConjugate;if(this._program||(this._allocate(),!this.errors)){var A,d;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e,o)),l.bindCommonTextures(this._program,this._uTexturePerObjectIdPositionsDecodeMatrix,this._uTexturePerVertexIdCoordinates,this._uTexturePerObjectIdColorsAndFlags,this._uTextureModelMatrices,this._uTexturePerObjectIdOffsets);var v=0!==u[0]||0!==u[1]||0!==u[2],h=0!==c[0]||0!==c[1]||0!==c[2];if(v||h){var I=Bf;if(v){var y=Z.transformPoint3(f,u,Of);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=Ie(i.viewMatrix,I,Lf),(d=Sf)[0]=i.eye[0]-I[0],d[1]=i.eye[1]-I[1],d[2]=i.eye[2]-I[2]}else A=i.viewMatrix,d=i.eye;if(s.uniformMatrix4fv(this._uSceneModelWorldMatrix,!1,p),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,i.projMatrix),s.uniform3fv(this._uCameraEyeRtc,d),s.uniform1i(this._uRenderPass,n),r.logarithmicDepthBufferEnabled){var m=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,m)}var w=r._sectionPlanesState.sectionPlanes.length;if(w>0)for(var g=r._sectionPlanesState.sectionPlanes,T=t.layerIndex*w,E=a.renderFlags,b=0;b<w;b++){var D=this._uSectionPlanes[b];if(D){var P=E.sectionPlanesActivePerLayer[T+b];if(s.uniform1i(D.active,P?1:0),P){var R=g[b];if(u){var C=ge(R.dist,R.dir,u,Nf);s.uniform3fv(D.pos,C)}else s.uniform3fv(D.pos,R.pos);s.uniform3fv(D.dir,R.dir)}}}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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uSceneModelWorldMatrix=n.getLocation("sceneModelWorldMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;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._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds",this._uTextureModelMatrices="uTextureModelMatrices",this._uTexturePerObjectIdOffsets="uTexturePerObjectIdOffsets",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;e._lightsState;var n=t.sectionPlanes.length>0,r=[];return r.push("#version 300 es"),r.push("// Triangles dataTexture draw vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("precision highp usampler2D;"),r.push("precision highp isampler2D;"),r.push("precision highp sampler2D;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("precision mediump usampler2D;"),r.push("precision mediump isampler2D;"),r.push("precision mediump sampler2D;"),r.push("#endif"),r.push("uniform int renderPass;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("uniform mat4 sceneModelWorldMatrix;"),r.push("uniform mat4 viewMatrix;"),r.push("uniform mat4 projMatrix;"),r.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),r.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"),r.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"),r.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"),r.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"),r.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"),r.push("uniform highp sampler2D uTextureModelMatrices;"),r.push("uniform vec3 uCameraEyeRtc;"),r.push("vec3 positions[3];"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;"),r.push("out float isPerspective;")),r.push("bool isPerspectiveMatrix(mat4 m) {"),r.push(" return (m[2][3] == - 1.0);"),r.push("}"),r.push("out highp vec2 vHighPrecisionZW;"),n&&(r.push("out vec4 vWorldPosition;"),r.push("flat out uint vFlags2;")),r.push("void main(void) {"),r.push("int polygonIndex = gl_VertexID / 3;"),r.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;"),r.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;"),r.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);"),r.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),r.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),r.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),r.push("if (int(flags.x) != renderPass) {"),r.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),r.push(" return;"),r.push("} else {"),r.push("mat4 worldMatrix = sceneModelWorldMatrix * mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));"),r.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),r.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"),r.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),r.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;"),r.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;"),r.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),r.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),r.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),r.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),r.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),r.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"),r.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),r.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),r.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),r.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"),r.push("if (color.a == 0u) {"),r.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"),r.push(" return;"),r.push("};"),r.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),r.push("vec3 position;"),r.push("position = positions[gl_VertexID % 3];"),r.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);"),r.push("if (solid != 1u) {"),r.push("if (isPerspectiveMatrix(projMatrix)) {"),r.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;"),r.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),r.push("position = positions[2 - (gl_VertexID % 3)];"),r.push("viewNormal = -viewNormal;"),r.push("}"),r.push("} else {"),r.push("if (viewNormal.z < 0.0) {"),r.push("position = positions[2 - (gl_VertexID % 3)];"),r.push("viewNormal = -viewNormal;"),r.push("}"),r.push("}"),r.push("}"),r.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),r.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);"),r.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags2 = flags2.r;")),r.push("gl_Position = clipPos;"),r.push("vHighPrecisionZW = gl_Position.zw;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),r.push("in highp vec2 vHighPrecisionZW;"),r.push("out vec4 outColor;"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("flat in uint vFlags2;");for(var i=0,a=t.sectionPlanes.length;i<a;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(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.sectionPlanes.length;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;"),r.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),r.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Mf=Z.vec3(),Ff=Z.vec3(),Hf=Z.vec3(),Uf=Z.vec3(),Gf=Z.mat4(),kf=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=Mf;if(v){var y=Ff;Z.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=Ie(p,I,Gf),(d=Hf)[0]=a.eye[0]-I[0],d[1]=a.eye[1]-I[1],d[2]=a.eye[2]-I[2]}else A=p,d=a.eye;s.uniform1i(this._uRenderPass,n),s.uniformMatrix4fv(this._uWorldMatrix,!1,f),s.uniformMatrix4fv(this._uViewMatrix,!1,A),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),s.uniformMatrix4fv(this._uViewNormalMatrix,!1,a.viewNormalMatrix),s.uniformMatrix4fv(this._uWorldNormalMatrix,!1,r.worldNormalMatrix);var m=i._sectionPlanesState.sectionPlanes.length;if(m>0)for(var w=i._sectionPlanesState.sectionPlanes,g=t.layerIndex*m,T=r.renderFlags,E=0;E<m;E++){var b=this._uSectionPlanes[E];if(b){var D=T.sectionPlanesActivePerLayer[g+E];if(s.uniform1i(b.active,D?1:0),D){var P=w[E];if(l){var R=ge(P.dist,P.dir,l,Uf);s.uniform3fv(b.pos,R)}else s.uniform3fv(b.pos,P.pos);s.uniform3fv(b.dir,P.dir)}}}s.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,t._state.positionsDecodeMatrix),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 pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._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.sectionPlanes.length;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.sectionPlanes.length>0,n=[];return n.push("// Batched geometry normals vertex shader"),e.logarithmicDepthBufferEnabled&&$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("#extension GL_EXT_frag_depth : enable"),n.push("uniform int renderPass;"),n.push("attribute vec3 position;"),e.entityOffsetsEnabled&&n.push("attribute vec3 offset;"),n.push("attribute vec3 normal;"),n.push("attribute vec4 color;"),n.push("attribute vec4 flags;"),n.push("attribute vec4 flags2;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 worldNormalMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 viewNormalMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("varying float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out vec4 vFlags2;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("if (int(flags.x) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags2 = flags2;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&($e.SUPPORTED_EXTENSIONS.EXT_frag_depth?n.push("vFragDepth = 1.0 + clipPos.w;"):(n.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;"),n.push("clipPos.z *= clipPos.w;")),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),e.logarithmicDepthBufferEnabled&&$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in vec4 vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("in vec3 vViewNormal;"),r.push("vec3 packNormalToRGB( const in vec3 normal ) {"),r.push(" return normalize( normal ) * 0.5 + 0.5;"),r.push("}"),r.push("void main(void) {"),n){r.push(" bool clippable = (float(vFlags2.x) > 0.0);"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a<t.sectionPlanes.length;a++)r.push(" if (sectionPlaneActive"+a+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+a+".xyz, vWorldPosition.xyz - sectionPlanePos"+a+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&$e.SUPPORTED_EXTENSIONS.EXT_frag_depth&&r.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" gl_FragColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),jf=Z.vec3(),Vf=function(){function e(t){b(this,e),this._scene=t,this._hash=this._getHash(),this._allocate()}return P(e,[{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"drawLayer",value:function(e,t,n){var r=t.model,i=r.scene,a=i.camera,s=i.canvas.gl,o=t._state,l=t._state.origin;this._program||this._allocate(t),e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),this._program.bindTexture(this._uTexturePerObjectIdPositionsDecodeMatrix,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerObjectIdPositionsDecodeMatrix),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},1),this._program.bindTexture(this._uTexturePerVertexIdCoordinates,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerVertexIdCoordinates),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},2),this._program.bindTexture(this._uTexturePerObjectIdColorsAndFlags,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerObjectIdColorsAndFlags),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},3),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible),s.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix);var u=e.pickViewMatrix||a.viewMatrix,c=l?Ie(u,l):u;if(s.uniformMatrix4fv(this._uViewMatrix,!1,c),s.uniformMatrix4fv(this._uProjMatrix,!1,e.pickProjMatrix),i.logarithmicDepthBufferEnabled){var f=2/(Math.log(a.project.far+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,f)}var p=i._sectionPlanesState.sectionPlanes.length;if(p>0)for(var A=i._sectionPlanesState.sectionPlanes,d=t.layerIndex*p,v=r.renderFlags,h=0;h<p;h++){var I=this._uSectionPlanes[h],y=v.sectionPlanesActivePerLayer[d+h];if(s.uniform1i(I.active,y?1:0),y){var m=A[h];if(l){var w=ge(m.dist,m.dir,l,jf);s.uniform3fv(I.pos,w)}else s.uniform3fv(I.pos,m.pos);s.uniform3fv(I.dir,m.dir)}}o.numIndices8Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds8Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices8Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices8Bits)),o.numIndices16Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds16Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices16Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices16Bits)),o.numIndices32Bits>0&&(this._program.bindTexture(this._uTexturePerPolygonIdPortionIds,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdPortionIds32Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},4),this._program.bindTexture(this._uTexturePerPolygonIdIndices,{bind:function(e){return s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,o.texturePerPolygonIdIndices32Bits),!0},unbind:function(e){s.activeTexture(s["TEXTURE"+e]),s.bindTexture(s.TEXTURE_2D,null)}},5),s.drawArrays(s.TRIANGLES,0,o.numIndices32Bits)),e.drawElements++}},{key:"_allocate",value:function(){var e=this._scene,t=e.canvas.gl;if(this._program=new pt(t,this._buildShader()),this._program.errors)this.errors=this._program.errors;else{var n=this._program;this._uRenderPass=n.getLocation("renderPass"),this._uPickInvisible=n.getLocation("pickInvisible"),this._uPositionsDecodeMatrix=n.getLocation("positionsDecodeMatrix"),this._uWorldMatrix=n.getLocation("worldMatrix"),this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(var r=0,i=e._sectionPlanesState.sectionPlanes.length;r<i;r++)this._uSectionPlanes.push({active:n.getLocation("sectionPlaneActive"+r),pos:n.getLocation("sectionPlanePos"+r),dir:n.getLocation("sectionPlaneDir"+r)});this._aPackedVertexId=n.getAttribute("packedVertexId"),e.logarithmicDepthBufferEnabled&&(this._uLogDepthBufFC=n.getLocation("logDepthBufFC")),this._uTexturePerObjectIdPositionsDecodeMatrix="uTexturePerObjectIdPositionsDecodeMatrix",this._uTexturePerObjectIdColorsAndFlags="uTexturePerObjectIdColorsAndFlags",this._uTexturePerVertexIdCoordinates="uTexturePerVertexIdCoordinates",this._uTexturePerPolygonIdNormals="uTexturePerPolygonIdNormals",this._uTexturePerPolygonIdIndices="uTexturePerPolygonIdIndices",this._uTexturePerPolygonIdPortionIds="uTexturePerPolygonIdPortionIds"}}},{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.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles dataTexture pick flat normals vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in uvec3 packedVertexId;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"),n.push("uniform usampler2D uTexturePerObjectIdColorsAndFlags;"),n.push("uniform usampler2D uTexturePerVertexIdCoordinates;"),n.push("uniform usampler2D uTexturePerPolygonIdIndices;"),n.push("uniform isampler2D uTexturePerPolygonIdNormals;"),n.push("uniform usampler2D uTexturePerPolygonIdPortionIds;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("out vec4 vWorldPosition;"),t&&n.push("out int vFlags2;"),n.push("void main(void) {"),n.push("int polygonIndex = gl_VertexID / 3;"),n.push("int h_normal_index = polygonIndex & 4095;"),n.push("int v_normal_index = polygonIndex >> 12;"),n.push("int h_packed_object_id_index = ((polygonIndex >> 3) / 2) & 4095;"),n.push("int v_packed_object_id_index = ((polygonIndex >> 3) / 2) >> 12;"),n.push("ivec3 packedObjectId = ivec3(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).rgb);"),n.push("int objectIndex;"),n.push("if (((polygonIndex >> 3) % 2) == 0) {"),n.push(" objectIndex = (packedObjectId.r << 4) + (packedObjectId.g >> 4);"),n.push("} else {"),n.push(" objectIndex = ((packedObjectId.g & 15) << 8) + packedObjectId.b;"),n.push("}"),n.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),n.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"),n.push("int h_index = polygonIndex & 4095;"),n.push("int v_index = polygonIndex >> 12;"),n.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));"),n.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),n.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),n.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),n.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*4+3, objectIndexCoords.y), 0));"),n.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"),n.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"),n.push("vec3 position1 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));"),n.push("vec3 position2 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));"),n.push("vec3 position3 = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));"),n.push("vec3 normal = normalize(cross(position3 - position1, position2 - position1));"),n.push("int vertexNumber = gl_VertexID % 3;"),n.push("vec3 position;"),n.push("if (vertexNumber == 0) position = position1;"),n.push("else if (vertexNumber == 1) position = position2;"),n.push("else position = position3;"),n.push("if (int(flags.w) != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),t&&n.push(" vFlags2 = flags2.r;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles dataTexture pick flat normals fragment shader"),r.push("#extension GL_OES_standard_derivatives : enable"),e.logarithmicDepthBufferEnabled&&r.push("#extension GL_EXT_frag_depth : enable"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in int vFlags2;");for(var i=0;i<t.sectionPlanes.length;i++)r.push("uniform bool sectionPlaneActive"+i+";"),r.push("uniform vec3 sectionPlanePos"+i+";"),r.push("uniform vec3 sectionPlaneDir"+i+";")}if(r.push("out vec4 outNormal;"),r.push("void main(void) {"),n){r.push(" bool clippable = vFlags2 > 0;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(i=0;i<t.sectionPlanes.length;i++)r.push(" if (sectionPlaneActive"+i+") {"),r.push(" dist += clamp(dot(-sectionPlaneDir"+i+".xyz, vWorldPosition.xyz - sectionPlanePos"+i+".xyz), 0.0, 1000.0);"),r.push(" }");r.push(" if (dist > 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outNormal = vec4((worldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Qf=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._colorRendererWithSAO&&!this._colorRendererWithSAO.getValid()&&(this._colorRendererWithSAO.destroy(),this._colorRendererWithSAO=null),this._flatColorRenderer&&!this._flatColorRenderer.getValid()&&(this._flatColorRenderer.destroy(),this._flatColorRenderer=null),this._flatColorRendererWithSAO&&!this._flatColorRendererWithSAO.getValid()&&(this._flatColorRendererWithSAO.destroy(),this._flatColorRendererWithSAO=null),this._colorQualityRendererWithSAO&&!this._colorQualityRendererWithSAO.getValid()&&(this._colorQualityRendererWithSAO.destroy(),this._colorQualityRendererWithSAO=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._normalsRenderer&&!this._normalsRenderer.getValid()&&(this._normalsRenderer.destroy(),this._normalsRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._edgesRenderer&&!this._edgesRenderer.getValid()&&(this._edgesRenderer.destroy(),this._edgesRenderer=null),this._edgesColorRenderer&&!this._edgesColorRenderer.getValid()&&(this._edgesColorRenderer.destroy(),this._edgesColorRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._vertexDepthRenderer&&!this._vertexDepthRenderer.getValid()&&(this._vertexDepthRenderer.destroy(),this._vertexDepthRenderer=null),this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._pickNormalsRenderer&&!1===this._pickNormalsRenderer.getValid()&&(this._pickNormalsRenderer.destroy(),this._pickNormalsRenderer=null),this._pickNormalsFlatRenderer&&!1===this._pickNormalsFlatRenderer.getValid()&&(this._pickNormalsFlatRenderer.destroy(),this._pickNormalsFlatRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Oc(this._scene,!1)),this._colorRenderer}},{key:"colorRendererWithSAO",get:function(){return this._colorRendererWithSAO||(this._colorRendererWithSAO=new Oc(this._scene,!0)),this._colorRendererWithSAO}},{key:"colorQualityRendererWithSAO",get:function(){return this._colorQualityRendererWithSAO||(this._colorQualityRendererWithSAO=new TrianglesDataTextureColorQualityRenderer(this._scene,!0)),this._colorQualityRendererWithSAO}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Hc(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new xf(this._scene)),this._depthRenderer}},{key:"normalsRenderer",get:function(){return this._normalsRenderer||(this._normalsRenderer=new kf(this._scene)),this._normalsRenderer}},{key:"edgesRenderer",get:function(){return this._edgesRenderer||(this._edgesRenderer=new Qc(this._scene)),this._edgesRenderer}},{key:"edgesColorRenderer",get:function(){return this._edgesColorRenderer||(this._edgesColorRenderer=new Xc(this._scene)),this._edgesColorRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new ef(this._scene)),this._pickMeshRenderer}},{key:"pickNormalsRenderer",get:function(){return this._pickNormalsRenderer||(this._pickNormalsRenderer=new Ef(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 of(this._scene)),this._pickDepthRenderer}},{key:"vertexDepthRenderer",get:function(){return this._vertexDepthRenderer||(this._vertexDepthRenderer=new df(this._scene)),this._vertexDepthRenderer}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new gf(this._scene)),this._snapDepthBufInitRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new _f(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}(),Wf={};var zf=P((function e(){b(this,e),this.positionsCompressed=[],this.metallicRoughness=[],this.indices8Bits=[],this.indices16Bits=[],this.indices32Bits=[],this.edgeIndices8Bits=[],this.edgeIndices16Bits=[],this.edgeIndices32Bits=[],this.perObjectColors=[],this.perObjectPickColors=[],this.perObjectSolid=[],this.perObjectOffsets=[],this.perObjectPositionsDecodeMatrices=[],this.perObjectInstancePositioningMatrices=[],this.perObjectVertexBases=[],this.perObjectIndexBaseOffsets=[],this.perObjectEdgeIndexBaseOffsets=[],this.perTriangleNumberPortionId8Bits=[],this.perTriangleNumberPortionId16Bits=[],this.perTriangleNumberPortionId32Bits=[],this.perEdgeNumberPortionId8Bits=[],this.perEdgeNumberPortionId16Bits=[],this.perEdgeNumberPortionId32Bits=[]})),Kf=function(){function e(){b(this,e),this.texturePerObjectIdColorsAndFlags=null,this.texturePerObjectIdOffsets=null,this.texturePerObjectIdPositionsDecodeMatrix=null,this.texturePerVertexIdCoordinates=null,this.texturePerPolygonIdPortionIds8Bits=null,this.texturePerPolygonIdPortionIds16Bits=null,this.texturePerPolygonIdPortionIds32Bits=null,this.texturePerEdgeIdPortionIds8Bits=null,this.texturePerEdgeIdPortionIds16Bits=null,this.texturePerEdgeIdPortionIds32Bits=null,this.texturePerPolygonIdIndices8Bits=null,this.texturePerPolygonIdIndices16Bits=null,this.texturePerPolygonIdIndices32Bits=null,this.texturePerPolygonIdEdgeIndices8Bits=null,this.texturePerPolygonIdEdgeIndices16Bits=null,this.texturePerPolygonIdEdgeIndices32Bits=null,this.textureModelMatrices=null}return P(e,[{key:"finalize",value:function(){this.indicesPerBitnessTextures={8:this.texturePerPolygonIdIndices8Bits,16:this.texturePerPolygonIdIndices16Bits,32:this.texturePerPolygonIdIndices32Bits},this.indicesPortionIdsPerBitnessTextures={8:this.texturePerPolygonIdPortionIds8Bits,16:this.texturePerPolygonIdPortionIds16Bits,32:this.texturePerPolygonIdPortionIds32Bits},this.edgeIndicesPerBitnessTextures={8:this.texturePerPolygonIdEdgeIndices8Bits,16:this.texturePerPolygonIdEdgeIndices16Bits,32:this.texturePerPolygonIdEdgeIndices32Bits},this.edgeIndicesPortionIdsPerBitnessTextures={8:this.texturePerEdgeIdPortionIds8Bits,16:this.texturePerEdgeIdPortionIds16Bits,32:this.texturePerEdgeIdPortionIds32Bits}}},{key:"bindCommonTextures",value:function(e,t,n,r,i,a){this.texturePerObjectIdPositionsDecodeMatrix.bindTexture(e,t,1),this.texturePerVertexIdCoordinates.bindTexture(e,n,2),this.texturePerObjectIdColorsAndFlags.bindTexture(e,r,3),this.textureModelMatrices.bindTexture(e,i,4),this.texturePerObjectIdOffsets.bindTexture(e,a,5)}},{key:"bindPickCameraTexture",value:function(e,t){}},{key:"bindTriangleIndicesTextures",value:function(e,t,n,r){this.indicesPortionIdsPerBitnessTextures[r].bindTexture(e,t,6),this.indicesPerBitnessTextures[r].bindTexture(e,n,7)}},{key:"bindEdgeIndicesTextures",value:function(e,t,n,r){this.edgeIndicesPortionIdsPerBitnessTextures[r].bindTexture(e,t,6),this.edgeIndicesPerBitnessTextures[r].bindTexture(e,n,7)}}]),e}(),Yf=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}(),Xf={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(Xf,null,4));var e=0;Object.keys(Xf).forEach((function(t){t.startsWith("size")&&(e+=Xf[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/Xf.totalPolygons).toFixed(2)));var t={};Object.keys(Xf).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((Xf[n]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var qf=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:"generateCameraDataTexture",value:function(e,t,n,r){var i=e.createTexture();e.bindTexture(e.TEXTURE_2D,i),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,4,3),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null);var a=new Yf(e,i,4,3),s=!0;a.updateViewMatrix=function(n,i){e.bindTexture(e.TEXTURE_2D,a._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,4,1,e.RGBA,e.FLOAT,new Float32Array(r?Ie(n,r):n)),e.texSubImage2D(e.TEXTURE_2D,0,0,1,4,1,e.RGBA,e.FLOAT,new Float32Array(t.viewNormalMatrix)),e.texSubImage2D(e.TEXTURE_2D,0,0,2,4,1,e.RGBA,e.FLOAT,new Float32Array(i))};var o=function(){s&&(s=!1,a.updateViewMatrix(t.viewMatrix,t.project.matrix))};return t.on("matrix",(function(){return s=!0})),n.on("rendering",o),o(),a}},{key:"generatePickCameraDataTexture",value:function(e,t,n){var r=e.createTexture();e.bindTexture(e.TEXTURE_2D,r),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,4,3),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null);var i=new Yf(e,r,4,3);return i.updateViewMatrix=function(r,a){e.bindTexture(e.TEXTURE_2D,i._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,4,1,e.RGBA,e.FLOAT,new Float32Array(n?Ie(r,n):r)),e.texSubImage2D(e.TEXTURE_2D,0,0,1,4,1,e.RGBA,e.FLOAT,new Float32Array(t.viewNormalMatrix)),e.texSubImage2D(e.TEXTURE_2D,0,0,2,4,1,e.RGBA,e.FLOAT,new Float32Array(a))},i}},{key:"generateModelTexture",value:function(e,t){var n=e.createTexture();return e.bindTexture(e.TEXTURE_2D,n),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,4,2),e.texSubImage2D(e.TEXTURE_2D,0,0,0,4,1,e.RGBA,e.FLOAT,new Float32Array(t.worldMatrix)),e.texSubImage2D(e.TEXTURE_2D,0,0,1,4,1,e.RGBA,e.FLOAT,new Float32Array(t.worldNormalMatrix)),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,n,4,2)}},{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);Xf.sizeDataColorsAndFlags+=c.byteLength,Xf.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 Yf(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);Xf.sizeDataTextureOffsets+=i.byteLength,Xf.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 Yf(e,a,n,r,i)}},{key:"generateTextureForPositionsDecodeMatrices",value:function(e,t,n){var r=t.length;if(0===r)throw"num decode+entity matrices===0";var i=2048,a=Math.ceil(r/512),s=new Float32Array(8192*a);Xf.sizeDataPositionDecodeMatrices+=s.byteLength,Xf.numberOfTextures++;for(var o=Z.mat4(),l=0;l<t.length;l++)s.set(Z.mulMat4(n[l],t[l],o),16*l);var u=e.createTexture();return e.bindTexture(e.TEXTURE_2D,u),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA32F,i,a),e.texSubImage2D(e.TEXTURE_2D,0,0,0,i,a,e.RGBA,e.FLOAT,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 Yf(e,u,i,a)}},{key:"generateTextureFor8BitIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/3/n);if(0===r)throw"texture height===0";var i=new Uint8Array(n*r*3);Xf.sizeDataTextureIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB8UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RGB_INTEGER,e.UNSIGNED_BYTE,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor16BitIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/3/n);if(0===r)throw"texture height===0";var i=new Uint16Array(n*r*3);Xf.sizeDataTextureIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB16UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RGB_INTEGER,e.UNSIGNED_SHORT,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor32BitIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/3/n);if(0===r)throw"texture height===0";var i=new Uint32Array(n*r*3);Xf.sizeDataTextureIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RGB32UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RGB_INTEGER,e.UNSIGNED_INT,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor8BitsEdgeIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/2/n);if(0===r)throw"texture height===0";var i=new Uint8Array(n*r*2);Xf.sizeDataTextureEdgeIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RG8UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RG_INTEGER,e.UNSIGNED_BYTE,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor16BitsEdgeIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/2/n);if(0===r)throw"texture height===0";var i=new Uint16Array(n*r*2);Xf.sizeDataTextureEdgeIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RG16UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RG_INTEGER,e.UNSIGNED_SHORT,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureFor32BitsEdgeIndices",value:function(e,t){if(0===t.length)return{texture:null,textureHeight:0};var n=4096,r=Math.ceil(t.length/2/n);if(0===r)throw"texture height===0";var i=new Uint32Array(n*r*2);Xf.sizeDataTextureEdgeIndices+=i.byteLength,Xf.numberOfTextures++,i.fill(0),i.set(t,0);var a=e.createTexture();return e.bindTexture(e.TEXTURE_2D,a),e.texStorage2D(e.TEXTURE_2D,1,e.RG32UI,n,r),e.texSubImage2D(e.TEXTURE_2D,0,0,0,n,r,e.RG_INTEGER,e.UNSIGNED_INT,i,0),this.disableBindedTextureFiltering(e),e.bindTexture(e.TEXTURE_2D,null),new Yf(e,a,n,r)}},{key:"generateTextureForPositions",value:function(e,t){var n=t.length/3,r=4096,i=Math.ceil(n/r);if(0===i)throw"texture height===0";var a=new Uint16Array(r*i*3);Xf.sizeDataTexturePositions+=a.byteLength,Xf.numberOfTextures++,a.fill(0),a.set(t,0);var s=e.createTexture();return e.bindTexture(e.TEXTURE_2D,s),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),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 Yf(e,s,r,i)}},{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),Xf.sizeDataTexturePortionIds+=a.byteLength,Xf.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 Yf(e,s,r,i)}}]),e}(),Jf=Z.vec4([0,0,0,1]),Zf=Z.vec4([0,0,0,1]);Z.vec4([0,0,0,1]);var $f=new Uint8Array(4),ep=new Float32Array(3),tp=Z.AABB3(),np=0,rp=Z.identityMat4(),ip=function(){function e(t,n){var r,i,a;b(this,e),Xf.numberOfLayers++,this._layerNumber=np++,this.sortId="TriDTX-".concat(this._layerNumber),this.layerIndex=n.layerIndex,this._dataTextureRenderers=(r=t.scene,i=r.id,(a=Wf[i])||(a=new Qf(r),Wf[i]=a,a._compile(),r.on("compile",(function(){a._compile()})),r.on("destroyed",(function(){delete Wf[i],a._destroy()}))),a),this.model=t,this._buffer=new zf,this._dataTextureState=new Kf,this._dataTextureGenerator=new qf,this._state=new Nt({origin:Z.vec3(n.origin),metallicRoughnessBuf:null,positionsDecodeMatrix:Z.mat4(),textureState:this._dataTextureState,numIndices8Bits:0,numIndices16Bits:0,numIndices32Bits:0,numEdgeIndices8Bits:0,numEdgeIndices16Bits:0,numEdgeIndices32Bits:0,numVertices:0}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._subPortions=[],this._portionToSubPortionsMap=[],this._bucketGeometries={},this.aabb=Z.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&&Xf.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)&&Xf.cannotCreatePortion.becauseTextureSize++,n&&(n=this._state.numVertices+a<=16777216&&i+s<=16777216)}return n}},{key:"createPortion",value:function(e){var t=this;if(this._finalized)throw"Already finalized";var n=[],r=e.worldAABB;e.buckets.forEach((function(i,a){var s=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(a):"".concat(e.id,"#").concat(a),o=t._bucketGeometries[s];o||(o=t._createBucketGeometry(e,i),t._bucketGeometries[s]=o);var l=Z.collapseAABB3(tp),u=t._createSubPortion(e,o,i,l);Z.expandAABB3(r,l),n.push(u)}));var i=this._state.origin;0===i[0]&&0===i[1]&&0===i[2]||(r[0]+=i[0],r[1]+=i[1],r[2]+=i[2],r[3]+=i[0],r[4]+=i[1],r[5]+=i[2]),Z.expandAABB3(this.aabb,r);var a=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(n),this.model.numPortions++,a}},{key:"_createBucketGeometry",value:function(e,t){if(t.indices){var n=8*Math.ceil(t.indices.length/3/8)*3;Xf.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;Xf.overheadSizeAlignementEdgeIndices+=2*(i-t.edgeIndices.length);var a=new Uint32Array(i);a.fill(0),a.set(t.edgeIndices),t.edgeIndices=a}for(var s,o=t.positionsCompressed,l=t.indices,u=t.edgeIndices,c=this._buffer,f=c.positionsCompressed.length/3,p=o.length/3,A=0,d=o.length;A<d;A++)c.positionsCompressed.push(o[A]);var v,h=0;if(l){var I;h=l.length/3,s=(I=p<=256?c.indices8Bits:p<=65536?c.indices16Bits:c.indices32Bits).length/3;for(var y=0,m=l.length;y<m;y++)I.push(l[y])}var w=0;if(u){var g;w=u.length/2,v=(g=p<=256?c.edgeIndices8Bits:p<=65536?c.edgeIndices16Bits:c.edgeIndices32Bits).length/2;for(var T=0,E=u.length;T<E;T++)g.push(u[T])}this._state.numVertices+=p,Xf.numberOfGeometries++;var b=Z.collapseAABB3();return Z.expandAABB3Points3(b,t.positionsCompressed),An.decompressAABB(b,e.positionsDecodeMatrix),{vertexBase:f,numVertices:p,numTriangles:h,numEdges:w,indicesBase:s,edgeIndicesBase:v,aabb:b,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;if(f.perObjectPositionsDecodeMatrices.push(e.positionsDecodeMatrix),f.perObjectInstancePositioningMatrices.push(u||rp),u){t.obb||(t.obb=Z.AABB3ToOBB3(t.aabb));for(var A=t.obb,d=0,v=A.length;d<v;d+=4)Jf[0]=A[d+0],Jf[1]=A[d+1],Jf[2]=A[d+2],Jf[3]=1,u&&Z.transformPoint4(u,Jf,Zf),Z.expandAABB3Point3(r,Zf)}else Z.expandAABB3(r,t.aabb);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 h=this._subPortions.length;if(t.numTriangles>0){var I,y=3*t.numTriangles;t.numVertices<=256?(I=f.perTriangleNumberPortionId8Bits,p.numIndices8Bits+=y,Xf.totalPolygons8Bits+=t.numTriangles):t.numVertices<=65536?(I=f.perTriangleNumberPortionId16Bits,p.numIndices16Bits+=y,Xf.totalPolygons16Bits+=t.numTriangles):(I=f.perTriangleNumberPortionId32Bits,p.numIndices32Bits+=y,Xf.totalPolygons32Bits+=t.numTriangles),Xf.totalPolygons+=t.numTriangles;for(var m=0;m<t.numTriangles;m+=8)I.push(h)}if(t.numEdges>0){var w,g=2*t.numEdges;t.numVertices<=256?(w=f.perEdgeNumberPortionId8Bits,p.numEdgeIndices8Bits+=g,Xf.totalEdges8Bits+=t.numEdges):t.numVertices<=65536?(w=f.perEdgeNumberPortionId16Bits,p.numEdgeIndices16Bits+=g,Xf.totalEdges16Bits+=t.numEdges):(w=f.perEdgeNumberPortionId32Bits,p.numEdgeIndices32Bits+=g,Xf.totalEdges32Bits+=t.numEdges),Xf.totalEdges+=t.numEdges;for(var T=0;T<t.numEdges;T+=8)w.push(h)}return this._subPortions.push({numVertices:t.numTriangles}),this._numPortions++,Xf.numberOfPortions++,h}},{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.texturePerObjectIdColorsAndFlags=this._dataTextureGenerator.generateTextureForColorsAndFlags(r,i.perObjectColors,i.perObjectPickColors,i.perObjectVertexBases,i.perObjectIndexBaseOffsets,i.perObjectEdgeIndexBaseOffsets,i.perObjectSolid),n.texturePerObjectIdOffsets=this._dataTextureGenerator.generateTextureForObjectOffsets(r,this._numPortions),n.texturePerObjectIdPositionsDecodeMatrix=this._dataTextureGenerator.generateTextureForPositionsDecodeMatrices(r,i.perObjectPositionsDecodeMatrices,i.perObjectInstancePositioningMatrices),n.texturePerVertexIdCoordinates=this._dataTextureGenerator.generateTextureForPositions(r,i.positionsCompressed),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.indices8Bits.length>0&&(n.texturePerPolygonIdIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitIndices(r,i.indices8Bits)),i.indices16Bits.length>0&&(n.texturePerPolygonIdIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitIndices(r,i.indices16Bits)),i.indices32Bits.length>0&&(n.texturePerPolygonIdIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitIndices(r,i.indices32Bits)),i.edgeIndices8Bits.length>0&&(n.texturePerPolygonIdEdgeIndices8Bits=this._dataTextureGenerator.generateTextureFor8BitsEdgeIndices(r,i.edgeIndices8Bits)),i.edgeIndices16Bits.length>0&&(n.texturePerPolygonIdEdgeIndices16Bits=this._dataTextureGenerator.generateTextureFor16BitsEdgeIndices(r,i.edgeIndices16Bits)),i.edgeIndices32Bits.length>0&&(n.texturePerPolygonIdEdgeIndices32Bits=this._dataTextureGenerator.generateTextureFor32BitsEdgeIndices(r,i.edgeIndices32Bits)),this.model._modelMatricesTexture||(this.model._modelMatricesTexture=this._dataTextureGenerator.generateModelTexture(r,this.model)),n.textureModelMatrices=this.model._modelMatricesTexture,n.cameraTexture=this._dataTextureGenerator.generateCameraDataTexture(this.model.scene.canvas.gl,this.model.scene.camera,this.model.scene,this._state.origin.slice()),n.textureCameraMatrices=n.cameraTexture,n.texturePickCameraMatrices=this._dataTextureGenerator.generatePickCameraDataTexture(this.model.scene.canvas.gl,this.model.scene.camera,this._state.origin.slice()),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&Te&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&Ce&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&Re&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&_e&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&De&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Be&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&be&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ee&&(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&Te?(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&Ce?(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&Re?(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&_e?(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&Be?(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&De?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags2(e,t)}},{key:"_beginDeferredFlags",value:function(){this._deferredSetFlagsActive=!0}},{key:"_uploadDeferredFlags",value:function(){if(console.info("_uploadDeferredFlags"),this._deferredSetFlagsActive=!1,this._deferredSetFlagsDirty){this._deferredSetFlagsDirty=!1;var e=this.model.scene.canvas.gl,t=this._dataTextureState;e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdColorsAndFlags._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdColorsAndFlags._textureWidth,t.texturePerObjectIdColorsAndFlags._textureHeight,e.RGBA_INTEGER,e.UNSIGNED_BYTE,t.texturePerObjectIdColorsAndFlags._textureData),e.bindTexture(e.TEXTURE_2D,t.texturePerObjectIdOffsets._texture),e.texSubImage2D(e.TEXTURE_2D,0,0,0,t.texturePerObjectIdOffsets._textureWidth,t.texturePerObjectIdOffsets._textureHeight,e.RGB,e.FLOAT,t.texturePerObjectIdOffsets._textureData)}}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(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&be?(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($f[0]=t[0],$f[1]=t[1],$f[2]=t[2],$f[3]=t[3],n.texturePerObjectIdColorsAndFlags._textureData.set($f,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.texturePerObjectIdColorsAndFlags._texture),r.texSubImage2D(r.TEXTURE_2D,0,e%512*8,Math.floor(e/512),1,1,r.RGBA_INTEGER,r.UNSIGNED_BYTE,$f)}},{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&Te),o=!!(t&Re),l=!!(t&Ce),u=!!(t&_e),c=!!(t&Be),f=!!(t&be),p=!!(t&Ee);i=!s||p||o?to.NOT_RENDERED:n?to.COLOR_TRANSPARENT:to.COLOR_OPAQUE,a=!s||p?to.NOT_RENDERED:u?to.SILHOUETTE_SELECTED:l?to.SILHOUETTE_HIGHLIGHTED:o?to.SILHOUETTE_XRAYED:to.NOT_RENDERED;var A=0;A=!s||p?to.NOT_RENDERED:u?to.EDGES_SELECTED:l?to.EDGES_HIGHLIGHTED:o?to.EDGES_XRAYED:c?n?to.EDGES_COLOR_TRANSPARENT:to.EDGES_COLOR_OPAQUE:to.NOT_RENDERED;var d=s&&f?to.PICK:to.NOT_RENDERED,v=this._dataTextureState,h=this.model.scene.canvas.gl;if($f[0]=i,$f[1]=a,$f[2]=A,$f[3]=d,v.texturePerObjectIdColorsAndFlags._textureData.set($f,32*e+8),this._deferredSetFlagsActive||r)return console.info("_subPortionSetFlags set flags defer"),void(this._deferredSetFlagsDirty=!0);++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),console.info("_subPortionSetFlags set flags write through"),h.bindTexture(h.TEXTURE_2D,v.texturePerObjectIdColorsAndFlags._texture),h.texSubImage2D(h.TEXTURE_2D,0,e%512*8+2,Math.floor(e/512),1,1,h.RGBA_INTEGER,h.UNSIGNED_BYTE,$f)}},{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&De?255:0,i=this._dataTextureState,a=this.model.scene.canvas.gl;$f[0]=r,$f[1]=0,$f[2]=1,$f[3]=2,i.texturePerObjectIdColorsAndFlags._textureData.set($f,32*e+12),this._deferredSetFlagsActive||n?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),console.info("_subPortionSetFlags2 set flags write through"),a.bindTexture(a.TEXTURE_2D,i.texturePerObjectIdColorsAndFlags._texture),a.texSubImage2D(a.TEXTURE_2D,0,e%512*8+3,Math.floor(e/512),1,1,a.RGBA_INTEGER,a.UNSIGNED_BYTE,$f))}},{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;ep[0]=t[0],ep[1]=t[1],ep[2]=t[2],n.texturePerObjectIdOffsets._textureData.set(ep,3*e),this._deferredSetFlagsActive?this._deferredSetFlagsDirty=!0:(++this._numUpdatesInFrame>=10&&this._beginDeferredFlags(),r.bindTexture(r.TEXTURE_2D,n.texturePerObjectIdOffsets._texture),r.texSubImage2D(r.TEXTURE_2D,0,0,e,1,1,r.RGB,r.FLOAT,ep))}},{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,to.COLOR_OPAQUE):this._dataTextureRenderers.colorRenderer&&this._dataTextureRenderers.colorRenderer.drawLayer(t,this,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.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,to.COLOR_OPAQUE))}},{key:"setPickMatrices",value:function(e,t){0!==this._numVisibleLayerPortions&&this._dataTextureState.texturePickCameraMatrices.updateViewMatrix(e,t)}},{key:"drawPickMesh",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickMeshRenderer&&this._dataTextureRenderers.pickMeshRenderer.drawLayer(t,this,to.PICK))}},{key:"drawPickDepths",value:function(e,t){0!==this._numVisibleLayerPortions&&(this._updateBackfaceCull(e,t),this._dataTextureRenderers.pickDepthRenderer&&this._dataTextureRenderers.pickDepthRenderer.drawLayer(t,this,to.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,to.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,to.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,to.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}(),ap=Z.vec3();Z.mat4();var sp=Z.vec3([1,1,1]),op=Z.vec3([0,0,0]),lp=Z.vec3([0,0,0]),up=Z.identityQuaternion(),cp=Z.identityMat4(),fp=new Uint8Array([255,255,255]),pp=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._dtxEnabled=r.scene.dtxEnabled&&!1!==i.dtxEnabled,r._enableVertexWelding=!1,r._enableIndexBucketing=!0,r._vboBatchingLayerScratchMemory=eo(),r._textureTranscoder=i.textureTranscoder||Ac(r.scene.viewer),r._maxGeometryBatchSize=i.maxGeometryBatchSize,r._aabb=Z.collapseAABB3(),r._aabbDirty=!0,r._quantizationRanges={},r._vboInstancingLayers={},r._vboBatchingLayers={},r._dtxLayers={},r._meshList=[],r.layerList=[],r._entityList=[],r._geometries={},r._dtxBuckets={},r._textures={},r._textureSets={},r._meshes={},r._entities={},r._scheduledMeshes={},r.renderFlags=new ea,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=Z.vec3(i.origin||[0,0,0]),r._position=Z.vec3(i.position||[0,0,0]),r._rotation=Z.vec3(i.rotation||[0,0,0]),r._quaternion=Z.vec4(i.quaternion||[0,0,0,1]),r._conjugateQuaternion=Z.vec4(i.quaternion||[0,0,0,1]),i.rotation&&Z.eulerToQuaternion(r._rotation,"XYZ",r._quaternion),r._scale=Z.vec3(i.scale||[1,1,1]),r._worldRotationMatrix=Z.mat4(),r._worldRotationMatrixConjugate=Z.mat4(),r._matrix=Z.mat4(),r._matrixDirty=!0,r._rebuildMatrices(),r._worldNormalMatrix=Z.mat4(),Z.inverseMat4(r._matrix,r._worldNormalMatrix),Z.transposeMat4(r._worldNormalMatrix),(i.matrix||i.position||i.rotation||i.scale||i.quaternion)&&(r._viewMatrix=Z.mat4(),r._viewNormalMatrix=Z.mat4(),r._viewMatrixDirty=!0,r._matrixNonIdentity=!0),r._opacity=1,r._colorize=[1,1,1],r._saoEnabled=!1!==i.saoEnabled,r._pbrEnabled=!1!==i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._isModel=i.isModel,r._isModel&&r.scene._registerModel(g(r)),r._onCameraViewMatrix=r.scene.camera.on("matrix",(function(){r._viewMatrixDirty=!0})),r.scene.vfc.enabled&&(r._vfcManager=r.scene.vfc.getVFCManager(g(r))),r._createDefaultTextureSet(),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.backfaces=i.backfaces,r}return P(n,[{key:"_createDefaultTextureSet",value:function(){var e=new nc({id:"defaultColorTexture",texture:new Ha({gl:this.scene.canvas.gl,preloadColor:[1,1,1,1]})}),t=new nc({id:"defaultMetalRoughTexture",texture:new Ha({gl:this.scene.canvas.gl,preloadColor:[0,1,1,1]})}),n=new nc({id:"defaultNormalsTexture",texture:new Ha({gl:this.scene.canvas.gl,preloadColor:[0,0,0,0]})}),r=new nc({id:"defaultEmissiveTexture",texture:new Ha({gl:this.scene.canvas.gl,preloadColor:[0,0,0,1]})}),i=new nc({id:"defaultOcclusionTexture",texture:new Ha({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 tc({id:"defaultTextureSet",model:this,colorTexture:e,metallicRoughnessTexture:t,normalsTexture:n,emissiveTexture:r,occlusionTexture:i})}},{key:"isPerformanceModel",get:function(){return!0}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),Z.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),Z.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||cp),Z.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),Z.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),Z.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),Z.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&(Z.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),Z.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),Z.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),Z.translateMat4v(this._position,this._matrix),this._matrixDirty=!1)}},{key:"rotationMatrixConjugate",get:function(){return this._matrixDirty&&this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0}},{key:"_setLocalAABBDirty",value:function(){for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._setLocalAABBDirty()}},{key:"_setWorldAABBDirty",value:function(){this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._setWorldAABBDirty()}},{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&&(Z.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),Z.inverseMat4(this._viewMatrix,this._viewNormalMatrix),Z.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&&(Z.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),Z.inverseMat4(this._viewMatrix,this._viewNormalMatrix),Z.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1),Z.inverseMat4(this._viewMatrix,this._viewNormalMatrix),Z.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){Z.collapseAABB3(this._aabb);for(var e=0,t=this._entityList.length;e<t;e++)Z.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:Uo(e.aabb,Z.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=Uo(e.positionsDecodeBoundary,Z.mat4())),e.positions){var t=Z.collapseAABB3();e.positionsDecodeMatrix=Z.mat4(),Z.expandAABB3Points3(t,e.positions),e.positionsCompressed=Ho(e.positions,t,e.positionsDecodeMatrix)}else e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed);if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var n=e.colors,r=new Uint8Array(n.length),i=0,a=n.length;i<a;i++)r[i]=255*n[i];e.colorsCompressed=r}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=sn(e.positions,e.indices,null,5):e.edgeIndices=sn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets&&(this._dtxBuckets[e.id]=e.buckets),e.uv){var s=An.getUVBounds(e.uv),o=An.compressUVs(e.uv,s.min,s.max);e.uvCompressed=o.quantized,e.uvDecodeMatrix=o.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(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 Ha({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?ae.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 nc({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])this.error("[createTextureSet] Texture set already created: ".concat(t));else{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 tc({id:t,model:this,colorTexture:n,metallicRoughnessTexture:r,normalsTexture:i,emissiveTexture:a,occlusionTexture:s});this._textureSets[t]=o}else this.error("[createTextureSet] Config missing: id")}},{key:"createMesh",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._scheduledMeshes[e.id])this.error("[createMesh] SceneModel already has a mesh with this ID: ".concat(e.id));else{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?Z.addVec3(this._origin,e.origin,Z.vec3()):this._origin,e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position){var n=e.scale||sp,r=e.position||op,i=e.rotation||lp;Z.eulerToQuaternion(i,"XYZ",up),e.meshMatrix=Z.composeMat4(r,up,n,Z.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Uo(e.positionsDecodeBoundary,Z.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])]):fp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.positions){var a=Z.vec3(),s=[];me(e.positions,s,a)&&(e.positions=s,e.origin=Z.addVec3(e.origin,a,a))}if(e.positions){var o=Z.collapseAABB3();e.positionsDecodeMatrix=Z.mat4(),Z.expandAABB3Points3(o,e.positions),e.positionsCompressed=Ho(e.positions,o,e.positionsDecodeMatrix)}e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=sn(e.positions,e.indices,null,2):e.edgeIndices=sn(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.buckets||(e.buckets=Ap(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 l=[];me(e.positions,l,ap)&&(e.positions=l,e.origin=Z.addVec3(e.origin,ap,Z.vec3()))}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=sn(e.positions,e.indices,null,2):e.edgeIndices=sn(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?Z.addVec3(this._origin,e.origin,Z.vec3()):this._origin,e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.matrix)e.meshMatrix=e.matrix.slice();else{var u=e.scale||sp,c=e.position||op,f=e.rotation||lp;Z.eulerToQuaternion(f,"XYZ",up),e.meshMatrix=Z.composeMat4(c,up,u,Z.mat4())}if(!!this._dtxEnabled&&("triangles"===e.geometry.primitive||"solid"===e.geometry.primitive||"surface"===e.geometry.primitive)){e.type=2,e.color=e.color?new Uint8Array([Math.floor(255*e.color[0]),Math.floor(255*e.color[1]),Math.floor(255*e.color[2])]):fp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255;var p=this._dtxBuckets[e.geometryId];p||(p=Ap(e.geometry,this._enableVertexWelding,this._enableIndexBucketing),this._dtxBuckets[e.geometryId]=p),e.buckets=p}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])]):fp,e.opacity=void 0!==e.opacity&&null!==e.opacity?Math.floor(255*e.opacity):255,e.metallic=void 0!==e.metallic&&null!==e.metallic?Math.floor(255*e.metallic):0,e.roughness=void 0!==e.roughness&&null!==e.roughness?Math.floor(255*e.roughness):255,e.textureSetId&&(e.textureSet=this._textureSets[e.textureSetId]),function(e){if(e.obb=Z.OBB3(),e.positionsCompressed&&e.positionsCompressed.length>0){var t=Z.collapseAABB3();Z.expandAABB3Points3(t,e.positionsCompressed),An.decompressAABB(t,e.positionsDecodeMatrix),Z.AABB3ToOBB3(t,e.obb)}else if(e.positions&&e.positions.length>0){var n=Z.collapseAABB3();Z.expandAABB3Points3(n,e.positions),Z.AABB3ToOBB3(n,e.obb)}}(e.geometry)}e.numPrimitives=this._getNumPrimitives(e),this._vfcManager&&!this._vfcManager.finalized?this._vfcManager.addMesh(e):this._createMesh(e)}else this.error("[createMesh] SceneModel.createMesh() config missing: id")}},{key:"_createMesh",value:function(e){var t=new Js(this,e.id,e.color,e.opacity);t.pickId=this.scene._renderer.getPickID(t);var n=t.pickId,r=n>>24&255,i=n>>16&255,a=n>>8&255,s=255&n;switch(e.pickColor=new Uint8Array([s,a,i,r]),e.worldAABB=Z.collapseAABB3(),e.aabb=e.worldAABB,e.solid="solid"===e.primitive,t.origin=Z.vec3(e.origin),e.type){case 2:t.layer=this._getDTXLayer(e);break;case 1:t.layer=this._getVBOBatchingLayer(e);break;case 0:t.layer=this._getVBOInstancingLayer(e)}t.portionId=t.layer.createPortion(e),t.aabb=e.worldAABB,t.numPrimitives=e.numPrimitives,Z.expandAABB3(this._aabb,t.aabb),this._meshes[e.id]=t,this._meshList.push(t)}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var n=0,r=e.buckets.length;n<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:case 0:t+=e.positions?e.positions.length:e.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(var s=0,o=e.buckets.length;s<o;s++)t+=e.buckets[s].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 console.info("[SceneModel ".concat(this.id,"]: creating TrianglesDataTextureLayer")),r=new ip(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":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesBatchingLayer")),s=new vl({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":console.info("[SceneModel ".concat(this.id,"]: creating LinesBatchingLayer")),s=new hu({model:t,layerIndex:0,scratchMemory:this._vboBatchingLayerScratchMemory,positionsDecodeMatrix:e.positionsDecodeMatrix,uvDecodeMatrix:e.uvDecodeMatrix,origin:n,maxGeometryBatchSize:this._maxGeometryBatchSize});break;case"points":console.info("[SceneModel ".concat(this.id,"]: creating PointsBatchingLayer")),s=new Uu({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":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesInstancingLayer")),s=new lu({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!1});break;case"solid":console.info("[SceneModel ".concat(this.id,"]: creating TrianglesInstancingLayer")),s=new lu({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0,solid:!0});break;case"lines":console.info("[SceneModel ".concat(this.id,"]: creating LinesInstancingLayer")),s=new Pu({model:t,textureSet:o,geometry:l,origin:n,layerIndex:0});break;case"points":console.info("[SceneModel ".concat(this.id,"]: creating PointsInstancingLayer")),s=new ec({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=Z.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=Z.createUUID()),void 0!==e.meshIds){var t=0;if(this._visible&&!1!==e.visible&&(t|=Te),this._pickable&&!1!==e.pickable&&(t|=be),this._culled&&!1!==e.culled&&(t|=Ee),this._clippable&&!1!==e.clippable&&(t|=De),this._collidable&&!1!==e.collidable&&(t|=Pe),this._edges&&!1!==e.edges&&(t|=Be),this._xrayed&&!1!==e.xrayed&&(t|=Re),this._highlighted&&!1!==e.highlighted&&(t|=Ce),this._selected&&!1!==e.selected&&(t|=_e),e.flags=t,this._vfcManager&&!this._vfcManager.finalized){for(var n=0,r=e.meshIds.length;n<r;n++){var i=e.meshIds[n];if(this._scheduledMeshes[i])return void this.error("[createEntity] Mesh not found: ".concat(i))}this._vfcManager.addEntity(e)}else this._createEntity(e)}else this.error("Config missing: meshIds")}},{key:"_createEntity",value:function(e){for(var t=[],n=Z.collapseAABB3(),r=0,i=e.meshIds.length;r<i;r++){var a=e.meshIds[r],s=this._meshes[a];s?s.parent?this.error('Mesh with ID "'.concat(a,'" already belongs to object with ID "').concat(s.parent.id,'" - ignoring this mesh')):(Z.expandAABB3(n,s.aabb),t.push(s)):this.error('Mesh with this ID not found: "'.concat(a,'" - ignoring this mesh'))}var o=new Le(this,e.isObject,e.id,t,e.flags,n,!0);this._entityList.push(o),this._entities[e.id]=o,this.numEntities++}},{key:"finalize",value:function(){if(!this.destroyed){this._vfcManager&&this._vfcManager.finalize((function(){}));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.scene.lod.enabled&&(this._lodManager=this.scene.lod.getLODManager(this)),this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._setWorldAABBDirty(),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);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!==$s&&0==--$s&&Zs._clear(),this._vfcManager&&this.scene.vfc.putVFCManager(this._vfcManager),this._lodManager&&this.scene.lod.putLODManager(this._lodManager),v(T(n.prototype),"destroy",this).call(this)}}]),n}();function Ap(e,t,n){var r,i,a,s;if(t){var o=p(Ic({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=wc(e.indices||[],t),a=Ec(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,T=2*r.length+(i.length+a.length)*w,E=0;return r.length,c.forEach((function(e){E+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*g,e.positionsCompressed.length})),E>T?[e]:(n&&bc(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 dp=function(e){I(n,pp);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)}(),vp=function(e){I(n,ve);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 fa(g(r),{geometry:new hn(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 gn(g(r),{ambient:[0,0,0],diffuse:[0,0,0],specular:[0,0,0],emissive:[1,1,1],emissiveMap:new Qa(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}(),hp=function(){function e(){b(this,e)}return P(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),Ip=Z.vec4(),yp=Z.vec4(),mp=Z.vec3(),wp=Z.vec3(),gp=Z.vec3(),Tp=Z.vec4(),Ep=Z.vec4(),bp=Z.vec4(),Dp=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=Z.subVec3(e,i.eye,mp);r=Z.lenVec3(a)<n}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-n;var s=this._unproject(t,Tp),o=Z.subVec3(s,i.eye,bp),l=Z.mulVec3Scalar(Z.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=Z.subVec3(e,i.eye,mp),c=Z.lenVec3(u),f=Z.mulVec3Scalar(Z.normalizeVec3(Z.subVec3(i.look,i.eye,wp)),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,Ep),d=Z.subVec3(A,p,bp),v=Z.mulVec3Scalar(Z.normalizeVec3(Z.subVec3(i.look,i.eye,mp)),-n,wp),h=Z.addVec3(d,v,gp);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=Z.dotVec4(s,i)/Z.dotVec4(s,a);return n.project.unproject(e,o,Ip,yp,t),t}},{key:"destroy",value:function(){}}]),e}(),Pp=Z.vec3(),Rp=Z.vec3(),Cp=Z.vec3(),_p=Z.vec4(),Bp=Z.vec4(),Op=Z.vec4(),Sp=function(){function e(t,n){var r=this;b(this,e),this._scene=t,this._configs=n,this._pivotWorldPos=Z.vec3(),this._cameraOffset=Z.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=Z.vec3(),this._rtcPos=Z.vec3(),this._pivotViewPos=Z.vec4(),this._pivotProjPos=Z.vec4(),this._pivotCanvasPos=Z.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=Z.vec3();Z.decomposeMat4(Z.inverseMat4(this._scene.viewer.camera.viewMatrix,Z.mat4()),t,Z.vec4(),Z.vec3());var n=Z.distVec3(t,e),r=Math.tan(Math.PI/500)*n*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(r/=this._scene.camera.ortho.scale/2),ye(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Ya(this._scene,da({radius:r})),this._pivotSphere=new fa(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){Z.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,Z.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&&(ye(this.getPivotPos(),this._rtcCenter,this._rtcPos),Z.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 gn(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=Z.lookAtMat4v(e.eye,e.look,e.worldUp);Z.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var n=this.getPivotPos();this._cameraOffset[2]+=Z.distVec3(e.eye,n),t=Z.inverseMat4(t);var r=Z.transformVec3(t,this._cameraOffset),i=Z.vec3();if(Z.subVec3(e.eye,n,i),Z.addVec3(i,r),e.zUp){var a=i[1];i[1]=i[2],i[2]=a}this._radius=Z.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=Z.normalizeVec3(Z.subVec3(e.look,e.eye,Pp)),n=Z.cross3Vec3(t,e.worldUp,Rp);return Z.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(Z.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=Z.dotVec4(s,i)/Z.dotVec4(s,a),l=_p;t.project.unproject(e,o,Bp,Op,l);var u=Z.normalizeVec3(Z.subVec3(l,t.eye,Pp)),c=Z.addVec3(t.eye,Z.mulVec3Scalar(u,n,Rp),Cp);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=Z.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=Z.lenVec3(Z.subVec3(n.look,n.eye,Z.vec3())),l=this.getPivotPos();Z.addVec3(a,l);var u=Z.lookAtMat4v(a,l,n.worldUp);u=Z.inverseMat4(u);var c=Z.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]],Z.subVec3(n.eye,Z.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}(),Np=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=Z.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._needFireEvents=!1}return P(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1,this._needFireEvents=!1;var e=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var t=this._scene.snapPick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapMode:this._configs.snapMode});t&&t.snappedWorldPos?(this.snapPickResult=t,this.snappedOrPicked=!0,this._needFireEvents=!0):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var n=this.pickResult.canvasPos;if(n[0]===this.pickCursorPos[0]&&n[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents=e,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var r=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents=!0):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents=!0)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents=!0)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}},{key:"fireEvents",value:function(){if(this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new at;e.worldPos=this.snapPickResult.snappedWorldPos,e.canvasPos=this.snapPickResult.snappedCanvasPos,"vertex"===this._configs.snapMode?e.snappedToVertex=!0:e.snappedToEdge=!0,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=!1}}},{key:"destroy",value:function(){}}]),e}(),Lp=Z.vec2(),xp=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=Z.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?Z.lenVec3(Z.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,Lp);var t=Lp[0],i=Lp[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:Lp,event:e},!0)}I.style.removeProperty("cursor")}}),I.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var T=1/60,E=null;I.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled){var t=performance.now()/1e3,n=null!==E?t-E:0;E=t,n>.05&&(n=.05),n<T&&(n=T);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}(),Mp=Z.vec3(),Fp=Z.vec3(),Hp=Z.vec3(),Up=Z.vec3(),Gp=Z.vec3(),kp={eye:Z.vec3(),look:Z.vec3(),up:Z.vec3()},jp=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=Z.getAABB3Diag(p);Z.getAABB3Center(p,Mp);var d=Math.abs(A/Math.tan(n.cameraFlight.fitFOV*Z.DEGTORAD)),v=1.1*A;kp.orthoScale=v,e?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldRight,d,Fp),Gp)),kp.look.set(Mp),kp.up.set(s.worldUp)):o?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldForward,d,Fp),Gp)),kp.look.set(Mp),kp.up.set(s.worldUp)):l?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldRight,-d,Fp),Gp)),kp.look.set(Mp),kp.up.set(s.worldUp)):u?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldForward,-d,Fp),Gp)),kp.look.set(Mp),kp.up.set(s.worldUp)):c?(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldUp,d,Fp),Gp)),kp.look.set(Mp),kp.up.set(Z.normalizeVec3(Z.mulVec3Scalar(s.worldForward,1,Hp),Up))):f&&(kp.eye.set(Z.addVec3(Mp,Z.mulVec3Scalar(s.worldUp,-d,Fp),Gp)),kp.look.set(Mp),kp.up.set(Z.normalizeVec3(Z.mulVec3Scalar(s.worldForward,-1,Hp)))),!r.firstPerson&&r.followPointer&&n.pivotController.setPivotPos(Mp),n.cameraFlight.duration>0?n.cameraFlight.flyTo(kp,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(kp),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}(),Vp=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;Z.subVec3(a.eye,a.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})};p.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!c&&!f){var n=u.hasSubs("hover"),a=u.hasSubs("hoverOut"),l=u.hasSubs("hoverOff"),p=u.hasSubs("hoverSurface"),A=u.hasSubs("hoverSnapOrSurface");if(n||a||l||p||A)if(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=p,o.scheduleSnapOrPick=A,o.update(),o.pickResult){if(o.pickResult.entity){var d=o.pickResult.entity.id;s._lastPickedEntityId!==d&&(void 0!==s._lastPickedEntityId&&u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),u.fire("hoverEnter",o.pickResult,!0),s._lastPickedEntityId=d)}u.fire("hover",o.pickResult,!0),(o.pickResult.worldPos||o.pickResult.snappedWorldPos)&&u.fire("hoverSurface",o.pickResult,!0)}else void 0!==s._lastPickedEntityId&&(u.fire("hoverOut",{entity:t.objects[s._lastPickedEntityId]},!0),s._lastPickedEntityId=void 0),u.fire("hoverOff",{canvasPos:o.pickCursorPos},!0)}}),p.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(c=!0),3===e.which&&(f=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickSurface=!0,o.update(),1===e.which))){var n=o.pickResult;n&&n.worldPos?(l.setPivotPos(n.worldPos),l.startPivot()):(r.smartPivot?l.setCanvasPivotPos(i.pointerCanvasPos):l.setPivotPos(t.camera.look),l.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(c=!1),3===e.which&&(f=!1),l.getPivoting()&&l.endPivot()}),p.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(l.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var a=u.hasSubs("picked"),c=u.hasSubs("pickedNothing"),f=u.hasSubs("pickedSurface"),p=u.hasSubs("doublePicked"),d=u.hasSubs("doublePickedSurface"),v=u.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||p||d||v))return(a||c||f)&&(o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=!0,o.schedulePickSurface=f,o.update(),o.pickResult?(u.fire("picked",o.pickResult,!0),o.pickedSurface&&u.fire("pickedSurface",o.pickResult,!0)):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(s._clicks=0);if(s._clicks++,1===s._clicks){o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo,o.schedulePickSurface=f,o.update();var h=o.pickResult,I=o.pickedSurface;s._timeout=setTimeout((function(){h?(u.fire("picked",h,!0),I&&(u.fire("pickedSurface",h,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(h.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):u.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),s._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==s._timeout&&(window.clearTimeout(s._timeout),s._timeout=null),o.pickCursorPos=i.pointerCanvasPos,o.schedulePickEntity=r.doublePickFlyTo||p||d,o.schedulePickSurface=o.schedulePickEntity&&d,o.update(),o.pickResult){if(u.fire("doublePicked",o.pickResult,!0),o.pickedSurface&&u.fire("doublePickedSurface",o.pickResult,!0),r.doublePickFlyTo&&(A(o.pickResult),!r.firstPerson&&r.followPointer)){var y=o.pickResult.entity.aabb,m=Z.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=Z.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}(),Qp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=t.input,o=[],l=t.canvas.canvas,u=!0;this._onSceneMouseMove=s.on("mousemove",(function(){u=!0})),this._onSceneKeyDown=s.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover&&(o[e]=!0,e===s.KEY_SHIFT&&(l.style.cursor="move"))})),this._onSceneKeyUp=s.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(o[e]=!1,e===s.KEY_SHIFT&&(l.style.cursor=null),n.pivotController.getPivoting()&&n.pivotController.endPivot())})),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&i.mouseover){var l=n.cameraControl,c=e.deltaTime/1e3;if(!r.planView){var f=l._isKeyDownForAction(l.ROTATE_Y_POS,o),p=l._isKeyDownForAction(l.ROTATE_Y_NEG,o),A=l._isKeyDownForAction(l.ROTATE_X_POS,o),d=l._isKeyDownForAction(l.ROTATE_X_NEG,o),v=c*r.keyboardRotationRate;(f||p||A||d)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),f?a.rotateDeltaY+=v:p&&(a.rotateDeltaY-=v),A?a.rotateDeltaX+=v:d&&(a.rotateDeltaX-=v),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!o[s.KEY_CTRL]&&!o[s.KEY_ALT]){var h=l._isKeyDownForAction(l.DOLLY_BACKWARDS,o),I=l._isKeyDownForAction(l.DOLLY_FORWARDS,o);if(h||I){var y=c*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),I?a.dollyDelta-=y:h&&(a.dollyDelta+=y),u&&(i.followPointerDirty=!0,u=!1)}}var m=l._isKeyDownForAction(l.PAN_FORWARDS,o),w=l._isKeyDownForAction(l.PAN_BACKWARDS,o),g=l._isKeyDownForAction(l.PAN_LEFT,o),T=l._isKeyDownForAction(l.PAN_RIGHT,o),E=l._isKeyDownForAction(l.PAN_UP,o),b=l._isKeyDownForAction(l.PAN_DOWN,o),D=(o[s.KEY_ALT]?.3:1)*c*r.keyboardPanRate;(m||w||g||T||E||b)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),b?a.panDeltaY+=D:E&&(a.panDeltaY+=-D),T?a.panDeltaX+=-D:g&&(a.panDeltaX+=D),w?a.panDeltaZ+=D:m&&(a.panDeltaZ+=-D))}}))}return P(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),Wp=Z.vec3(),zp=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(Z.lenVec3(Z.subVec3(p,t.camera.eye,Wp)));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=Z.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,T=s.look;s.xUp?(g[0]=m,T[0]=w):s.yUp?(g[1]=m,T[1]=w):s.zUp&&(g[2]=m,T[2]=w),s.eye=g,s.look=T}}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}(),Kp=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){Yp(e,s,i.pointerCanvasPos)}),s.addEventListener("mousedown",this._mouseDownHandler=function(e){r.active&&r.pointerEnabled&&(Yp(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 Yp(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 Xp=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},qp=function(){function e(t,n,r,i,a){b(this,e),this._scene=t;var s=n.pickController,o=n.pivotController,l=Z.vec2(),u=Z.vec2(),c=Z.vec2(),f=Z.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&&(Xp(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(Z.vec2());for(var u=0,c=n.length;u<c;++u)Xp(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){Xp(A[0],u),Z.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];Xp(w,u),Xp(g,c);var T=Z.geometricMeanVec2(p[0],p[1]),E=Z.geometricMeanVec2(u,c),b=Z.vec2();Z.subVec2(T,E,b);var D=b[0],P=b[1],R=t.camera,C=Z.distVec2([w.pageX,w.pageY],[g.pageX,g.pageY]),_=(Z.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(Z.lenVec3(Z.subVec3(B,t.camera.eye,[])))*Math.tan(R.perspective.fov/2*Math.PI/180);a.panDeltaX-=D*O/l*r.touchPanRate,a.panDeltaY-=P*O/l*r.touchPanRate}else a.panDeltaX-=.5*R.ortho.scale*(D/l)*r.touchPanRate,a.panDeltaY-=.5*R.ortho.scale*(P/l)*r.touchPanRate;i.pointerCanvasPos=E}for(var S=0;S<d;++S)Xp(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}(),Jp=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},Zp=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;Z.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,Jp(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)Jp(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?(Jp(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):Z.distVec2(u[0],c)<4&&(Jp(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}(),$p=function(e){I(n,ve);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,snapMode:"vertex",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:Z.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:Z.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 Np(g(r),r._configs),pivotController:new Sp(a,r._configs),panController:new Dp(a),cameraFlight:new _s(g(r),{duration:.5})},r._handlers=[new Kp(r.scene,r._controllers,r._configs,r._states,r._updates),new qp(r.scene,r._controllers,r._configs,r._states,r._updates),new xp(r.scene,r._controllers,r._configs,r._states,r._updates),new jp(r.scene,r._controllers,r._configs,r._states,r._updates),new Vp(r.scene,r._controllers,r._configs,r._states,r._updates),new Zp(r.scene,r._controllers,r._configs,r._states,r._updates),new Qp(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cameraUpdater=new zp(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",ae.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){this._configs.active=!1!==e}},{key:"snapMode",get:function(){return this._configs.snapMode},set:function(e){"vertex"!==(e=e||"vertex")&&"edge"!==e&&(this.error("Unsupported value for snapMode: "+e+" - supported values are 'vertex' and 'edge' - defaulting to 'vertex'"),e="vertex"),this._configs.snapMode=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(T(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}(),eA=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})),tA=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 eA(a.name,a.value,a.type,a.valueType,a.description))}})),nA=function(){function e(t){b(this,e),this.metaModel=null,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||{}}return P(e,[{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}(),rA=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.rootMetaObject=null,this.rootMetaObjects=[],this.metaObjects=[],this.graph=t.graph||{},this.metaScene.metaModels[this.id]=this,this.finalized=!1}return P(e,[{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;if(e.propertySets)for(var r=0,i=e.propertySets.length;r<i;r++){var a=e.propertySets[r],s=n.propertySets[a.id];s||(s=new tA({id:a.id,originalSystemId:a.originalSystemId||a.id,type:a.type,name:a.name,properties:a.properties}),n.propertySets[s.id]=s),s.metaModels.push(this),this.propertySets.push(s)}if(e.metaObjects)for(var o=0,l=e.metaObjects.length;o<l;o++){var u=e.metaObjects[o],c=u.id,f=n.metaObjects[c];if(!f){var p=u.type,A=u.originalSystemId,d=u.propertySets||u.propertySetIds;f=new nA({id:c,originalSystemId:A,parentId:u.parent,type:p,name:u.name,attributes:u.attributes,propertySetIds:d}),this.metaScene.metaObjects[c]=f}f.metaModels.push(this),u.parent||(this.rootMetaObjects.push(f),n.rootMetaObjects[c]=f),this.metaObjects.push(f)}}},{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.originalParentSystemId=a.parent,n&&(a.id=Z.globalizeObjectId(this.id,a.id),a.parent=Z.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(Z.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=Z.globalizeObjectId(this.id,p.id))}}}]),e}(),iA=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 rA({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 T in this.metaObjectsByType={},this.metaObjects){var E=this.metaObjects[T],b=E.type;E.children&&(E.children=null),(this.metaObjectsByType[b]||(this.metaObjectsByType[b]={}))[T]=E}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?aA(t):null,s=n&&n.length>0?aA(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 aA(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=!0;return t}
27
27
  /*!
28
28
  * html2canvas 1.4.1 <https://html2canvas.hertzen.com>
29
29
  * Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>