diff --git a/dist/xeokit-sdk.cjs.js b/dist/xeokit-sdk.cjs.js index f444a2162..15780660d 100644 --- a/dist/xeokit-sdk.cjs.js +++ b/dist/xeokit-sdk.cjs.js @@ -16786,7 +16786,7 @@ class VBOSceneModelRenderer { if (this._aColor) { this._aColor.bindArrayBuffer(state.colorsBuf ? state.colorsBuf : state.colorsBuf); - if (this._instancing && state.geometry && state.colorsBuf) { + if (this._instancing && state.colorsBuf) { gl.vertexAttribDivisor(this._aColor.location, 1); } } @@ -16839,7 +16839,7 @@ class VBOSceneModelRenderer { const scene = this._scene; const gl = scene.canvas.gl; const {_state: state, model} = layer; - const {textureSet, geometry, origin, positionsDecodeMatrix} = state; + const {textureSet, origin, positionsDecodeMatrix} = state; const lightsState = scene._lightsState; const pointsMaterial = scene.pointsMaterial; const {camera} = model.scene; @@ -17022,7 +17022,7 @@ class VBOSceneModelRenderer { } } - this._draw({geometry, state, frameCtx, incrementDrawState}); + this._draw({ state, frameCtx, incrementDrawState}); gl.bindVertexArray(null); } @@ -17087,7 +17087,6 @@ class VBOSceneModelTriangleInstancingRenderer extends VBOSceneModelRenderer { const { state, frameCtx, - geometry, incrementDrawState, } = drawCfg; @@ -17137,7 +17136,6 @@ class VBOSceneModelPointInstancingRenderer extends VBOSceneModelRenderer { const { state, frameCtx, - geometry, incrementDrawState, } = drawCfg; @@ -17177,7 +17175,6 @@ class VBOSceneModelLineInstancingRenderer extends VBOSceneModelRenderer { const { state, - geometry, frameCtx, incrementDrawState, } = drawCfg; diff --git a/dist/xeokit-sdk.es.js b/dist/xeokit-sdk.es.js index bae8d0115..730641336 100644 --- a/dist/xeokit-sdk.es.js +++ b/dist/xeokit-sdk.es.js @@ -16782,7 +16782,7 @@ class VBOSceneModelRenderer { if (this._aColor) { this._aColor.bindArrayBuffer(state.colorsBuf ? state.colorsBuf : state.colorsBuf); - if (this._instancing && state.geometry && state.colorsBuf) { + if (this._instancing && state.colorsBuf) { gl.vertexAttribDivisor(this._aColor.location, 1); } } @@ -16835,7 +16835,7 @@ class VBOSceneModelRenderer { const scene = this._scene; const gl = scene.canvas.gl; const {_state: state, model} = layer; - const {textureSet, geometry, origin, positionsDecodeMatrix} = state; + const {textureSet, origin, positionsDecodeMatrix} = state; const lightsState = scene._lightsState; const pointsMaterial = scene.pointsMaterial; const {camera} = model.scene; @@ -17018,7 +17018,7 @@ class VBOSceneModelRenderer { } } - this._draw({geometry, state, frameCtx, incrementDrawState}); + this._draw({ state, frameCtx, incrementDrawState}); gl.bindVertexArray(null); } @@ -17083,7 +17083,6 @@ class VBOSceneModelTriangleInstancingRenderer extends VBOSceneModelRenderer { const { state, frameCtx, - geometry, incrementDrawState, } = drawCfg; @@ -17133,7 +17132,6 @@ class VBOSceneModelPointInstancingRenderer extends VBOSceneModelRenderer { const { state, frameCtx, - geometry, incrementDrawState, } = drawCfg; @@ -17173,7 +17171,6 @@ class VBOSceneModelLineInstancingRenderer extends VBOSceneModelRenderer { const { state, - geometry, frameCtx, incrementDrawState, } = drawCfg; diff --git a/dist/xeokit-sdk.es5.js b/dist/xeokit-sdk.es5.js index a582f1fbe..72f58e146 100644 --- a/dist/xeokit-sdk.es5.js +++ b/dist/xeokit-sdk.es5.js @@ -4001,8 +4001,8 @@ var x=array[i]/(Math.abs(array[i])+Math.abs(array[i+1])+Math.abs(array[i+2]));va * @returns { string } */_createClass(VBOSceneModelRenderer,[{key:"_getHash",value:function _getHash(){return this._scene._sectionPlanesState.getHash();}},{key:"_buildShader",value:function _buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()};}},{key:"_buildVertexShader",value:function _buildVertexShader(){return[""];}},{key:"_buildFragmentShader",value:function _buildFragmentShader(){return[""];}},{key:"_addMatricesUniformBlockLines",value:function _addMatricesUniformBlockLines(src){var normals=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;src.push("uniform Matrices {");src.push(" mat4 worldMatrix;");src.push(" mat4 viewMatrix;");src.push(" mat4 projMatrix;");src.push(" mat4 positionsDecodeMatrix;");if(normals){src.push(" mat4 worldNormalMatrix;");src.push(" mat4 viewNormalMatrix;");}src.push("};");return src;}},{key:"getValid",value:function getValid(){return this._hash===this._getHash();}},{key:"setSectionPlanesStateUniforms",value:function setSectionPlanesStateUniforms(layer){var scene=this._scene;var gl=scene.canvas.gl;var model=layer.model,layerIndex=layer.layerIndex;var numSectionPlanes=scene._sectionPlanesState.sectionPlanes.length;if(numSectionPlanes>0){var sectionPlanes=scene._sectionPlanesState.sectionPlanes;var baseIndex=layerIndex*numSectionPlanes;var renderFlags=model.renderFlags;for(var sectionPlaneIndex=0;sectionPlaneIndex0){this._uReflectionMap="reflectionMap";}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}this._uSectionPlanes=[];for(var _i62=0,_len5=scene._sectionPlanesState.sectionPlanes.length;_i62<_len5;_i62++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i62),pos:program.getLocation("sectionPlanePos"+_i62),dir:program.getLocation("sectionPlaneDir"+_i62)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aUV=program.getAttribute("uv");this._aColor=program.getAttribute("color");this._aMetallicRoughness=program.getAttribute("metallicRoughness");this._aFlags=program.getAttribute("flags");this._aPickColor=program.getAttribute("pickColor");this._uPickZNear=program.getLocation("pickZNear");this._uPickZFar=program.getLocation("pickZFar");this._uColorMap="uColorMap";this._uMetallicRoughMap="uMetallicRoughMap";this._uEmissiveMap="uEmissiveMap";this._uNormalMap="uNormalMap";this._uAOMap="uAOMap";if(this._instancing){this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._aModelNormalMatrixCol0=program.getAttribute("modelNormalMatrixCol0");this._aModelNormalMatrixCol1=program.getAttribute("modelNormalMatrixCol1");this._aModelNormalMatrixCol2=program.getAttribute("modelNormalMatrixCol2");}if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}if(scene.pointsMaterial._state.filterIntensity){this._uIntensityRange=program.getLocation("intensityRange");}this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;program.bind();frameCtx.textureUnit=0;if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,lightsState.getAmbientColorAndIntensity());}for(var _i63=0,len=lights.length;_i633&&arguments[3]!==undefined?arguments[3]:{},_ref5$colorUniform=_ref5.colorUniform,colorUniform=_ref5$colorUniform===void 0?false:_ref5$colorUniform,_ref5$incrementDrawSt=_ref5.incrementDrawState,incrementDrawState=_ref5$incrementDrawSt===void 0?false:_ref5$incrementDrawSt;var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var scene=this._scene;var gl=scene.canvas.gl;var state=layer._state,model=layer.model;var textureSet=state.textureSet,geometry=state.geometry,origin=state.origin,positionsDecodeMatrix=state.positionsDecodeMatrix;var lightsState=scene._lightsState;var pointsMaterial=scene.pointsMaterial;var camera=model.scene.camera;var viewNormalMatrix=camera.viewNormalMatrix,project=camera.project;var viewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var worldMatrix=model.worldMatrix,worldNormalMatrix=model.worldNormalMatrix;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}if(this._vaoCache.has(layer)){gl.bindVertexArray(this._vaoCache.get(layer));}else{this._vaoCache.set(layer,this._makeVAO(state));}var offset=0;var mat4Size=4*4;this._matricesUniformBlockBufferData.set(worldMatrix,0);this._matricesUniformBlockBufferData.set(origin?createRTCViewMat(viewMatrix,origin):viewMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(frameCtx.pickProjMatrix||project.matrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(positionsDecodeMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(worldNormalMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(viewNormalMatrix,offset+=mat4Size);gl.bindBuffer(gl.UNIFORM_BUFFER,this._matricesUniformBlockBuffer);gl.bufferData(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,gl.DYNAMIC_DRAW);gl.bindBufferBase(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);gl.uniform1i(this._uRenderPass,renderPass);this.setSectionPlanesStateUniforms(layer);if(scene.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix? -gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}if(this._uZFar){gl.uniform1f(this._uZFar,scene.camera.project.far);}}if(this._uPickInvisible){gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);}if(this._uPickZNear){gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);}if(this._uPickZFar){gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);}if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,state.positionsDecodeMatrix);}if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,this._instancing?state.uvDecodeMatrix:state.uvDecodeMatrix);}if(this._uIntensityRange&&pointsMaterial.filterIntensity){gl.uniform2f(this._uIntensityRange,pointsMaterial.minIntensity,pointsMaterial.maxIntensity);}if(this._uPointSize){gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);}if(this._uNearPlaneHeight){var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);}if(textureSet){var colorTexture=textureSet.colorTexture,metallicRoughnessTexture=textureSet.metallicRoughnessTexture,emissiveTexture=textureSet.emissiveTexture,normalsTexture=textureSet.normalsTexture,occlusionTexture=textureSet.occlusionTexture;if(this._uColorMap&&colorTexture){this._program.bindTexture(this._uColorMap,colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uMetallicRoughMap&&metallicRoughnessTexture){this._program.bindTexture(this._uMetallicRoughMap,metallicRoughnessTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uEmissiveMap&&emissiveTexture){this._program.bindTexture(this._uEmissiveMap,emissiveTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uNormalMap&&normalsTexture){this._program.bindTexture(this._uNormalMap,normalsTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uAOMap&&occlusionTexture){this._program.bindTexture(this._uAOMap,occlusionTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}}if(lightsState.reflectionMaps.length>0&&lightsState.reflectionMaps[0].texture&&this._uReflectionMap){this._program.bindTexture(this._uReflectionMap,lightsState.reflectionMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(lightsState.lightMaps.length>0&&lightsState.lightMaps[0].texture&&this._uLightMap){this._program.bindTexture(this._uLightMap,lightsState.lightMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$2[0]=viewportWidth;tempVec4$2[1]=viewportHeight;tempVec4$2[2]=sao.blendCutoff;tempVec4$2[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$2);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}if(colorUniform){var colorKey=this._edges?"edgeColor":"fillColor";var alphaKey=this._edges?"edgeAlpha":"fillAlpha";if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var material=scene.xrayMaterial._state;var _color2=material[colorKey];var alpha=material[alphaKey];gl.uniform4f(this._uColor,_color2[0],_color2[1],_color2[2],alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var _material=scene.highlightMaterial._state;var _color3=_material[colorKey];var _alpha=_material[alphaKey];gl.uniform4f(this._uColor,_color3[0],_color3[1],_color3[2],_alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var _material2=scene.selectedMaterial._state;var _color4=_material2[colorKey];var _alpha2=_material2[alphaKey];gl.uniform4f(this._uColor,_color4[0],_color4[1],_color4[2],_alpha2);}else{gl.uniform4fv(this._uColor,this._edges?edgesDefaultColor:defaultColor$2);}}this._draw({geometry:geometry,state:state,frameCtx:frameCtx,incrementDrawState:incrementDrawState});gl.bindVertexArray(null);}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;stats.memory.programs--;}}]);return VBOSceneModelRenderer;}();var VBOSceneModelTriangleBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere){_inherits(VBOSceneModelTriangleBatchingRenderer,_VBOSceneModelRendere);var _super10=_createSuper(VBOSceneModelTriangleBatchingRenderer);function VBOSceneModelTriangleBatchingRenderer(scene,withSAO){var _ref6=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref6$instancing=_ref6.instancing,instancing=_ref6$instancing===void 0?false:_ref6$instancing,_ref6$edges=_ref6.edges,edges=_ref6$edges===void 0?false:_ref6$edges;_classCallCheck(this,VBOSceneModelTriangleBatchingRenderer);return _super10.call(this,scene,withSAO,{instancing:instancing,edges:edges});}_createClass(VBOSceneModelTriangleBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){gl.drawElements(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0);}else{var count=frameCtx.pickElementsCount||state.indicesBuf.numItems;var offset=frameCtx.pickElementsOffset?frameCtx.pickElementsOffset*state.indicesBuf.itemByteSize:0;gl.drawElements(gl.TRIANGLES,count,state.indicesBuf.itemType,offset);if(incrementDrawState){frameCtx.drawElements++;}}}}]);return VBOSceneModelTriangleBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelTriangleBatchingEdgesRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl){_inherits(VBOSceneModelTriangleBatchingEdgesRenderer,_VBOSceneModelTriangl);var _super11=_createSuper(VBOSceneModelTriangleBatchingEdgesRenderer);function VBOSceneModelTriangleBatchingEdgesRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelTriangleBatchingEdgesRenderer);return _super11.call(this,scene,withSAO,{instancing:false,edges:true});}return _createClass(VBOSceneModelTriangleBatchingEdgesRenderer);}(VBOSceneModelTriangleBatchingRenderer);var VBOSceneModelTriangleInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere2){_inherits(VBOSceneModelTriangleInstancingRenderer,_VBOSceneModelRendere2);var _super12=_createSuper(VBOSceneModelTriangleInstancingRenderer);function VBOSceneModelTriangleInstancingRenderer(scene,withSAO){var _ref7=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref7$edges=_ref7.edges,edges=_ref7$edges===void 0?false:_ref7$edges;_classCallCheck(this,VBOSceneModelTriangleInstancingRenderer);return _super12.call(this,scene,withSAO,{instancing:true,edges:edges});}_createClass(VBOSceneModelTriangleInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,geometry=drawCfg.geometry,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){gl.drawElementsInstanced(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0,state.numInstances);}else{gl.drawElementsInstanced(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0,state.numInstances);if(incrementDrawState){frameCtx.drawElements++;}}}}]);return VBOSceneModelTriangleInstancingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelTriangleInstancingEdgesRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl2){_inherits(VBOSceneModelTriangleInstancingEdgesRenderer,_VBOSceneModelTriangl2);var _super13=_createSuper(VBOSceneModelTriangleInstancingEdgesRenderer);function VBOSceneModelTriangleInstancingEdgesRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelTriangleInstancingEdgesRenderer);return _super13.call(this,scene,withSAO,{instancing:true,edges:true});}return _createClass(VBOSceneModelTriangleInstancingEdgesRenderer);}(VBOSceneModelTriangleInstancingRenderer);var VBOSceneModelPointBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere3){_inherits(VBOSceneModelPointBatchingRenderer,_VBOSceneModelRendere3);var _super14=_createSuper(VBOSceneModelPointBatchingRenderer);function VBOSceneModelPointBatchingRenderer(){_classCallCheck(this,VBOSceneModelPointBatchingRenderer);return _super14.apply(this,arguments);}_createClass(VBOSceneModelPointBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawArrays(gl.POINTS,0,state.positionsBuf.numItems);if(incrementDrawState){frameCtx.drawArrays++;}}}]);return VBOSceneModelPointBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelPointInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere4){_inherits(VBOSceneModelPointInstancingRenderer,_VBOSceneModelRendere4);var _super15=_createSuper(VBOSceneModelPointInstancingRenderer);function VBOSceneModelPointInstancingRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelPointInstancingRenderer);return _super15.call(this,scene,withSAO,{instancing:true});}_createClass(VBOSceneModelPointInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,geometry=drawCfg.geometry,incrementDrawState=drawCfg.incrementDrawState;gl.drawArraysInstanced(gl.POINTS,0,state.positionsBuf.numItems,state.numInstances);if(incrementDrawState){frameCtx.drawArrays++;}}}]);return VBOSceneModelPointInstancingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelLineBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere5){_inherits(VBOSceneModelLineBatchingRenderer,_VBOSceneModelRendere5);var _super16=_createSuper(VBOSceneModelLineBatchingRenderer);function VBOSceneModelLineBatchingRenderer(){_classCallCheck(this,VBOSceneModelLineBatchingRenderer);return _super16.apply(this,arguments);}_createClass(VBOSceneModelLineBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawElements(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);if(incrementDrawState){frameCtx.drawElements++;}}}]);return VBOSceneModelLineBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelLineInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere6){_inherits(VBOSceneModelLineInstancingRenderer,_VBOSceneModelRendere6);var _super17=_createSuper(VBOSceneModelLineInstancingRenderer);function VBOSceneModelLineInstancingRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelLineInstancingRenderer);return _super17.call(this,scene,withSAO,{instancing:true});}_createClass(VBOSceneModelLineInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,geometry=drawCfg.geometry,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawElementsInstanced(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0,state.numInstances);if(incrementDrawState){frameCtx.drawElements++;}}}]);return VBOSceneModelLineInstancingRenderer;}(VBOSceneModelRenderer);/** +var lights=lightsState.lights;var light;for(var _i61=0,len=lights.length;_i610){this._uReflectionMap="reflectionMap";}if(lightsState.lightMaps.length>0){this._uLightMap="lightMap";}this._uSectionPlanes=[];for(var _i62=0,_len5=scene._sectionPlanesState.sectionPlanes.length;_i62<_len5;_i62++){this._uSectionPlanes.push({active:program.getLocation("sectionPlaneActive"+_i62),pos:program.getLocation("sectionPlanePos"+_i62),dir:program.getLocation("sectionPlaneDir"+_i62)});}this._aPosition=program.getAttribute("position");this._aOffset=program.getAttribute("offset");this._aNormal=program.getAttribute("normal");this._aUV=program.getAttribute("uv");this._aColor=program.getAttribute("color");this._aMetallicRoughness=program.getAttribute("metallicRoughness");this._aFlags=program.getAttribute("flags");this._aPickColor=program.getAttribute("pickColor");this._uPickZNear=program.getLocation("pickZNear");this._uPickZFar=program.getLocation("pickZFar");this._uColorMap="uColorMap";this._uMetallicRoughMap="uMetallicRoughMap";this._uEmissiveMap="uEmissiveMap";this._uNormalMap="uNormalMap";this._uAOMap="uAOMap";if(this._instancing){this._aModelMatrixCol0=program.getAttribute("modelMatrixCol0");this._aModelMatrixCol1=program.getAttribute("modelMatrixCol1");this._aModelMatrixCol2=program.getAttribute("modelMatrixCol2");this._aModelNormalMatrixCol0=program.getAttribute("modelNormalMatrixCol0");this._aModelNormalMatrixCol1=program.getAttribute("modelNormalMatrixCol1");this._aModelNormalMatrixCol2=program.getAttribute("modelNormalMatrixCol2");}if(this._withSAO){this._uOcclusionTexture="uOcclusionTexture";this._uSAOParams=program.getLocation("uSAOParams");}if(scene.logarithmicDepthBufferEnabled){this._uLogDepthBufFC=program.getLocation("logDepthBufFC");}if(scene.pointsMaterial._state.filterIntensity){this._uIntensityRange=program.getLocation("intensityRange");}this._uPointSize=program.getLocation("pointSize");this._uNearPlaneHeight=program.getLocation("nearPlaneHeight");}},{key:"_bindProgram",value:function _bindProgram(frameCtx){var scene=this._scene;var gl=scene.canvas.gl;var program=this._program;var lightsState=scene._lightsState;var lights=lightsState.lights;var project=scene.camera.project;program.bind();frameCtx.textureUnit=0;if(this._uLightAmbient){gl.uniform4fv(this._uLightAmbient,lightsState.getAmbientColorAndIntensity());}for(var _i63=0,len=lights.length;_i633&&arguments[3]!==undefined?arguments[3]:{},_ref5$colorUniform=_ref5.colorUniform,colorUniform=_ref5$colorUniform===void 0?false:_ref5$colorUniform,_ref5$incrementDrawSt=_ref5.incrementDrawState,incrementDrawState=_ref5$incrementDrawSt===void 0?false:_ref5$incrementDrawSt;var maxTextureUnits=WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;var scene=this._scene;var gl=scene.canvas.gl;var state=layer._state,model=layer.model;var textureSet=state.textureSet,origin=state.origin,positionsDecodeMatrix=state.positionsDecodeMatrix;var lightsState=scene._lightsState;var pointsMaterial=scene.pointsMaterial;var camera=model.scene.camera;var viewNormalMatrix=camera.viewNormalMatrix,project=camera.project;var viewMatrix=frameCtx.pickViewMatrix||camera.viewMatrix;var worldMatrix=model.worldMatrix,worldNormalMatrix=model.worldNormalMatrix;if(!this._program){this._allocate();if(this.errors){return;}}if(frameCtx.lastProgramId!==this._program.id){frameCtx.lastProgramId=this._program.id;this._bindProgram(frameCtx);}if(this._vaoCache.has(layer)){gl.bindVertexArray(this._vaoCache.get(layer));}else{this._vaoCache.set(layer,this._makeVAO(state));}var offset=0;var mat4Size=4*4;this._matricesUniformBlockBufferData.set(worldMatrix,0);this._matricesUniformBlockBufferData.set(origin?createRTCViewMat(viewMatrix,origin):viewMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(frameCtx.pickProjMatrix||project.matrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(positionsDecodeMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(worldNormalMatrix,offset+=mat4Size);this._matricesUniformBlockBufferData.set(viewNormalMatrix,offset+=mat4Size);gl.bindBuffer(gl.UNIFORM_BUFFER,this._matricesUniformBlockBuffer);gl.bufferData(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,gl.DYNAMIC_DRAW);gl.bindBufferBase(gl.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer);gl.uniform1i(this._uRenderPass,renderPass);this.setSectionPlanesStateUniforms(layer);if(scene.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var logDepthBufFC=2.0/(Math.log(frameCtx.pickZFar+1.0)/Math.LN2);// TODO: Far from pick project matrix? +gl.uniform1f(this._uLogDepthBufFC,logDepthBufFC);}if(this._uZFar){gl.uniform1f(this._uZFar,scene.camera.project.far);}}if(this._uPickInvisible){gl.uniform1i(this._uPickInvisible,frameCtx.pickInvisible);}if(this._uPickZNear){gl.uniform1f(this._uPickZNear,frameCtx.pickZNear);}if(this._uPickZFar){gl.uniform1f(this._uPickZFar,frameCtx.pickZFar);}if(this._uPositionsDecodeMatrix){gl.uniformMatrix4fv(this._uPositionsDecodeMatrix,false,state.positionsDecodeMatrix);}if(this._uUVDecodeMatrix){gl.uniformMatrix3fv(this._uUVDecodeMatrix,false,this._instancing?state.uvDecodeMatrix:state.uvDecodeMatrix);}if(this._uIntensityRange&&pointsMaterial.filterIntensity){gl.uniform2f(this._uIntensityRange,pointsMaterial.minIntensity,pointsMaterial.maxIntensity);}if(this._uPointSize){gl.uniform1f(this._uPointSize,pointsMaterial.pointSize);}if(this._uNearPlaneHeight){var nearPlaneHeight=scene.camera.projection==="ortho"?1.0:gl.drawingBufferHeight/(2*Math.tan(0.5*scene.camera.perspective.fov*Math.PI/180.0));gl.uniform1f(this._uNearPlaneHeight,nearPlaneHeight);}if(textureSet){var colorTexture=textureSet.colorTexture,metallicRoughnessTexture=textureSet.metallicRoughnessTexture,emissiveTexture=textureSet.emissiveTexture,normalsTexture=textureSet.normalsTexture,occlusionTexture=textureSet.occlusionTexture;if(this._uColorMap&&colorTexture){this._program.bindTexture(this._uColorMap,colorTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uMetallicRoughMap&&metallicRoughnessTexture){this._program.bindTexture(this._uMetallicRoughMap,metallicRoughnessTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uEmissiveMap&&emissiveTexture){this._program.bindTexture(this._uEmissiveMap,emissiveTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uNormalMap&&normalsTexture){this._program.bindTexture(this._uNormalMap,normalsTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}if(this._uAOMap&&occlusionTexture){this._program.bindTexture(this._uAOMap,occlusionTexture.texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;}}if(lightsState.reflectionMaps.length>0&&lightsState.reflectionMaps[0].texture&&this._uReflectionMap){this._program.bindTexture(this._uReflectionMap,lightsState.reflectionMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(lightsState.lightMaps.length>0&&lightsState.lightMaps[0].texture&&this._uLightMap){this._program.bindTexture(this._uLightMap,lightsState.lightMaps[0].texture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}if(this._withSAO){var sao=scene.sao;var saoEnabled=sao.possible;if(saoEnabled){var viewportWidth=gl.drawingBufferWidth;var viewportHeight=gl.drawingBufferHeight;tempVec4$2[0]=viewportWidth;tempVec4$2[1]=viewportHeight;tempVec4$2[2]=sao.blendCutoff;tempVec4$2[3]=sao.blendFactor;gl.uniform4fv(this._uSAOParams,tempVec4$2);this._program.bindTexture(this._uOcclusionTexture,frameCtx.occlusionTexture,frameCtx.textureUnit);frameCtx.textureUnit=(frameCtx.textureUnit+1)%maxTextureUnits;frameCtx.bindTexture++;}}if(colorUniform){var colorKey=this._edges?"edgeColor":"fillColor";var alphaKey=this._edges?"edgeAlpha":"fillAlpha";if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var material=scene.xrayMaterial._state;var _color2=material[colorKey];var alpha=material[alphaKey];gl.uniform4f(this._uColor,_color2[0],_color2[1],_color2[2],alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var _material=scene.highlightMaterial._state;var _color3=_material[colorKey];var _alpha=_material[alphaKey];gl.uniform4f(this._uColor,_color3[0],_color3[1],_color3[2],_alpha);}else if(renderPass===RENDER_PASSES["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var _material2=scene.selectedMaterial._state;var _color4=_material2[colorKey];var _alpha2=_material2[alphaKey];gl.uniform4f(this._uColor,_color4[0],_color4[1],_color4[2],_alpha2);}else{gl.uniform4fv(this._uColor,this._edges?edgesDefaultColor:defaultColor$2);}}this._draw({state:state,frameCtx:frameCtx,incrementDrawState:incrementDrawState});gl.bindVertexArray(null);}},{key:"webglContextRestored",value:function webglContextRestored(){this._program=null;}},{key:"destroy",value:function destroy(){if(this._program){this._program.destroy();}this._program=null;stats.memory.programs--;}}]);return VBOSceneModelRenderer;}();var VBOSceneModelTriangleBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere){_inherits(VBOSceneModelTriangleBatchingRenderer,_VBOSceneModelRendere);var _super10=_createSuper(VBOSceneModelTriangleBatchingRenderer);function VBOSceneModelTriangleBatchingRenderer(scene,withSAO){var _ref6=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref6$instancing=_ref6.instancing,instancing=_ref6$instancing===void 0?false:_ref6$instancing,_ref6$edges=_ref6.edges,edges=_ref6$edges===void 0?false:_ref6$edges;_classCallCheck(this,VBOSceneModelTriangleBatchingRenderer);return _super10.call(this,scene,withSAO,{instancing:instancing,edges:edges});}_createClass(VBOSceneModelTriangleBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){gl.drawElements(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0);}else{var count=frameCtx.pickElementsCount||state.indicesBuf.numItems;var offset=frameCtx.pickElementsOffset?frameCtx.pickElementsOffset*state.indicesBuf.itemByteSize:0;gl.drawElements(gl.TRIANGLES,count,state.indicesBuf.itemType,offset);if(incrementDrawState){frameCtx.drawElements++;}}}}]);return VBOSceneModelTriangleBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelTriangleBatchingEdgesRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl){_inherits(VBOSceneModelTriangleBatchingEdgesRenderer,_VBOSceneModelTriangl);var _super11=_createSuper(VBOSceneModelTriangleBatchingEdgesRenderer);function VBOSceneModelTriangleBatchingEdgesRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelTriangleBatchingEdgesRenderer);return _super11.call(this,scene,withSAO,{instancing:false,edges:true});}return _createClass(VBOSceneModelTriangleBatchingEdgesRenderer);}(VBOSceneModelTriangleBatchingRenderer);var VBOSceneModelTriangleInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere2){_inherits(VBOSceneModelTriangleInstancingRenderer,_VBOSceneModelRendere2);var _super12=_createSuper(VBOSceneModelTriangleInstancingRenderer);function VBOSceneModelTriangleInstancingRenderer(scene,withSAO){var _ref7=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{},_ref7$edges=_ref7.edges,edges=_ref7$edges===void 0?false:_ref7$edges;_classCallCheck(this,VBOSceneModelTriangleInstancingRenderer);return _super12.call(this,scene,withSAO,{instancing:true,edges:edges});}_createClass(VBOSceneModelTriangleInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;if(this._edges){gl.drawElementsInstanced(gl.LINES,state.edgeIndicesBuf.numItems,state.edgeIndicesBuf.itemType,0,state.numInstances);}else{gl.drawElementsInstanced(gl.TRIANGLES,state.indicesBuf.numItems,state.indicesBuf.itemType,0,state.numInstances);if(incrementDrawState){frameCtx.drawElements++;}}}}]);return VBOSceneModelTriangleInstancingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelTriangleInstancingEdgesRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl2){_inherits(VBOSceneModelTriangleInstancingEdgesRenderer,_VBOSceneModelTriangl2);var _super13=_createSuper(VBOSceneModelTriangleInstancingEdgesRenderer);function VBOSceneModelTriangleInstancingEdgesRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelTriangleInstancingEdgesRenderer);return _super13.call(this,scene,withSAO,{instancing:true,edges:true});}return _createClass(VBOSceneModelTriangleInstancingEdgesRenderer);}(VBOSceneModelTriangleInstancingRenderer);var VBOSceneModelPointBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere3){_inherits(VBOSceneModelPointBatchingRenderer,_VBOSceneModelRendere3);var _super14=_createSuper(VBOSceneModelPointBatchingRenderer);function VBOSceneModelPointBatchingRenderer(){_classCallCheck(this,VBOSceneModelPointBatchingRenderer);return _super14.apply(this,arguments);}_createClass(VBOSceneModelPointBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawArrays(gl.POINTS,0,state.positionsBuf.numItems);if(incrementDrawState){frameCtx.drawArrays++;}}}]);return VBOSceneModelPointBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelPointInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere4){_inherits(VBOSceneModelPointInstancingRenderer,_VBOSceneModelRendere4);var _super15=_createSuper(VBOSceneModelPointInstancingRenderer);function VBOSceneModelPointInstancingRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelPointInstancingRenderer);return _super15.call(this,scene,withSAO,{instancing:true});}_createClass(VBOSceneModelPointInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawArraysInstanced(gl.POINTS,0,state.positionsBuf.numItems,state.numInstances);if(incrementDrawState){frameCtx.drawArrays++;}}}]);return VBOSceneModelPointInstancingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelLineBatchingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere5){_inherits(VBOSceneModelLineBatchingRenderer,_VBOSceneModelRendere5);var _super16=_createSuper(VBOSceneModelLineBatchingRenderer);function VBOSceneModelLineBatchingRenderer(){_classCallCheck(this,VBOSceneModelLineBatchingRenderer);return _super16.apply(this,arguments);}_createClass(VBOSceneModelLineBatchingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawElements(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0);if(incrementDrawState){frameCtx.drawElements++;}}}]);return VBOSceneModelLineBatchingRenderer;}(VBOSceneModelRenderer);var VBOSceneModelLineInstancingRenderer=/*#__PURE__*/function(_VBOSceneModelRendere6){_inherits(VBOSceneModelLineInstancingRenderer,_VBOSceneModelRendere6);var _super17=_createSuper(VBOSceneModelLineInstancingRenderer);function VBOSceneModelLineInstancingRenderer(scene,withSAO){_classCallCheck(this,VBOSceneModelLineInstancingRenderer);return _super17.call(this,scene,withSAO,{instancing:true});}_createClass(VBOSceneModelLineInstancingRenderer,[{key:"_draw",value:function _draw(drawCfg){var gl=this._scene.canvas.gl;var state=drawCfg.state,frameCtx=drawCfg.frameCtx,incrementDrawState=drawCfg.incrementDrawState;gl.drawElementsInstanced(gl.LINES,state.indicesBuf.numItems,state.indicesBuf.itemType,0,state.numInstances);if(incrementDrawState){frameCtx.drawElements++;}}}]);return VBOSceneModelLineInstancingRenderer;}(VBOSceneModelRenderer);/** * @private */var TrianglesBatchingColorRenderer=/*#__PURE__*/function(_VBOSceneModelTriangl3){_inherits(TrianglesBatchingColorRenderer,_VBOSceneModelTriangl3);var _super18=_createSuper(TrianglesBatchingColorRenderer);function TrianglesBatchingColorRenderer(){_classCallCheck(this,TrianglesBatchingColorRenderer);return _super18.apply(this,arguments);}_createClass(TrianglesBatchingColorRenderer,[{key:"_getHash",value:function _getHash(){var scene=this._scene;return[scene._lightsState.getHash(),scene._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";");}},{key:"drawLayer",value:function drawLayer(frameCtx,layer,renderPass){_get(_getPrototypeOf(TrianglesBatchingColorRenderer.prototype),"drawLayer",this).call(this,frameCtx,layer,renderPass,{incrementDrawState:true});}},{key:"_buildVertexShader",value:function _buildVertexShader(){var scene=this._scene;var sectionPlanesState=scene._sectionPlanesState;var lightsState=scene._lightsState;var clipping=sectionPlanesState.sectionPlanes.length>0;var light;var src=[];src.push("#version 300 es");src.push("// Triangles batching draw vertex shader");src.push("uniform int renderPass;");src.push("in vec3 position;");src.push("in vec3 normal;");src.push("in vec4 color;");src.push("in float flags;");if(scene.entityOffsetsEnabled){src.push("in vec3 offset;");}this._addMatricesUniformBlockLines(src,true);if(scene.logarithmicDepthBufferEnabled){src.push("uniform float logDepthBufFC;");src.push("out float vFragDepth;");src.push("bool isPerspectiveMatrix(mat4 m) {");src.push(" return (m[2][3] == - 1.0);");src.push("}");src.push("out float isPerspective;");}src.push("uniform vec4 lightAmbient;");for(var _i64=0,len=lightsState.lights.length;_i64= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");src.push(" }");src.push(" return normalize(v);");src.push("}");if(clipping){src.push("out vec4 vWorldPosition;");src.push("out float vFlags;");}src.push("out vec4 vColor;");src.push("void main(void) {");// colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT // renderPass = COLOR_OPAQUE diff --git a/dist/xeokit-sdk.min.cjs.js b/dist/xeokit-sdk.min.cjs.js index c4395bdda..b75ec5856 100644 --- a/dist/xeokit-sdk.min.cjs.js +++ b/dist/xeokit-sdk.min.cjs.js @@ -1,4 +1,4 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let r=!0,l=r?Float64Array:Float32Array;const o=new l(16),c=new l(16),u=new l(4),h={setDoublePrecisionEnabled(e){r=e,l=r?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>r,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new l(e||2),vec3:e=>new l(e||3),vec4:e=>new l(e||4),mat3:e=>new l(e||9),mat3ToMat4:(e,t=new l(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new l(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new l(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new l(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>h.dotVec4(e,e),lenVec4:e=>Math.sqrt(h.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>h.dotVec3(e,e),sqLenVec2:e=>h.dotVec2(e,e),lenVec3:e=>Math.sqrt(h.sqLenVec3(e)),distVec3:(()=>{const e=new l(3);return(t,s)=>h.lenVec3(h.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(h.sqLenVec2(e)),distVec2:(()=>{const e=new l(2);return(t,s)=>h.lenVec2(h.subVec2(t,s,e))})(),rcpVec3:(e,t)=>h.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/h.lenVec4(e);return h.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/h.lenVec3(e);return h.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/h.lenVec2(e);return h.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=h.dotVec3(e,t)/Math.sqrt(h.sqLenVec3(e)*h.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new l(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=h.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=h.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=h.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||h.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>h.m4s(0),setMat4ToOnes:()=>h.m4s(1),diagonalMat4v:e=>new l([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>h.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>h.diagonalMat4c(e,e,e,e),identityMat4:(e=new l(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new l(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>h.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new l(9));const n=e[0],i=e[3],a=e[6],r=e[1],o=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+o*I+c*v,s[4]=r*d+o*y+c*w,s[7]=r*f+o*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=h.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||h.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||h.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.translationMat4v(e,i))})(),translationMat4s:(e,t)=>h.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>h.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=h.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,p,A,d,f,I;return u=l*o,p=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||h.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*p+d,s[7]=0,s[8]=r*A+f,s[9]=r*p-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>h.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=h.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=h.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>h.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=h.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,p=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=p+v,s[2]=A-m,s[3]=0,s[4]=p-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=h.vec4()){const n=h.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],p=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(p,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(p,-1,1)),Math.abs(p)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(p,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(p,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=h.mat4())=>(h.quaternionToRotationMat4(t,n),h.scaleMat4v(s,n),h.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new l(3),t=new l(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=h.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=h.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=h.lenVec3(e);h.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,p=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=p,t[9]*=p,t[10]*=p,h.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=h.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],p=t[1],A=t[2];if(i===u&&a===p&&r===A)return h.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-p,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>h.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=h.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];h.addVec4(i,n,o),h.subVec4(i,n,c);const a=2*n[2],r=c[0],l=c[1],u=c[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=o[0]/r,s[9]=o[1]/l,s[10]=-o[2]/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/u,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],h.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=h.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new l(16),t=new l(16),s=new l(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||h.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||h.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=h.vec4()){const n=e[0]*h.DEGTORAD/2,i=e[1]*h.DEGTORAD/2,a=e[2]*h.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),p=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"YXZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"ZXY"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"ZYX"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"YZX"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o-c*u*p):"XZY"===t&&(s[0]=c*l*o-r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o+c*u*p),s},mat4ToQuaternion(e,t=h.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let p;const A=s+r+u;return A>0?(p=.5/Math.sqrt(A+1),t[3]=.25/p,t[0]=(c-l)*p,t[1]=(i-o)*p,t[2]=(a-n)*p):s>r&&s>u?(p=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/p,t[0]=.25*p,t[1]=(n+a)/p,t[2]=(i+o)/p):r>u?(p=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/p,t[0]=(n+a)/p,t[1]=.25*p,t[2]=(l+c)/p):(p=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/p,t[0]=(i+o)/p,t[1]=(l+c)/p,t[2]=.25*p),t},vec3PairToQuaternion(e,t,s=h.vec4()){const n=Math.sqrt(h.dotVec3(e,e)*h.dotVec3(t,t));let i=n+h.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):h.cross3Vec3(e,t,s),s[3]=i,h.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=h.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new l(16);return(t,s,n)=>(n=n||h.vec3(),h.quaternionToRotationMat4(t,e),h.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=h.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,p=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+p*-o-A*-l,s[1]=p*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-p*-r,s},quaternionToMat4(e,t){t=h.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,p=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+p,t[2]=f-u,t[4]=d-p,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=h.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>h.normalizeQuaternion(h.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=h.vec4()){const s=(e=h.normalizeQuaternion(e,u))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new l(e||6),AABB2:e=>new l(e||4),OBB3:e=>new l(e||32),OBB2:e=>new l(e||16),Sphere3:(e,t,s,n)=>new l([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new l(3),t=new l(3),s=new l(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],h.subVec3(t,e,s),Math.abs(h.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=h.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],p=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>p?u:p,Math.abs(h.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||h.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||h.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=h.AABB3())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MAX_DOUBLE,e[3]=h.MIN_DOUBLE,e[4]=h.MIN_DOUBLE,e[5]=h.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=h.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new l(3);return(t,s,n)=>{s=s||h.AABB3();let i,a,r,l=h.MAX_DOUBLE,o=h.MAX_DOUBLE,c=h.MAX_DOUBLE,u=h.MIN_DOUBLE,p=h.MIN_DOUBLE,A=h.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>p&&(p=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=p,s[5]=A,s}})(),OBB3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new l(3);return(t,s)=>{s=s||h.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=p);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ip&&(p=u);return n[3]=p,n}})(),getSphere3Center:(e,t=h.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=h.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MIN_DOUBLE,e[3]=h.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=h.AABB2()){let s,n,i,a,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=h.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,p=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+p*p+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=p/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3);return(a,r,l,o,c,u)=>{u=u||h.vec3();const p=h.subVec3(o,l,e),A=h.subVec3(c,l,t),d=h.cross3Vec3(r,A,s),f=h.dotVec3(p,d);if(f<1e-6)return null;const I=h.subVec3(a,l,n),y=h.dotVec3(I,d);if(y<0||y>f)return null;const m=h.cross3Vec3(I,p,i),v=h.dotVec3(r,m);if(v<0||y+v>f)return null;const w=h.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3);return(i,a,r,l,o,c)=>{c=c||h.vec3(),a=h.normalizeVec3(a,e);const u=h.subVec3(l,r,t),p=h.subVec3(o,r,s),A=h.cross3Vec3(u,p,n);h.normalizeVec3(A,A);const d=-h.dotVec3(r,A),f=-(h.dotVec3(i,A)+d)/h.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i,a,r,l)=>{const o=h.subVec3(r,i,e),c=h.subVec3(a,i,t),u=h.subVec3(n,i,s),p=h.dotVec3(o,o),A=h.dotVec3(o,c),d=h.dotVec3(o,u),f=h.dotVec3(c,c),I=h.dotVec3(c,u),y=p*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(p*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=h.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3);return(r,l,o)=>{let c,u;const p=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3),r=new l(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let p=0;p>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,p;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new l(4),t=new l(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,h.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],h.transformVec3(s,e,t),h.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new l(16),t=new l(16),s=new l(4),n=new l(4),i=new l(4),a=new l(4);return(r,l,o,c,u,p)=>{const A=h.mulMat4(o,l,e),d=h.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,h.transformVec4(d,s,n),h.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,h.transformVec4(d,i,a),h.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],h.subVec3(a,n,p),h.normalizeVec3(p)}})(),canvasPosToLocalRay:(()=>{const e=new l(3),t=new l(3);return(s,n,i,a,r,l,o)=>{h.canvasPosToWorldRay(s,n,i,r,e,t),h.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new l(16),t=new l(4),s=new l(4);return(n,i,a,r,l)=>{const o=h.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,h.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],h.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new l(6),o={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return o.triangles=s,o.leaf=!0,o;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),o.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};h.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class p{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const A={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var d=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{v.removeItem(e.id),delete P.scenes[e.id],delete m[e.id],A.components.scenes--}))},this.clear=function(){let e;for(const t in P.scenes)P.scenes.hasOwnProperty(t)&&(e=P.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete P.scenes[e.id]))},this.scheduleTask=function(e,t){w.push(e),w.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;w.length>0&&(e<0||n0&&E>0){var t=1e3/E;D+=t,T.push(t),T.length>=30&&(D-=T.shift()),A.frame.fps=Math.round(D/T.length)}!function(e){const t=P.runTasks(e+10),s=P.getNumTasks();A.frame.tasksRun=t,A.frame.tasksScheduled=s,A.frame.tasksBudget=10}(e),function(e){for(var t in g.time=e,P.scenes)if(P.scenes.hasOwnProperty(t)){var s=P.scenes[t];g.sceneId=t,g.startTime=s.startTime,g.deltaTime=null!=g.prevTime?g.time-g.prevTime:0,s.fire("tick",g,!0)}g.prevTime=e}(e),function(){const e=P.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=m[r],n||(n=m[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),b=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R);class C{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof C))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+y.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(y.isNumeric(s)||y.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+y.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+y.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+y.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():P.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(h.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){z.set(this._viewPos),z[3]=1,h.transformPoint4(this.scene.camera.projMatrix,z,K);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+K[0]/K[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-K[1]/K[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof W?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),O(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class X{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class q{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class J{constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var Z=h.vec3(),$=h.vec3();class ee extends C{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new Y(s,t.origin),this._cornerMarker=new Y(s,t.corner),this._targetMarker=new Y(s,t.target),this._originWorld=h.vec3(),this._cornerWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new X(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new X(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new J(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(h.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,p=t.length;u{switch(a=!0,r=e.entity,l.set(e.worldPos),o.set(e.canvasPos),this._state){case 0:this.markerDiv.style.marginLeft=e.canvasPos[0]-5+"px",this.markerDiv.style.marginTop=e.canvasPos[1]-5+"px",this.markerDiv.style.background="pink",this.markerDiv.style.border="2px solid red";break;case 1:this._currentAngleMeasurement&&(this._currentAngleMeasurement.originWireVisible=!0,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.cornerVisible=!0,this._currentAngleMeasurement.angleVisible=!1,this._currentAngleMeasurement.corner.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer";break;case 2:this._currentAngleMeasurement&&(this._currentAngleMeasurement.targetWireVisible=!0,this._currentAngleMeasurement.targetVisible=!0,this._currentAngleMeasurement.angleVisible=!0,this._currentAngleMeasurement.target.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer"}})),this._onInputMouseDown=i.on("mousedown",(e=>{c=e[0],u=e[1]})),this._onInputMouseUp=i.on("mouseup",(e=>{if(!(e[0]>c+5||e[0]u+5||e[1]{if(a=!1,this.markerDiv.style.marginLeft="-100px",this.markerDiv.style.marginTop="-100px",this._currentAngleMeasurement){switch(this._state){case 0:this._currentAngleMeasurement.originVisible=!1;break;case 1:this._currentAngleMeasurement.cornerVisible=!1,this._currentAngleMeasurement.originWireVisible=!1,this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1;break;case 2:this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1}n.style.cursor="default"}})),n.addEventListener("touchstart",this._onCanvasTouchStart=e=>{const t=e.touches,s=e.changedTouches;1===t.length&&1===s.length&&se(t[0],p)},{passive:!0}),n.addEventListener("touchend",this._onCanvasTouchEnd=e=>{const s=e.touches,n=e.changedTouches;if(0===s.length&&1===n.length){if(se(n[0],A),A[0]>p[0]+5||A[0]p[1]+5||A[1]{this.plugin.fire("markerClicked",this)}),this._marker.addEventListener("mouseenter",this._onMouseEnterExternalMarker=()=>{this.plugin.fire("markerMouseEnter",this)}),this._marker.addEventListener("mouseleave",this._onMouseLeaveExternalMarker=()=>{this.plugin.fire("markerMouseLeave",this)}),this._markerExternal=!0):(this._markerHTML=t.markerHTML,this._htmlDirty=!0,this._markerExternal=!1),t.labelElement?(this._label=t.labelElement,this._labelExternal=!0):(this._labelHTML=t.labelHTML,this._htmlDirty=!0,this._labelExternal=!1),this._markerShown=!!t.markerShown,this._labelShown=!!t.labelShown,this._values=t.values||{},this._layoutDirty=!0,this._visibilityDirty=!0,this._buildHTML(),this._onTick=this.scene.on("tick",(()=>{this._htmlDirty&&(this._buildHTML(),this._htmlDirty=!1,this._layoutDirty=!0,this._visibilityDirty=!0),(this._layoutDirty||this._visibilityDirty)&&(this._markerShown||this._labelShown)&&(this._updatePosition(),this._layoutDirty=!1),this._visibilityDirty&&(this._marker.style.visibility=this.visible&&this._markerShown?"visible":"hidden",this._label.style.visibility=this.visible&&this._markerShown&&this._labelShown?"visible":"hidden",this._visibilityDirty=!1)})),this.on("canvasPos",(()=>{this._layoutDirty=!0})),this.on("visible",(()=>{this._visibilityDirty=!0})),this.setMarkerShown(!1!==t.markerShown),this.setLabelShown(t.labelShown),this.eye=t.eye?t.eye.slice():null,this.look=t.look?t.look.slice():null,this.up=t.up?t.up.slice():null,this.projection=t.projection}_buildHTML(){if(!this._markerExternal){this._marker&&(this._container.removeChild(this._marker),this._marker=null);let e=this._markerHTML||"

";y.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._marker=t.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(()=>{this.plugin.fire("markerClicked",this)})),this._marker.addEventListener("mouseenter",(()=>{this.plugin.fire("markerMouseEnter",this)})),this._marker.addEventListener("mouseleave",(()=>{this.plugin.fire("markerMouseLeave",this)})),this._marker.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);let e=this._labelHTML||"

";y.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._label=t.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}}_updatePosition(){const e=this.scene.canvas.boundary,t=e[0],s=e[1],n=this.canvasPos;this._marker.style.left=Math.floor(t+n[0])-12+"px",this._marker.style.top=Math.floor(s+n[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+n[0]+20)+"px",this._label.style.top=Math.floor(s+n[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}_renderTemplate(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){const s=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),s)}return e}setMarkerShown(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}getMarkerShown(){return this._markerShown}setLabelShown(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}getLabelShown(){return this._labelShown}setField(e,t){this._values[e]=t||"",this._htmlDirty=!0}getField(e){return this._values[e]}setValues(e){for(var t in e)if(e.hasOwnProperty(t)){const s=e[t];this.setField(t,s)}}getValues(){return this._values}destroy(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),super.destroy()}}const ie=h.vec3(),ae=h.vec3(),re=h.vec3();class le extends C{get type(){return"Spinner"}constructor(e,t={}){super(e,t),this._canvas=t.canvas,this._element=null,this._isCustom=!1,t.elementId&&(this._element=document.getElementById(t.elementId),this._element?this._adjustPosition():this.error("Can't find given Spinner HTML element: '"+t.elementId+"' - will automatically create default element")),this._element||this._createDefaultSpinner(),this.processes=0}_createDefaultSpinner(){this._injectDefaultCSS();const e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const oe={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},ce=document.createElement("canvas");if(ce){const e=ce.getContext("webgl",{antialias:!0})||ce.getContext("experimental-webgl",{antialias:!0});oe.WEBGL=!!e,oe.WEBGL&&(oe.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?oe.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?oe.FS_MAX_FLOAT_PRECISION="mediump":oe.FS_MAX_FLOAT_PRECISION="lowp":oe.FS_MAX_FLOAT_PRECISION="mediump",oe.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),oe.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),oe.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),oe.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),oe.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),oe.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),oe.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),oe.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),oe.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),oe.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){oe.SUPPORTED_EXTENSIONS[e]=!0})))}const ue=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class he extends C{constructor(e,t={}){super(e,t),this._backgroundColor=h.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new le(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+h.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function ve(e){console.error(e.join("\n"))}class we{constructor(e,t){this.id=ye.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new de(e,e.VERTEX_SHADER,me(this.source.vertex)),this._fragmentShader=new de(e,e.FRAGMENT_SHADER,me(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void ve(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void ve(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void ve(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void ve(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void ve(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;sthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}class Te{constructor(e,t){this.scene=e,this.aabb=h.AABB3(),this.origin=h.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}_buildMarkerList(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}_buildPositions(){let e=0;for(let t=0;t-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Te(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Te(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new we(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,p=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Pe[0]=a,Pe[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,p),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Pe),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new we(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new ge(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new ge(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new ge(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const Ce=new Float32Array(xe(17,[0,1])),_e=new Float32Array(xe(17,[1,0])),Be=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Ne(n,t));return s}(17,4)),Oe=new Float32Array(2);class Se{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new we(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new ge(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new ge(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new ge(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Oe[0]=r,Oe[1]=l,n.uniform2fv(this._uViewport,Oe),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,_e):n.uniform2fv(this._uSampleOffsets,Ce),n.uniform1fv(this._uSampleWeights,Be);const p=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,p,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Ne(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function xe(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Le{constructor(e,t,s){s=s||{},this.gl=t,this.allocated=!1,this.canvas=e,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}setSize(e){this.size=e}webglContextRestored(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}bind(e=null){if(this._touch(e),this.bound)return;const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}_touch(e=null){let t,s;const n=this.gl;if(this.size?(t=this.size[0],s=this.size[1]):(t=n.drawingBufferWidth,s=n.drawingBufferHeight),this.buffer){if(this.buffer.width===t&&this.buffer.height===s)return;n.deleteTexture(this.buffer.texture),n.deleteFramebuffer(this.buffer.framebuf),n.deleteRenderbuffer(this.buffer.renderbuf)}const i=n.createTexture();let a;n.bindTexture(n.TEXTURE_2D,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),e?n.texStorage2D(n.TEXTURE_2D,1,e,t,s):n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,s,0,n.RGBA,n.UNSIGNED_BYTE,null),this._hasDepthTexture&&(a=n.createTexture(),n.bindTexture(n.TEXTURE_2D,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.DEPTH_COMPONENT32F,t,s,0,n.DEPTH_COMPONENT,n.FLOAT,null));const r=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT32F,t,s);const l=n.createFramebuffer();if(n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,i,0),this._hasDepthTexture?n.framebufferTexture2D(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.TEXTURE_2D,a,0):n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,r),n.bindTexture(n.TEXTURE_2D,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,l),!n.isFramebuffer(l))throw"Invalid framebuffer";n.bindFramebuffer(n.FRAMEBUFFER,null);const o=n.checkFramebufferStatus(n.FRAMEBUFFER);switch(o){case n.FRAMEBUFFER_COMPLETE:break;case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case n.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+o}this.buffer={framebuf:l,renderbuf:r,texture:i,depthTexture:a,width:t,height:s},this.bound=!1}clear(){if(!this.bound)throw"Render buffer not bound";const e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}read(e,t,s=null,n=null,i=Uint8Array,a=4){const r=e,l=(this.buffer.height||this.gl.drawingBufferHeight)-t,o=new i(a),c=this.gl;return c.readPixels(r,l,1,1,s||c.RGBA,n||c.UNSIGNED_BYTE,o,0),o}readArray(e=null,t=null,s=Uint8Array,n=4){const i=new s(this.buffer.width*this.buffer.height*n),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}readImageAsCanvas(){const e=this.gl,t=this._getImageDataCache(),s=t.pixelData,n=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,s);const r=this.buffer.width,l=this.buffer.height,o=l/2|0,c=4*r,u=new Uint8Array(4*r);for(let e=0;eT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class Ue{constructor(e,t,s,n,i=null,a=0){this.model=e,this.object=null,this.parent=null,this.id=t,this.aabb=null,this.layer=i,this.portionId=a,this._color=[s[0],s[1],s[2],n],this._colorize=[s[0],s[1],s[2],n],this._colorizing=!1,this._transparent=n<255,this.numTriangles=0,this.origin=null}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const s=e<255,n=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),n&&this.layer.setTransparent(this.portionId,t,s)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,s,n){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,s,n)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex(this.portionId,e)}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const Ge=new class{constructor(){this._uint8Arrays={},this._float32Arrays={}}_clear(){this._uint8Arrays={},this._float32Arrays={}}getUInt8Array(e){let t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}getFloat32Array(e){let t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}};let Ve=0;const je={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},ke=new e({});class Qe{constructor(e){this.id=ke.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){ke.removeItem(this.id)}}const We=function(){const e=h.mat4(),t=h.mat4();return function(s,n){n=n||h.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return h.identityMat4(e),h.translationMat4v(s,e),h.identityMat4(t),h.scalingMat4v([l/u,o/u,c/u],t),h.mulMat4(e,t,n),n}}();var ze=function(){const e=h.mat4(),t=h.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function Xe(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function qe(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const Je={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=Ye(e,l,"floor","ceil"),n=Xe(s),a=qe(e,l,n),a>r&&(i=s,r=a),s=Ye(e,l,"ceil","ceil"),n=Xe(s),a=qe(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},Ze=new Float32Array([1,1,1,1]),$e=new Float32Array([0,0,0,1]),et=h.vec4(),tt=h.vec3();class st{constructor(e,t=!1,{instancing:s=!1,edges:n=!1}={}){this._scene=e,this._withSAO=t,this._instancing=s,this._edges=n,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}_getHash(){return this._scene._sectionPlanesState.getHash()}_buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}_buildVertexShader(){return[""]}_buildFragmentShader(){return[""]}_addMatricesUniformBlockLines(e,t=!1){return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}getValid(){return this._hash===this._getHash()}setSectionPlanesStateUniforms(e){const t=this._scene,{gl:s}=t.canvas,{model:n,layerIndex:i}=e,a=t._sectionPlanesState.sectionPlanes.length;if(a>0){const r=t._sectionPlanesState.sectionPlanes,l=i*a,o=n.renderFlags;for(let t=0;t0&&(this._uReflectionMap="reflectionMap"),s.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(let t=0,s=e._sectionPlanesState.sectionPlanes.length;t0&&d.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,d.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),d.lightMaps.length>0&&d.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,d.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),this._withSAO){const t=r.sao;if(t.possible){const s=l.drawingBufferWidth,n=l.drawingBufferHeight;et[0]=s,et[1]=n,et[2]=t.blendCutoff,et[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,et),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++}}if(n){const e=this._edges?"edgeColor":"fillColor",t=this._edges?"edgeAlpha":"fillAlpha";if(s===je[(this._edges?"EDGES":"SILHOUETTE")+"_XRAYED"]){const s=r.xrayMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===je[(this._edges?"EDGES":"SILHOUETTE")+"_HIGHLIGHTED"]){const s=r.highlightMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===je[(this._edges?"EDGES":"SILHOUETTE")+"_SELECTED"]){const s=r.selectedMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else l.uniform4fv(this._uColor,this._edges?$e:Ze)}this._draw({geometry:h,state:o,frameCtx:e,incrementDrawState:i}),l.bindVertexArray(null)}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null,A.memory.programs--}}class nt extends st{constructor(e,t,{instancing:s=!1,edges:n=!1}={}){super(e,t,{instancing:s,edges:n})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;if(this._edges)t.drawElements(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0);else{const e=n.pickElementsCount||s.indicesBuf.numItems,a=n.pickElementsOffset?n.pickElementsOffset*s.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,e,s.indicesBuf.itemType,a),i&&n.drawElements++}}}class it extends nt{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class at extends st{constructor(e,t,{edges:s=!1}={}){super(e,t,{instancing:!0,edges:s})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,geometry:i,incrementDrawState:a}=e;this._edges?t.drawElementsInstanced(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances):(t.drawElementsInstanced(t.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),a&&n.drawElements++)}}class rt extends at{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class lt extends st{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArrays(t.POINTS,0,s.positionsBuf.numItems),i&&n.drawArrays++}}class ot extends st{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,geometry:i,incrementDrawState:a}=e;t.drawArraysInstanced(t.POINTS,0,s.positionsBuf.numItems,s.numInstances),a&&n.drawArrays++}}class ct extends st{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElements(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0),i&&n.drawElements++}}class ut extends st{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,geometry:n,frameCtx:i,incrementDrawState:a}=e;t.drawElementsInstanced(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),a&&i.drawElements++}}class ht extends nt{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i;const a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class pt extends nt{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching flat-shading draw vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._lightsState,s=e._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),n){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,s=t.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}class dt extends it{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class ft extends it{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class It extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class yt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class mt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec3 worldNormal = octDecode(normal.xy); "),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class vt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class wt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching depth fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}class gt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Tt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry shadow vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push(" int colorFlag = int(flags) & 0xF;"),s.push(" bool visible = (colorFlag > 0);"),s.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push(" if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry shadow fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = encodeFloat( gl_FragCoord.z); "),s.push("}"),s}}class Et extends nt{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Triangles batching quality draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),r.push("uniform sampler2D uAOMap;"),r.push("in vec4 vViewPosition;"),r.push("in vec3 vViewNormal;"),r.push("in vec4 vColor;"),r.push("in vec2 vUV;"),r.push("in vec2 vMetallicRoughness;"),n.lightMaps.length>0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick flat normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out float vFlags;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags = flags;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick flat normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class Dt extends nt{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching color texture vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._lightsState,n=e._sectionPlanesState,i=n.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(let e=0,t=n.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(let e=0,t=n.sectionPlanes.length;e 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,t=s.lights.length;e5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]}}const _t=h.mat4(),Bt=h.mat4();function Ot(e,t,s){const n=e.length,i=new Uint16Array(n),a=t[0],r=t[1],l=t[2],o=t[3]-a,c=t[4]-r,u=t[5]-l,p=65525,A=p/o,d=p/c,f=p/u,I=e=>e>=0?e:0;for(let t=0;t=0?1:-1),t=(1-Math.abs(n))*(i>=0?1:-1),n=e,i=t}return new Int8Array([Math[t](127.5*n+(n<0?-1:0)),Math[s](127.5*i+(i<0?-1:0))])}function xt(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}const Lt=h.vec3();class Mt{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;let c=a.eye;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];const u=t.aabb,p=[h.safeInv(u[3]-u[0])*h.MAX_INT,h.safeInv(u[4]-u[1])*h.MAX_INT,h.safeInv(u[5]-u[2])*h.MAX_INT];if(e._coordinateScale[0]=h.safeInv(p[0]),e._coordinateScale[1]=h.safeInv(p[1]),e._coordinateScale[2]=h.safeInv(p[2]),!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),e.pickViewMatrix&&(c=e.pickOrigin||c);const A=[c[0]-o[0],c[1]-o[1],c[2]-o[2]];r.uniform3fv(this._uCameraEyeRtc,A),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.layerNumber),r.uniform3fv(this._uCoordinateScaler,p),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform1i(this._uSolid,t.solid);const d=e.pickViewMatrix||a.viewMatrix,f=o?B(d,o):d;if(r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,a=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),s.push("uniform bool solid;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Ft=h.vec3();class Ht{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];const c=t.aabb,u=[h.safeInv(c[3]-c[0])*h.MAX_INT,h.safeInv(c[4]-c[1])*h.MAX_INT,h.safeInv(c[5]-c[2])*h.MAX_INT];if(e._coordinateScale[0]=h.safeInv(u[0]),e._coordinateScale[1]=h.safeInv(u[1]),e._coordinateScale[2]=h.safeInv(u[2]),!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());let p=a.eye;e.pickViewMatrix&&(p=e.pickOrigin||p);const A=[p[0]-o[0],p[1]-o[1],p[2]-o[2]];r.uniform3fv(this._uCameraEyeRtc,A),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.layerNumber),r.uniform3fv(this._uCoordinateScaler,u),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);const d=e.pickViewMatrix||a.viewMatrix,f=o?B(d,o):d;if(r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,a=n.renderFlags;for(let t=0;t0;e.pointsMaterial._state;const s=[];return s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class Ut{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Mt(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Ht(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Gt={};const Vt=h.mat4(),jt=h.mat4(),kt=h.vec4([0,0,0,1]),Qt=h.vec4([0,0,0,1]),Wt=h.vec4([0,0,0,1]),zt=h.OBB3(),Kt=h.vec3(),Yt=h.vec3(),Xt=h.vec3(),qt=h.vec3(),Jt=h.vec3(),Zt=h.vec3(),$t=h.vec3();class es{constructor(e){console.log("Creating TrianglesBatchingLayer"),this.model=e.model,this.sortId="TrianglesBatchingLayer"+(e.solid?"-solid":"-surface")+(e.autoNormals?"-autonormals":"-normals")+(e.textureSet&&e.textureSet.colorTexture?"-colorTexture":"")+(e.textureSet&&e.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=Rt[t];return s||(s=new Pt(e),Rt[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Rt[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=Gt[t];return s||(s=new Ut(e),Gt[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Gt[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Ct(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Qe({origin:h.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:e.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=h.mat4(e.positionsDecodeMatrix)),e.uvDecodeMatrix?(this._state.uvDecodeMatrix=h.mat3(e.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,e.origin&&this._state.origin.set(e.origin),this.aabb=h.collapseAABB3(),this.solid=!!e.solid}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(let e=0,t=i.length;e0){const e=Vt;I?h.inverseMat4(h.transposeMat4(I,jt),e):h.identityMat4(e,e),function(e,t,s,n,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let r,l,o,c,u,p,A=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(p=0;pu&&(o=r,u=c),r=Nt(d,"floor","ceil"),l=xt(r),c=a(d,l),c>u&&(o=r,u=c),r=Nt(d,"ceil","ceil"),l=xt(r),c=a(d,l),c>u&&(o=r,u=c),n[i+p+0]=o[0],n[i+p+1]=o[1],n[i+p+2]=0}(e,n,n.length,g.normals,g.normals.length)}if(l)for(let e=0,t=l.length;e0)for(let e=0,t=a.length;e0)for(let e=0,t=r.length;e0){const n=this._state.positionsDecodeMatrix?new Uint16Array(s.positions):Ot(s.positions,this._modelAABB,this._state.positionsDecodeMatrix=h.mat4());if(e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(let e=0,t=this._portions.length;e0){const n=new Int8Array(s.normals);let i=!0;e.normalsBuf=new ge(t,t.ARRAY_BUFFER,n,s.normals.length,3,t.STATIC_DRAW,i)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.uv.length>0)if(e.uvDecodeMatrix){let n=!1;e.uvBuf=new ge(t,t.ARRAY_BUFFER,s.uv,s.uv.length,2,t.STATIC_DRAW,n)}else{const n=Je.getUVBounds(s.uv),i=Je.compressUVs(s.uv,n.min,n.max),a=i.quantized;let r=!1;e.uvDecodeMatrix=h.mat3(i.decodeMatrix),e.uvBuf=new ge(t,t.ARRAY_BUFFER,a,a.length,2,t.STATIC_DRAW,r)}if(s.metallicRoughness.length>0){const n=new Uint8Array(s.metallicRoughness);let i=!1;e.metallicRoughnessBuf=new ge(t,t.ARRAY_BUFFER,n,s.metallicRoughness.length,2,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n),a=!1;e.flagsBuf=new ge(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new ge(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}if(s.edgeIndices.length>0){const n=new Uint32Array(s.edgeIndices);e.edgeIndicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,n,s.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}isEmpty(){return!this._state.indicesBuf}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=e,n=this._portions[s],i=4*n.vertsBaseIndex,a=4*n.numVerts,r=this._scratchMemory.getUInt8Array(a),l=t[0],o=t[1],c=t[2],u=t[3];for(let e=0;em)&&(m=e,n.set(v),i&&h.triangleNormal(d,f,I,i),y=!0)}}return y&&i&&(h.transformVec3(this.model.worldNormalMatrix,i,i),h.normalizeVec3(i)),y}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}class ts extends at{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i,a,r;const l=[];for(l.push("#version 300 es"),l.push("// Instancing geometry drawing vertex shader"),l.push("uniform int renderPass;"),l.push("in vec3 position;"),l.push("in vec2 normal;"),l.push("in vec4 color;"),l.push("in float flags;"),e.entityOffsetsEnabled&&l.push("in vec3 offset;"),l.push("in vec4 modelMatrixCol0;"),l.push("in vec4 modelMatrixCol1;"),l.push("in vec4 modelMatrixCol2;"),l.push("in vec4 modelNormalMatrixCol0;"),l.push("in vec4 modelNormalMatrixCol1;"),l.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(l,!0),e.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;")),l.push("uniform vec4 lightAmbient;"),i=0,a=s.lights.length;i= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"),n&&(l.push("out vec4 vWorldPosition;"),l.push("out float vFlags;")),l.push("out vec4 vColor;"),l.push("void main(void) {"),l.push("int colorFlag = int(flags) & 0xF;"),l.push("if (colorFlag != renderPass) {"),l.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),l.push("} else {"),l.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),l.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&l.push(" worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix * worldPosition; "),l.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),l.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),l.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),i=0,a=s.lights.length;i0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class ss extends at{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState;let n,i;const a=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry flat-shading drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),a){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}for(r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),n=0,i=s.lights.length;n0,s=[];return s.push("#version 300 es"),s.push("// Instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing fill fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class is extends rt{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class as extends rt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class rs extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class ls extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class os extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec2 normal;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("in vec4 modelNormalMatrixCol0;"),s.push("in vec4 modelNormalMatrixCol1;"),s.push("in vec4 modelNormalMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class cs extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("in float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class us extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}class hs extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class ps extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}const As={3e3:"linearToLinear",3001:"sRGBToLinear"};class ds extends at{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Instancing geometry quality drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),r.push("#define PI 3.14159265359"),r.push("#define RECIPROCAL_PI 0.31830988618"),r.push("#define RECIPROCAL_PI2 0.15915494"),r.push("#define EPSILON 1e-6"),r.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),r.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),r.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),r.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),r.push(" return normalize(surf_norm );"),r.push(" }"),r.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),r.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),r.push(" vec2 st0 = dFdx( uv.st );"),r.push(" vec2 st1 = dFdy( uv.st );"),r.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),r.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),r.push(" vec3 N = normalize( surf_norm );"),r.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),r.push(" mat3 tsn = mat3( S, T, N );"),r.push(" return normalize( tsn * mapN );"),r.push("}"),r.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),r.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),r.push("}"),r.push("struct IncidentLight {"),r.push(" vec3 color;"),r.push(" vec3 direction;"),r.push("};"),r.push("struct ReflectedLight {"),r.push(" vec3 diffuse;"),r.push(" vec3 specular;"),r.push("};"),r.push("struct Geometry {"),r.push(" vec3 position;"),r.push(" vec3 viewNormal;"),r.push(" vec3 worldNormal;"),r.push(" vec3 viewEyeDir;"),r.push("};"),r.push("struct Material {"),r.push(" vec3 diffuseColor;"),r.push(" float specularRoughness;"),r.push(" vec3 specularColor;"),r.push(" float shine;"),r.push("};"),r.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),r.push(" float r = ggxRoughness + 0.0001;"),r.push(" return (2.0 / (r * r) - 2.0);"),r.push("}"),r.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),r.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),r.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),r.push("}"),n.reflectionMaps.length>0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = "+As[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = "+As[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&s.push("out float vFlags;"),s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&s.push("vFlags = flags;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class Is extends at{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState;let i,a;const r=s.sectionPlanes.length>0,l=[];if(l.push("#version 300 es"),l.push("// Instancing geometry drawing fragment shader"),l.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),l.push("precision highp float;"),l.push("precision highp int;"),l.push("#else"),l.push("precision mediump float;"),l.push("precision mediump int;"),l.push("#endif"),e.logarithmicDepthBufferEnabled&&(l.push("in float isPerspective;"),l.push("uniform float logDepthBufFC;"),l.push("in float vFragDepth;")),l.push("uniform sampler2D uColorMap;"),this._withSAO&&(l.push("uniform sampler2D uOcclusionTexture;"),l.push("uniform vec4 uSAOParams;"),l.push("const float packUpscale = 256. / 255.;"),l.push("const float unpackDownScale = 255. / 256.;"),l.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),l.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),l.push("float unpackRGBToFloat( const in vec4 v ) {"),l.push(" return dot( v, unPackFactors );"),l.push("}")),l.push("uniform float gammaFactor;"),l.push("vec4 linearToLinear( in vec4 value ) {"),l.push(" return value;"),l.push("}"),l.push("vec4 sRGBToLinear( in vec4 value ) {"),l.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),l.push("}"),l.push("vec4 gammaToLinear( in vec4 value) {"),l.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),l.push("}"),t&&(l.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),l.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),l.push("}")),r){l.push("in vec4 vWorldPosition;"),l.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),l.push(" if (clippable) {"),l.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),l.push(" discard;"),l.push(" }"),l.push("}")}for(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),l.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),l.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),l.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),i=0,a=n.lights.length;i0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// Points instancing snap vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const gs=h.vec3();class Ts{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.canvas.gl,r=t._state,l=t._state.origin,o=r.geometry;e._origin[0]=l[0],e._origin[1]=l[1],e._origin[2]=l[2];const c=t.aabb,u=[h.safeInv(c[3]-c[0])*h.MAX_INT,h.safeInv(c[4]-c[1])*h.MAX_INT,h.safeInv(c[5]-c[2])*h.MAX_INT];if(e._coordinateScale[0]=h.safeInv(u[0]),e._coordinateScale[1]=h.safeInv(u[1]),e._coordinateScale[2]=h.safeInv(u[2]),!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const p=i.camera;let A=p.eye;e.pickViewMatrix&&(A=e.pickOrigin||A);const d=[A[0]-l[0],A[1]-l[1],A[2]-l[2]];a.uniform3fv(this._uCameraEyeRtc,d),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.layerNumber),a.uniform3fv(this._uCoordinateScaler,u),a.uniform1i(this._uRenderPass,s),a.uniform1i(this._uPickInvisible,e.pickInvisible);const f=e.pickViewMatrix||p.viewMatrix,I=l?B(f,l):f;if(a.uniformMatrix4fv(this._uViewMatrix,!1,I),a.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,p.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,t)}const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// Points instancing snap vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class Es{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new ws(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Ts(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const bs={};const Ds=new Uint8Array(4),Ps=new Float32Array(1),Rs=h.vec4([0,0,0,1]),Cs=h.vec4([0,0,0,1]),_s=h.vec4([0,0,0,1]),Bs=new Float32Array(3),Os=h.vec3(),Ss=h.vec3(),Ns=h.vec3(),xs=h.vec3(),Ls=h.vec3(),Ms=h.vec3(),Fs=h.vec3();class Hs{constructor(e){console.log("Creating TrianglesInstancingLayer"),this.model=e.model,this.sortId="TrianglesInstancingLayer"+(e.solid?"-solid":"-surface")+(e.normals?"-normals":"-autoNormals"),this.layerIndex=e.layerIndex,this._instancingRenderers=function(e){const t=e.id;let s=ms[t];return s||(s=new ys(e),ms[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete ms[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=bs[t];return s||(s=new Es(e),bs[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete bs[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Qe({numInstances:0,obb:h.OBB3(),origin:h.vec3(),geometry:e.geometry,textureSet:e.textureSet,pbrSupported:!1,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],e.origin&&this._state.origin.set(e.origin),this._finalized=!1,this.aabb=h.collapseAABB3(),this.solid=!!e.solid,this.numIndices=e.geometry.numIndices}createPortion(e){const t=e.color,s=e.metallic,n=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,r=e.sceneModelMatrix,l=e.aabb,o=e.pickColor;if(this._finalized)throw"Already finalized";const c=t[0],u=t[1],p=t[2];if(this._colors.push(c),this._colors.push(u),this._colors.push(p),this._colors.push(i),this._metallicRoughness.push(null!=s?s:0),this._metallicRoughness.push(null!=n?n:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){let e=h.transposeMat4(a,h.mat4()),t=h.inverseMat4(e);this._modelNormalMatrixCol0.push(t[0]),this._modelNormalMatrixCol0.push(t[4]),this._modelNormalMatrixCol0.push(t[8]),this._modelNormalMatrixCol0.push(t[12]),this._modelNormalMatrixCol1.push(t[1]),this._modelNormalMatrixCol1.push(t[5]),this._modelNormalMatrixCol1.push(t[9]),this._modelNormalMatrixCol1.push(t[13]),this._modelNormalMatrixCol2.push(t[2]),this._modelNormalMatrixCol2.push(t[6]),this._modelNormalMatrixCol2.push(t[10]),this._modelNormalMatrixCol2.push(t[14])}this._pickColors.push(o[0]),this._pickColors.push(o[1]),this._pickColors.push(o[2]),this._pickColors.push(o[3]);const A=this._state.geometry.positionsCompressed.length,d=this._state.geometry.positionsCompressed,f=this._state.geometry.positionsDecodeMatrix;for(let e=0;e0){let t=!1;e.colorsBuf=new ge(n,n.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,n.DYNAMIC_DRAW,t),this._colors=[]}if(this._metallicRoughness.length>0){const t=new Uint8Array(this._metallicRoughness);let s=!1;e.metallicRoughnessBuf=new ge(n,n.ARRAY_BUFFER,t,this._metallicRoughness.length,2,n.STATIC_DRAW,s)}if(a>0){let t=!1;e.flagsBuf=new ge(n,n.ARRAY_BUFFER,new Float32Array(a),a,1,n.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;e.offsetsBuf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,n.DYNAMIC_DRAW,t),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){const s=!1;e.positionsBuf=new ge(n,n.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,n.STATIC_DRAW,s),e.positionsDecodeMatrix=h.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){const s=new Uint8Array(t.colorsCompressed),i=!1;e.colorsBuf=new ge(n,n.ARRAY_BUFFER,s,s.length,4,n.STATIC_DRAW,i)}if(t.uvCompressed&&t.uvCompressed.length>0){const s=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new ge(n,n.ARRAY_BUFFER,s,s.length,2,n.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new ge(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,n.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new ge(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,n.STATIC_DRAW)),this._modelMatrixCol0.length>0){const t=!1;e.modelMatrixCol0Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelMatrixCol1Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelMatrixCol2Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol1Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol2Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){const t=!1;e.pickColorsBuf=new ge(n,n.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,n.STATIC_DRAW,t),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&s&&s.colorTexture&&s.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!s&&!!s.colorTexture,this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Ds[0]=t[0],Ds[1]=t[1],Ds[2]=t[2],Ds[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Ds,4*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&V),l=!!(t&j),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?je.NOT_RENDERED:s?je.COLOR_TRANSPARENT:je.COLOR_OPAQUE,h=!n||c?je.NOT_RENDERED:r?je.SILHOUETTE_SELECTED:a?je.SILHOUETTE_HIGHLIGHTED:i?je.SILHOUETTE_XRAYED:je.NOT_RENDERED;let p=0;p=!n||c?je.NOT_RENDERED:r?je.EDGES_SELECTED:a?je.EDGES_HIGHLIGHTED:i?je.EDGES_XRAYED:l?s?je.EDGES_COLOR_TRANSPARENT:je.EDGES_COLOR_OPAQUE:je.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?je.PICK:je.NOT_RENDERED)<<12,A|=(t&F?1:0)<<16,Ps[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Ps,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Bs[0]=t[0],Bs[1]=t[1],Bs[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Bs,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}getEachVertex(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;const s=this._state,n=s.geometry,i=this._portions[e];if(!i)return void this.model.error("portion not found: "+e);const a=n.quantizedPositions,r=s.origin,l=i.offset,o=r[0]+l[0],c=r[1]+l[1],u=r[2]+l[2],p=Rs,A=i.matrix,d=this.model.sceneModelMatrix,f=s.positionsDecodeMatrix;for(let e=0,s=a.length;ev)&&(v=e,n.set(w),i&&h.triangleNormal(f,I,y,i),m=!0)}}return m&&i&&(h.transformVec3(l.normalMatrix,i,i),h.transformVec3(this.model.worldNormalMatrix,i,i),h.normalizeVec3(i)),m}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}class Us extends ct{drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Gs extends ct{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class Vs{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Us(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Gs(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const js={};class ks{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const Qs=h.vec4([0,0,0,1]),Ws=h.vec4([0,0,0,1]),zs=h.vec4([0,0,0,1]),Ks=h.OBB3();class Ys{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=js[t];return s||(s=new Vs(e),js[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete js[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new ks(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Qe({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:h.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=h.vec3(e.origin)),this.aabb=h.collapseAABB3()}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Ot(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.colors.length>0){const n=s.colors.length/4,i=new Float32Array(n);let a=!1;e.flagsBuf=new ge(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new ge(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2],c=t[3];for(let e=0;e0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 lightAmbient;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class qs extends ut{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 color;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class Js{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Xs(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new qs(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Zs={};const $s=new Uint8Array(4),en=new Float32Array(1),tn=h.vec4([0,0,0,1]),sn=h.vec4([0,0,0,1]),nn=h.vec4([0,0,0,1]),an=new Float32Array(3);class rn{constructor(e){this.model=e.model,this.material=e.material,this.sortId="LinesInstancingLayer",this.layerIndex=e.layerIndex,this._linesInstancingRenderers=function(e){const t=e.id;let s=Zs[t];return s||(s=new Js(e),Zs[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Zs[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Qe({obb:h.OBB3(),numInstances:0,origin:null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],e.origin&&(this._state.origin=h.vec3(e.origin)),this._finalized=!1,this.aabb=h.collapseAABB3()}createPortion(e){const t=e.color,s=e.opacity,n=e.meshMatrix,i=e.worldMatrix,a=e.aabb;if(this._finalized)throw"Already finalized";const r=t[0],l=t[1],o=t[2];t[3],this._colors.push(r),this._colors.push(l),this._colors.push(o),this._colors.push(s),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(n[0]),this._modelMatrixCol0.push(n[4]),this._modelMatrixCol0.push(n[8]),this._modelMatrixCol0.push(n[12]),this._modelMatrixCol1.push(n[1]),this._modelMatrixCol1.push(n[5]),this._modelMatrixCol1.push(n[9]),this._modelMatrixCol1.push(n[13]),this._modelMatrixCol2.push(n[2]),this._modelMatrixCol2.push(n[6]),this._modelMatrixCol2.push(n[10]),this._modelMatrixCol2.push(n[14]),h.collapseAABB3(a);const c=this._state.obb,u=c.length;for(let e=0;e0){let t=!1;this._state.colorsBuf=new ge(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,t),this._colors=[]}if(s>0){let t=!1;this._state.flagsBuf=new ge(e,e.ARRAY_BUFFER,new Float32Array(s),s,1,e.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";$s[0]=t[0],$s[1]=t[1],$s[2]=t[2],$s[3]=t[3],this._state.colorsBuf.setData($s,4*e,4)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&V),l=!!(t&j),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?je.NOT_RENDERED:s?je.COLOR_TRANSPARENT:je.COLOR_OPAQUE,h=!n||c?je.NOT_RENDERED:r?je.SILHOUETTE_SELECTED:a?je.SILHOUETTE_HIGHLIGHTED:i?je.SILHOUETTE_XRAYED:je.NOT_RENDERED;let p=0;p=!n||c?je.NOT_RENDERED:r?je.EDGES_SELECTED:a?je.EDGES_HIGHLIGHTED:i?je.EDGES_XRAYED:l?s?je.EDGES_COLOR_TRANSPARENT:je.EDGES_COLOR_OPAQUE:je.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?je.PICK:je.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,en[0]=A,this._state.flagsBuf.setData(en,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(an[0]=t[0],an[1]=t[1],an[2]=t[2],this._state.offsetsBuf.setData(an,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,je.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,je.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesXRayed(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawOcclusion(e,t){}drawShadow(e,t){}drawPickMesh(e,t){}drawPickDepths(e,t){}drawPickNormals(e,t){}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}class ln extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial,n=[];return n.push("#version 300 es"),n.push("// Points batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class on extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}class cn extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class un extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batched pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batched pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class hn extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push(" gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class pn{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new ln(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new on(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new cn(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new un(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new hn(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const An={};class dn{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]}}const fn=h.vec4(),In=h.vec4(),yn=h.vec4([0,0,0,1]),mn=h.vec4([0,0,0,1]),vn=h.vec4([0,0,0,1]),wn=h.OBB3();class gn{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=An[t];return s||(s=new pn(e),An[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete An[t],s._destroy()}))),s}(e.model.scene),this._buffer=new dn(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Qe({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:h.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=h.vec3(e.origin)),this.aabb=h.collapseAABB3()}canCreatePortion(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}createPortion(e){if(this._finalized)throw"Already finalized";const t=e.positions,s=e.positionsCompressed,n=e.color,i=e.colorsCompressed,a=e.colors,r=e.meshMatrix,l=e.worldMatrix,o=e.worldAABB,c=e.pickColor,u=this._buffer,p=u.positions.length/3;let A;if(this._preCompressedPositionsExpected){if(!s)throw"positionsCompressed expected";for(let e=0,t=s.length;e0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Ot(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n);let a=!1;e.flagsBuf=new ge(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new ge(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized"}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2];for(let e=0;e0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class En extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 silhouetteColor;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class bn extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick mesh fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class Dn extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Pn extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Rn extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class Cn extends ot{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("gl_PointSize = pointSize;"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }"),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class _n{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Tn(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new En(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Rn(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new bn(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Dn(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Pn(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new Cn(this._scene)),this._shadowRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}const Bn={};const On=new Uint8Array(4),Sn=new Float32Array(1),Nn=h.vec4([0,0,0,1]),xn=h.vec4([0,0,0,1]),Ln=h.vec4([0,0,0,1]),Mn=new Float32Array(3);class Fn{constructor(e){this.model=e.model,this.material=e.material,this.sortId="PointsInstancingLayer",this.layerIndex=e.layerIndex,this._pointsInstancingRenderers=function(e){const t=e.id;let s=Bn[t];return s||(s=new _n(e),Bn[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Bn[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Qe({obb:h.OBB3(),numInstances:0,origin:e.origin?h.vec3(e.origin):null,geometry:e.geometry,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=h.collapseAABB3()}createPortion(e){const t=e.meshMatrix,s=e.worldMatrix,n=e.aabb,i=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(i[0]),this._pickColors.push(i[1]),this._pickColors.push(i[2]),this._pickColors.push(i[3]),h.collapseAABB3(n);const a=this._state.obb,r=a.length;for(let e=0;e0){let s=!1;this._state.flagsBuf=new ge(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,s)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){const t=!1;this._state.pickColorsBuf=new ge(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,t),this._pickColors=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";On[0]=t[0],On[1]=t[1],On[2]=t[2],this._state.colorsBuf.setData(On,3*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&V),l=!!(t&j),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?je.NOT_RENDERED:s?je.COLOR_TRANSPARENT:je.COLOR_OPAQUE,h=!n||c?je.NOT_RENDERED:r?je.SILHOUETTE_SELECTED:a?je.SILHOUETTE_HIGHLIGHTED:i?je.SILHOUETTE_XRAYED:je.NOT_RENDERED;let p=0;p=!n||c?je.NOT_RENDERED:r?je.EDGES_SELECTED:a?je.EDGES_HIGHLIGHTED:i?je.EDGES_XRAYED:l?s?je.EDGES_COLOR_TRANSPARENT:je.EDGES_COLOR_OPAQUE:je.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?je.PICK:je.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,Sn[0]=A,this._state.flagsBuf.setData(Sn,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Mn[0]=t[0],Mn[1]=t[1],Mn[2]=t[2],this._state.offsetsBuf.setData(Mn,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,je.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,je.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawEdgesXRayed(e,t){}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,je.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,je.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,je.PICK)}drawPickNormals(e,t){}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}class Hn{constructor(){this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}reset(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}class Un{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class Gn{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}function Vn(e,t,s=null){let n;const i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===s){const t=Fe(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===i)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(n=Fe(e,"WEBGL_compressed_texture_s3tc"),null===n)return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){const t=Fe(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===i)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){const t=Fe(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){const t=Fe(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===i)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){const t=Fe(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){const t=Fe(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===i)return 3001===s?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}const jn=new Uint8Array([0,0,0,1]);class kn{constructor({gl:e,target:t,format:s,type:n,wrapS:i,wrapT:a,wrapR:r,encoding:l,preloadColor:o,premultiplyAlpha:c,flipY:u}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=s||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!u,this.unpackAlignment=4,this.wrapS=i||1e3,this.wrapT=a||1e3,this.wrapR=r||1e3,this.encoding=l||3001,this.texture=e.createTexture(),o&&this.setPreloadColor(o),this.allocated=!0}setPreloadColor(e){e?(jn[0]=Math.floor(255*e[0]),jn[1]=Math.floor(255*e[1]),jn[2]=Math.floor(255*e[2]),jn[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(jn[0]=0,jn[1]=0,jn[2]=0,jn[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let s=0,n=e.length;s1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=Vn(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=Vn(s,this.wrapT);if(r&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,r),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=Vn(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}i?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Wn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Wn(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Vn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Vn(s,this.magFilter)));const l=Vn(s,this.format,this.encoding),o=Vn(s,this.type),c=Qn(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==qn[e])return void qn[e].push({onLoad:t,onProgress:s,onError:n});qn[e]=[],qn[e].push({onLoad:t,onProgress:s,onError:n});const a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),r=this.mimeType,l=this.responseType;fetch(a).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const s=qn[e],n=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,r=0!==a;let l=0;const o=new ReadableStream({start(e){!function t(){n.read().then((({done:n,value:i})=>{if(n)e.close();else{l+=i.byteLength;const n=new ProgressEvent("progress",{lengthComputable:r,loaded:l,total:a});for(let e=0,t=s.length;e{switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,r)));case"json":return e.json();default:if(void 0===r)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(r),s=t&&t[1]?t[1].toLowerCase():void 0,n=new TextDecoder(s);return e.arrayBuffer().then((e=>n.decode(e)))}}})).then((t=>{zn.add(e,t);const s=qn[e];delete qn[e];for(let e=0,n=s.length;e{const s=qn[e];if(void 0===s)throw this.manager.itemError(e),t;delete qn[e];for(let e=0,n=s.length;e{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class Zn{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e{const n=this._getIdleWorker();-1!==n?(this._initWorker(n),this.workerStatus|=1<e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let $n=0;class ei{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new Zn,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const n=e.capabilities;this._workerConfig={astcSupported:n.astcSupported,etc1Supported:n.etc1Supported,etc2Supported:n.etc2Supported,dxtSupported:n.dxtSupported,bptcSupported:n.bptcSupported,pvrtcSupported:n.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new Jn;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new Jn;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const n=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,n]).then((([e,t])=>{const s=ei.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(ei.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(ei.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(ei.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([n])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),$n>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),$n++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((n,i)=>{const a=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e))).then((e=>{const s=e.data,{mipmaps:a,width:r,height:l,format:o,type:c,error:u,dfdTransferFn:h,dfdFlags:p}=s;if("error"===c)return i(u);t.setCompressedData({mipmaps:a,props:{format:o,minFilter:1===a.length?1006:1008,magFilter:1===a.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&p)}}),n()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),$n--}}ei.BasisFormat={ETC1S:0,UASTC_4x4:1},ei.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},ei.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},ei.BasisWorker=function(){let e,t,s;const n=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(r){const u=r.data;switch(u.type){case"init":e=u.config,h=u.transcoderBinary,t=new Promise((e=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:r,hasAlpha:h,mipmaps:p,format:A,dfdTransferFn:d,dfdFlags:f}=function(t){const r=new s.KTX2File(new Uint8Array(t));function u(){r.close(),r.delete()}if(!r.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=r.isUASTC()?a.UASTC_4x4:a.ETC1S,p=r.getWidth(),A=r.getHeight(),d=r.getLevels(),f=r.getHasAlpha(),I=r.getDFDTransferFunc(),y=r.getDFDFlags(),{transcoderFormat:m,engineFormat:v}=function(t,s,r,u){let h,p;const A=t===a.ETC1S?l:o;for(let n=0;n{delete ti[t],s.destroy()}))),s} +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let r=!0,l=r?Float64Array:Float32Array;const o=new l(16),c=new l(16),u=new l(4),h={setDoublePrecisionEnabled(e){r=e,l=r?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>r,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new l(e||2),vec3:e=>new l(e||3),vec4:e=>new l(e||4),mat3:e=>new l(e||9),mat3ToMat4:(e,t=new l(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new l(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new l(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new l(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>h.dotVec4(e,e),lenVec4:e=>Math.sqrt(h.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>h.dotVec3(e,e),sqLenVec2:e=>h.dotVec2(e,e),lenVec3:e=>Math.sqrt(h.sqLenVec3(e)),distVec3:(()=>{const e=new l(3);return(t,s)=>h.lenVec3(h.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(h.sqLenVec2(e)),distVec2:(()=>{const e=new l(2);return(t,s)=>h.lenVec2(h.subVec2(t,s,e))})(),rcpVec3:(e,t)=>h.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/h.lenVec4(e);return h.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/h.lenVec3(e);return h.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/h.lenVec2(e);return h.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=h.dotVec3(e,t)/Math.sqrt(h.sqLenVec3(e)*h.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new l(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=h.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=h.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=h.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||h.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>h.m4s(0),setMat4ToOnes:()=>h.m4s(1),diagonalMat4v:e=>new l([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>h.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>h.diagonalMat4c(e,e,e,e),identityMat4:(e=new l(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new l(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>h.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new l(9));const n=e[0],i=e[3],a=e[6],r=e[1],o=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+o*I+c*v,s[4]=r*d+o*y+c*w,s[7]=r*f+o*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=h.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||h.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||h.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.translationMat4v(e,i))})(),translationMat4s:(e,t)=>h.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>h.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=h.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,p,A,d,f,I;return u=l*o,p=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||h.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*p+d,s[7]=0,s[8]=r*A+f,s[9]=r*p-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>h.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=h.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=h.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>h.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=h.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,p=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=p+v,s[2]=A-m,s[3]=0,s[4]=p-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=h.vec4()){const n=h.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],p=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(p,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(p,-1,1)),Math.abs(p)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(p,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(p,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=h.mat4())=>(h.quaternionToRotationMat4(t,n),h.scaleMat4v(s,n),h.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new l(3),t=new l(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=h.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=h.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=h.lenVec3(e);h.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,p=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=p,t[9]*=p,t[10]*=p,h.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=h.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],p=t[1],A=t[2];if(i===u&&a===p&&r===A)return h.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-p,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>h.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=h.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];h.addVec4(i,n,o),h.subVec4(i,n,c);const a=2*n[2],r=c[0],l=c[1],u=c[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=o[0]/r,s[9]=o[1]/l,s[10]=-o[2]/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/u,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],h.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=h.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new l(16),t=new l(16),s=new l(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||h.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||h.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=h.vec4()){const n=e[0]*h.DEGTORAD/2,i=e[1]*h.DEGTORAD/2,a=e[2]*h.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),p=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"YXZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"ZXY"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"ZYX"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"YZX"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o-c*u*p):"XZY"===t&&(s[0]=c*l*o-r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o+c*u*p),s},mat4ToQuaternion(e,t=h.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let p;const A=s+r+u;return A>0?(p=.5/Math.sqrt(A+1),t[3]=.25/p,t[0]=(c-l)*p,t[1]=(i-o)*p,t[2]=(a-n)*p):s>r&&s>u?(p=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/p,t[0]=.25*p,t[1]=(n+a)/p,t[2]=(i+o)/p):r>u?(p=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/p,t[0]=(n+a)/p,t[1]=.25*p,t[2]=(l+c)/p):(p=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/p,t[0]=(i+o)/p,t[1]=(l+c)/p,t[2]=.25*p),t},vec3PairToQuaternion(e,t,s=h.vec4()){const n=Math.sqrt(h.dotVec3(e,e)*h.dotVec3(t,t));let i=n+h.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):h.cross3Vec3(e,t,s),s[3]=i,h.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=h.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new l(16);return(t,s,n)=>(n=n||h.vec3(),h.quaternionToRotationMat4(t,e),h.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=h.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,p=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+p*-o-A*-l,s[1]=p*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-p*-r,s},quaternionToMat4(e,t){t=h.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,p=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+p,t[2]=f-u,t[4]=d-p,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=h.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>h.normalizeQuaternion(h.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=h.vec4()){const s=(e=h.normalizeQuaternion(e,u))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new l(e||6),AABB2:e=>new l(e||4),OBB3:e=>new l(e||32),OBB2:e=>new l(e||16),Sphere3:(e,t,s,n)=>new l([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new l(3),t=new l(3),s=new l(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],h.subVec3(t,e,s),Math.abs(h.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=h.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],p=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>p?u:p,Math.abs(h.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||h.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||h.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=h.AABB3())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MAX_DOUBLE,e[3]=h.MIN_DOUBLE,e[4]=h.MIN_DOUBLE,e[5]=h.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=h.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new l(3);return(t,s,n)=>{s=s||h.AABB3();let i,a,r,l=h.MAX_DOUBLE,o=h.MAX_DOUBLE,c=h.MAX_DOUBLE,u=h.MIN_DOUBLE,p=h.MIN_DOUBLE,A=h.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>p&&(p=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=p,s[5]=A,s}})(),OBB3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new l(3);return(t,s)=>{s=s||h.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=p);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ip&&(p=u);return n[3]=p,n}})(),getSphere3Center:(e,t=h.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=h.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MIN_DOUBLE,e[3]=h.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=h.AABB2()){let s,n,i,a,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=h.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,p=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+p*p+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=p/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3);return(a,r,l,o,c,u)=>{u=u||h.vec3();const p=h.subVec3(o,l,e),A=h.subVec3(c,l,t),d=h.cross3Vec3(r,A,s),f=h.dotVec3(p,d);if(f<1e-6)return null;const I=h.subVec3(a,l,n),y=h.dotVec3(I,d);if(y<0||y>f)return null;const m=h.cross3Vec3(I,p,i),v=h.dotVec3(r,m);if(v<0||y+v>f)return null;const w=h.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3);return(i,a,r,l,o,c)=>{c=c||h.vec3(),a=h.normalizeVec3(a,e);const u=h.subVec3(l,r,t),p=h.subVec3(o,r,s),A=h.cross3Vec3(u,p,n);h.normalizeVec3(A,A);const d=-h.dotVec3(r,A),f=-(h.dotVec3(i,A)+d)/h.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i,a,r,l)=>{const o=h.subVec3(r,i,e),c=h.subVec3(a,i,t),u=h.subVec3(n,i,s),p=h.dotVec3(o,o),A=h.dotVec3(o,c),d=h.dotVec3(o,u),f=h.dotVec3(c,c),I=h.dotVec3(c,u),y=p*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(p*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=h.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3);return(r,l,o)=>{let c,u;const p=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3),r=new l(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let p=0;p>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,p;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new l(4),t=new l(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,h.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],h.transformVec3(s,e,t),h.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new l(16),t=new l(16),s=new l(4),n=new l(4),i=new l(4),a=new l(4);return(r,l,o,c,u,p)=>{const A=h.mulMat4(o,l,e),d=h.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,h.transformVec4(d,s,n),h.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,h.transformVec4(d,i,a),h.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],h.subVec3(a,n,p),h.normalizeVec3(p)}})(),canvasPosToLocalRay:(()=>{const e=new l(3),t=new l(3);return(s,n,i,a,r,l,o)=>{h.canvasPosToWorldRay(s,n,i,r,e,t),h.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new l(16),t=new l(4),s=new l(4);return(n,i,a,r,l)=>{const o=h.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,h.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],h.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new l(6),o={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return o.triangles=s,o.leaf=!0,o;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),o.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};h.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class p{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const A={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var d=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{v.removeItem(e.id),delete P.scenes[e.id],delete m[e.id],A.components.scenes--}))},this.clear=function(){let e;for(const t in P.scenes)P.scenes.hasOwnProperty(t)&&(e=P.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete P.scenes[e.id]))},this.scheduleTask=function(e,t){w.push(e),w.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;w.length>0&&(e<0||n0&&E>0){var t=1e3/E;D+=t,T.push(t),T.length>=30&&(D-=T.shift()),A.frame.fps=Math.round(D/T.length)}!function(e){const t=P.runTasks(e+10),s=P.getNumTasks();A.frame.tasksRun=t,A.frame.tasksScheduled=s,A.frame.tasksBudget=10}(e),function(e){for(var t in g.time=e,P.scenes)if(P.scenes.hasOwnProperty(t)){var s=P.scenes[t];g.sceneId=t,g.startTime=s.startTime,g.deltaTime=null!=g.prevTime?g.time-g.prevTime:0,s.fire("tick",g,!0)}g.prevTime=e}(e),function(){const e=P.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=m[r],n||(n=m[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),b=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R);class C{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof C))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+y.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(y.isNumeric(s)||y.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+y.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+y.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+y.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():P.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(h.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){z.set(this._viewPos),z[3]=1,h.transformPoint4(this.scene.camera.projMatrix,z,K);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+K[0]/K[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-K[1]/K[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof W?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),O(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class X{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class q{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class J{constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var Z=h.vec3(),$=h.vec3();class ee extends C{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new Y(s,t.origin),this._cornerMarker=new Y(s,t.corner),this._targetMarker=new Y(s,t.target),this._originWorld=h.vec3(),this._cornerWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new X(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new X(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new J(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(h.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,p=t.length;u{switch(a=!0,r=e.entity,l.set(e.worldPos),o.set(e.canvasPos),this._state){case 0:this.markerDiv.style.marginLeft=e.canvasPos[0]-5+"px",this.markerDiv.style.marginTop=e.canvasPos[1]-5+"px",this.markerDiv.style.background="pink",this.markerDiv.style.border="2px solid red";break;case 1:this._currentAngleMeasurement&&(this._currentAngleMeasurement.originWireVisible=!0,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.cornerVisible=!0,this._currentAngleMeasurement.angleVisible=!1,this._currentAngleMeasurement.corner.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer";break;case 2:this._currentAngleMeasurement&&(this._currentAngleMeasurement.targetWireVisible=!0,this._currentAngleMeasurement.targetVisible=!0,this._currentAngleMeasurement.angleVisible=!0,this._currentAngleMeasurement.target.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer"}})),this._onInputMouseDown=i.on("mousedown",(e=>{c=e[0],u=e[1]})),this._onInputMouseUp=i.on("mouseup",(e=>{if(!(e[0]>c+5||e[0]u+5||e[1]{if(a=!1,this.markerDiv.style.marginLeft="-100px",this.markerDiv.style.marginTop="-100px",this._currentAngleMeasurement){switch(this._state){case 0:this._currentAngleMeasurement.originVisible=!1;break;case 1:this._currentAngleMeasurement.cornerVisible=!1,this._currentAngleMeasurement.originWireVisible=!1,this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1;break;case 2:this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1}n.style.cursor="default"}})),n.addEventListener("touchstart",this._onCanvasTouchStart=e=>{const t=e.touches,s=e.changedTouches;1===t.length&&1===s.length&&se(t[0],p)},{passive:!0}),n.addEventListener("touchend",this._onCanvasTouchEnd=e=>{const s=e.touches,n=e.changedTouches;if(0===s.length&&1===n.length){if(se(n[0],A),A[0]>p[0]+5||A[0]p[1]+5||A[1]{this.plugin.fire("markerClicked",this)}),this._marker.addEventListener("mouseenter",this._onMouseEnterExternalMarker=()=>{this.plugin.fire("markerMouseEnter",this)}),this._marker.addEventListener("mouseleave",this._onMouseLeaveExternalMarker=()=>{this.plugin.fire("markerMouseLeave",this)}),this._markerExternal=!0):(this._markerHTML=t.markerHTML,this._htmlDirty=!0,this._markerExternal=!1),t.labelElement?(this._label=t.labelElement,this._labelExternal=!0):(this._labelHTML=t.labelHTML,this._htmlDirty=!0,this._labelExternal=!1),this._markerShown=!!t.markerShown,this._labelShown=!!t.labelShown,this._values=t.values||{},this._layoutDirty=!0,this._visibilityDirty=!0,this._buildHTML(),this._onTick=this.scene.on("tick",(()=>{this._htmlDirty&&(this._buildHTML(),this._htmlDirty=!1,this._layoutDirty=!0,this._visibilityDirty=!0),(this._layoutDirty||this._visibilityDirty)&&(this._markerShown||this._labelShown)&&(this._updatePosition(),this._layoutDirty=!1),this._visibilityDirty&&(this._marker.style.visibility=this.visible&&this._markerShown?"visible":"hidden",this._label.style.visibility=this.visible&&this._markerShown&&this._labelShown?"visible":"hidden",this._visibilityDirty=!1)})),this.on("canvasPos",(()=>{this._layoutDirty=!0})),this.on("visible",(()=>{this._visibilityDirty=!0})),this.setMarkerShown(!1!==t.markerShown),this.setLabelShown(t.labelShown),this.eye=t.eye?t.eye.slice():null,this.look=t.look?t.look.slice():null,this.up=t.up?t.up.slice():null,this.projection=t.projection}_buildHTML(){if(!this._markerExternal){this._marker&&(this._container.removeChild(this._marker),this._marker=null);let e=this._markerHTML||"

";y.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._marker=t.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(()=>{this.plugin.fire("markerClicked",this)})),this._marker.addEventListener("mouseenter",(()=>{this.plugin.fire("markerMouseEnter",this)})),this._marker.addEventListener("mouseleave",(()=>{this.plugin.fire("markerMouseLeave",this)})),this._marker.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);let e=this._labelHTML||"

";y.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._label=t.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}}_updatePosition(){const e=this.scene.canvas.boundary,t=e[0],s=e[1],n=this.canvasPos;this._marker.style.left=Math.floor(t+n[0])-12+"px",this._marker.style.top=Math.floor(s+n[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+n[0]+20)+"px",this._label.style.top=Math.floor(s+n[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}_renderTemplate(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){const s=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),s)}return e}setMarkerShown(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}getMarkerShown(){return this._markerShown}setLabelShown(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}getLabelShown(){return this._labelShown}setField(e,t){this._values[e]=t||"",this._htmlDirty=!0}getField(e){return this._values[e]}setValues(e){for(var t in e)if(e.hasOwnProperty(t)){const s=e[t];this.setField(t,s)}}getValues(){return this._values}destroy(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),super.destroy()}}const ie=h.vec3(),ae=h.vec3(),re=h.vec3();class le extends C{get type(){return"Spinner"}constructor(e,t={}){super(e,t),this._canvas=t.canvas,this._element=null,this._isCustom=!1,t.elementId&&(this._element=document.getElementById(t.elementId),this._element?this._adjustPosition():this.error("Can't find given Spinner HTML element: '"+t.elementId+"' - will automatically create default element")),this._element||this._createDefaultSpinner(),this.processes=0}_createDefaultSpinner(){this._injectDefaultCSS();const e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const oe={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},ce=document.createElement("canvas");if(ce){const e=ce.getContext("webgl",{antialias:!0})||ce.getContext("experimental-webgl",{antialias:!0});oe.WEBGL=!!e,oe.WEBGL&&(oe.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?oe.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?oe.FS_MAX_FLOAT_PRECISION="mediump":oe.FS_MAX_FLOAT_PRECISION="lowp":oe.FS_MAX_FLOAT_PRECISION="mediump",oe.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),oe.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),oe.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),oe.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),oe.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),oe.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),oe.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),oe.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),oe.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),oe.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){oe.SUPPORTED_EXTENSIONS[e]=!0})))}const ue=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class he extends C{constructor(e,t={}){super(e,t),this._backgroundColor=h.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new le(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+h.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function ve(e){console.error(e.join("\n"))}class we{constructor(e,t){this.id=ye.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new de(e,e.VERTEX_SHADER,me(this.source.vertex)),this._fragmentShader=new de(e,e.FRAGMENT_SHADER,me(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void ve(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void ve(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void ve(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void ve(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void ve(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;sthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}class Te{constructor(e,t){this.scene=e,this.aabb=h.AABB3(),this.origin=h.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}_buildMarkerList(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}_buildPositions(){let e=0;for(let t=0;t-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Te(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Te(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new we(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,p=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Pe[0]=a,Pe[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,p),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Pe),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new we(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new ge(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new ge(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new ge(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const Ce=new Float32Array(xe(17,[0,1])),_e=new Float32Array(xe(17,[1,0])),Be=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Ne(n,t));return s}(17,4)),Oe=new Float32Array(2);class Se{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new we(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new ge(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new ge(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new ge(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Oe[0]=r,Oe[1]=l,n.uniform2fv(this._uViewport,Oe),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,_e):n.uniform2fv(this._uSampleOffsets,Ce),n.uniform1fv(this._uSampleWeights,Be);const p=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,p,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Ne(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function xe(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Le{constructor(e,t,s){s=s||{},this.gl=t,this.allocated=!1,this.canvas=e,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}setSize(e){this.size=e}webglContextRestored(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}bind(e=null){if(this._touch(e),this.bound)return;const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}_touch(e=null){let t,s;const n=this.gl;if(this.size?(t=this.size[0],s=this.size[1]):(t=n.drawingBufferWidth,s=n.drawingBufferHeight),this.buffer){if(this.buffer.width===t&&this.buffer.height===s)return;n.deleteTexture(this.buffer.texture),n.deleteFramebuffer(this.buffer.framebuf),n.deleteRenderbuffer(this.buffer.renderbuf)}const i=n.createTexture();let a;n.bindTexture(n.TEXTURE_2D,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),e?n.texStorage2D(n.TEXTURE_2D,1,e,t,s):n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,s,0,n.RGBA,n.UNSIGNED_BYTE,null),this._hasDepthTexture&&(a=n.createTexture(),n.bindTexture(n.TEXTURE_2D,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.DEPTH_COMPONENT32F,t,s,0,n.DEPTH_COMPONENT,n.FLOAT,null));const r=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT32F,t,s);const l=n.createFramebuffer();if(n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,i,0),this._hasDepthTexture?n.framebufferTexture2D(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.TEXTURE_2D,a,0):n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,r),n.bindTexture(n.TEXTURE_2D,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,l),!n.isFramebuffer(l))throw"Invalid framebuffer";n.bindFramebuffer(n.FRAMEBUFFER,null);const o=n.checkFramebufferStatus(n.FRAMEBUFFER);switch(o){case n.FRAMEBUFFER_COMPLETE:break;case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case n.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+o}this.buffer={framebuf:l,renderbuf:r,texture:i,depthTexture:a,width:t,height:s},this.bound=!1}clear(){if(!this.bound)throw"Render buffer not bound";const e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}read(e,t,s=null,n=null,i=Uint8Array,a=4){const r=e,l=(this.buffer.height||this.gl.drawingBufferHeight)-t,o=new i(a),c=this.gl;return c.readPixels(r,l,1,1,s||c.RGBA,n||c.UNSIGNED_BYTE,o,0),o}readArray(e=null,t=null,s=Uint8Array,n=4){const i=new s(this.buffer.width*this.buffer.height*n),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}readImageAsCanvas(){const e=this.gl,t=this._getImageDataCache(),s=t.pixelData,n=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,s);const r=this.buffer.width,l=this.buffer.height,o=l/2|0,c=4*r,u=new Uint8Array(4*r);for(let e=0;eT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class Ue{constructor(e,t,s,n,i=null,a=0){this.model=e,this.object=null,this.parent=null,this.id=t,this.aabb=null,this.layer=i,this.portionId=a,this._color=[s[0],s[1],s[2],n],this._colorize=[s[0],s[1],s[2],n],this._colorizing=!1,this._transparent=n<255,this.numTriangles=0,this.origin=null}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const s=e<255,n=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),n&&this.layer.setTransparent(this.portionId,t,s)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,s,n){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,s,n)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex(this.portionId,e)}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const Ge=new class{constructor(){this._uint8Arrays={},this._float32Arrays={}}_clear(){this._uint8Arrays={},this._float32Arrays={}}getUInt8Array(e){let t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}getFloat32Array(e){let t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}};let Ve=0;const je={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},ke=new e({});class Qe{constructor(e){this.id=ke.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){ke.removeItem(this.id)}}const We=function(){const e=h.mat4(),t=h.mat4();return function(s,n){n=n||h.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return h.identityMat4(e),h.translationMat4v(s,e),h.identityMat4(t),h.scalingMat4v([l/u,o/u,c/u],t),h.mulMat4(e,t,n),n}}();var ze=function(){const e=h.mat4(),t=h.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function Xe(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function qe(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const Je={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=Ye(e,l,"floor","ceil"),n=Xe(s),a=qe(e,l,n),a>r&&(i=s,r=a),s=Ye(e,l,"ceil","ceil"),n=Xe(s),a=qe(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},Ze=new Float32Array([1,1,1,1]),$e=new Float32Array([0,0,0,1]),et=h.vec4(),tt=h.vec3();class st{constructor(e,t=!1,{instancing:s=!1,edges:n=!1}={}){this._scene=e,this._withSAO=t,this._instancing=s,this._edges=n,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}_getHash(){return this._scene._sectionPlanesState.getHash()}_buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}_buildVertexShader(){return[""]}_buildFragmentShader(){return[""]}_addMatricesUniformBlockLines(e,t=!1){return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}getValid(){return this._hash===this._getHash()}setSectionPlanesStateUniforms(e){const t=this._scene,{gl:s}=t.canvas,{model:n,layerIndex:i}=e,a=t._sectionPlanesState.sectionPlanes.length;if(a>0){const r=t._sectionPlanesState.sectionPlanes,l=i*a,o=n.renderFlags;for(let t=0;t0&&(this._uReflectionMap="reflectionMap"),s.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(let t=0,s=e._sectionPlanesState.sectionPlanes.length;t0&&A.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,A.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),A.lightMaps.length>0&&A.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,A.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),this._withSAO){const t=r.sao;if(t.possible){const s=l.drawingBufferWidth,n=l.drawingBufferHeight;et[0]=s,et[1]=n,et[2]=t.blendCutoff,et[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,et),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++}}if(n){const e=this._edges?"edgeColor":"fillColor",t=this._edges?"edgeAlpha":"fillAlpha";if(s===je[(this._edges?"EDGES":"SILHOUETTE")+"_XRAYED"]){const s=r.xrayMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===je[(this._edges?"EDGES":"SILHOUETTE")+"_HIGHLIGHTED"]){const s=r.highlightMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===je[(this._edges?"EDGES":"SILHOUETTE")+"_SELECTED"]){const s=r.selectedMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else l.uniform4fv(this._uColor,this._edges?$e:Ze)}this._draw({state:o,frameCtx:e,incrementDrawState:i}),l.bindVertexArray(null)}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null,A.memory.programs--}}class nt extends st{constructor(e,t,{instancing:s=!1,edges:n=!1}={}){super(e,t,{instancing:s,edges:n})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;if(this._edges)t.drawElements(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0);else{const e=n.pickElementsCount||s.indicesBuf.numItems,a=n.pickElementsOffset?n.pickElementsOffset*s.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,e,s.indicesBuf.itemType,a),i&&n.drawElements++}}}class it extends nt{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class at extends st{constructor(e,t,{edges:s=!1}={}){super(e,t,{instancing:!0,edges:s})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;this._edges?t.drawElementsInstanced(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances):(t.drawElementsInstanced(t.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++)}}class rt extends at{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class lt extends st{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArrays(t.POINTS,0,s.positionsBuf.numItems),i&&n.drawArrays++}}class ot extends st{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArraysInstanced(t.POINTS,0,s.positionsBuf.numItems,s.numInstances),i&&n.drawArrays++}}class ct extends st{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElements(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0),i&&n.drawElements++}}class ut extends st{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElementsInstanced(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++}}class ht extends nt{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i;const a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class pt extends nt{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching flat-shading draw vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._lightsState,s=e._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),n){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,s=t.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}class dt extends it{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class ft extends it{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class It extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class yt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class mt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec3 worldNormal = octDecode(normal.xy); "),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class vt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class wt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching depth fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}class gt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Tt extends nt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry shadow vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push(" int colorFlag = int(flags) & 0xF;"),s.push(" bool visible = (colorFlag > 0);"),s.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push(" if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry shadow fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = encodeFloat( gl_FragCoord.z); "),s.push("}"),s}}class Et extends nt{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Triangles batching quality draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),r.push("uniform sampler2D uAOMap;"),r.push("in vec4 vViewPosition;"),r.push("in vec3 vViewNormal;"),r.push("in vec4 vColor;"),r.push("in vec2 vUV;"),r.push("in vec2 vMetallicRoughness;"),n.lightMaps.length>0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick flat normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out float vFlags;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags = flags;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick flat normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class Dt extends nt{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching color texture vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._lightsState,n=e._sectionPlanesState,i=n.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(let e=0,t=n.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(let e=0,t=n.sectionPlanes.length;e 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,t=s.lights.length;e5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]}}const _t=h.mat4(),Bt=h.mat4();function Ot(e,t,s){const n=e.length,i=new Uint16Array(n),a=t[0],r=t[1],l=t[2],o=t[3]-a,c=t[4]-r,u=t[5]-l,p=65525,A=p/o,d=p/c,f=p/u,I=e=>e>=0?e:0;for(let t=0;t=0?1:-1),t=(1-Math.abs(n))*(i>=0?1:-1),n=e,i=t}return new Int8Array([Math[t](127.5*n+(n<0?-1:0)),Math[s](127.5*i+(i<0?-1:0))])}function xt(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}const Lt=h.vec3();class Mt{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;let c=a.eye;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];const u=t.aabb,p=[h.safeInv(u[3]-u[0])*h.MAX_INT,h.safeInv(u[4]-u[1])*h.MAX_INT,h.safeInv(u[5]-u[2])*h.MAX_INT];if(e._coordinateScale[0]=h.safeInv(p[0]),e._coordinateScale[1]=h.safeInv(p[1]),e._coordinateScale[2]=h.safeInv(p[2]),!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),e.pickViewMatrix&&(c=e.pickOrigin||c);const A=[c[0]-o[0],c[1]-o[1],c[2]-o[2]];r.uniform3fv(this._uCameraEyeRtc,A),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.layerNumber),r.uniform3fv(this._uCoordinateScaler,p),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform1i(this._uSolid,t.solid);const d=e.pickViewMatrix||a.viewMatrix,f=o?B(d,o):d;if(r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,a=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),s.push("uniform bool solid;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Ft=h.vec3();class Ht{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];const c=t.aabb,u=[h.safeInv(c[3]-c[0])*h.MAX_INT,h.safeInv(c[4]-c[1])*h.MAX_INT,h.safeInv(c[5]-c[2])*h.MAX_INT];if(e._coordinateScale[0]=h.safeInv(u[0]),e._coordinateScale[1]=h.safeInv(u[1]),e._coordinateScale[2]=h.safeInv(u[2]),!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());let p=a.eye;e.pickViewMatrix&&(p=e.pickOrigin||p);const A=[p[0]-o[0],p[1]-o[1],p[2]-o[2]];r.uniform3fv(this._uCameraEyeRtc,A),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.layerNumber),r.uniform3fv(this._uCoordinateScaler,u),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);const d=e.pickViewMatrix||a.viewMatrix,f=o?B(d,o):d;if(r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,a=n.renderFlags;for(let t=0;t0;e.pointsMaterial._state;const s=[];return s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class Ut{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Mt(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Ht(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Gt={};const Vt=h.mat4(),jt=h.mat4(),kt=h.vec4([0,0,0,1]),Qt=h.vec4([0,0,0,1]),Wt=h.vec4([0,0,0,1]),zt=h.OBB3(),Kt=h.vec3(),Yt=h.vec3(),Xt=h.vec3(),qt=h.vec3(),Jt=h.vec3(),Zt=h.vec3(),$t=h.vec3();class es{constructor(e){console.log("Creating TrianglesBatchingLayer"),this.model=e.model,this.sortId="TrianglesBatchingLayer"+(e.solid?"-solid":"-surface")+(e.autoNormals?"-autonormals":"-normals")+(e.textureSet&&e.textureSet.colorTexture?"-colorTexture":"")+(e.textureSet&&e.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=Rt[t];return s||(s=new Pt(e),Rt[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Rt[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=Gt[t];return s||(s=new Ut(e),Gt[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Gt[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Ct(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Qe({origin:h.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:e.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=h.mat4(e.positionsDecodeMatrix)),e.uvDecodeMatrix?(this._state.uvDecodeMatrix=h.mat3(e.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,e.origin&&this._state.origin.set(e.origin),this.aabb=h.collapseAABB3(),this.solid=!!e.solid}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(let e=0,t=i.length;e0){const e=Vt;I?h.inverseMat4(h.transposeMat4(I,jt),e):h.identityMat4(e,e),function(e,t,s,n,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let r,l,o,c,u,p,A=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(p=0;pu&&(o=r,u=c),r=Nt(d,"floor","ceil"),l=xt(r),c=a(d,l),c>u&&(o=r,u=c),r=Nt(d,"ceil","ceil"),l=xt(r),c=a(d,l),c>u&&(o=r,u=c),n[i+p+0]=o[0],n[i+p+1]=o[1],n[i+p+2]=0}(e,n,n.length,g.normals,g.normals.length)}if(l)for(let e=0,t=l.length;e0)for(let e=0,t=a.length;e0)for(let e=0,t=r.length;e0){const n=this._state.positionsDecodeMatrix?new Uint16Array(s.positions):Ot(s.positions,this._modelAABB,this._state.positionsDecodeMatrix=h.mat4());if(e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(let e=0,t=this._portions.length;e0){const n=new Int8Array(s.normals);let i=!0;e.normalsBuf=new ge(t,t.ARRAY_BUFFER,n,s.normals.length,3,t.STATIC_DRAW,i)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.uv.length>0)if(e.uvDecodeMatrix){let n=!1;e.uvBuf=new ge(t,t.ARRAY_BUFFER,s.uv,s.uv.length,2,t.STATIC_DRAW,n)}else{const n=Je.getUVBounds(s.uv),i=Je.compressUVs(s.uv,n.min,n.max),a=i.quantized;let r=!1;e.uvDecodeMatrix=h.mat3(i.decodeMatrix),e.uvBuf=new ge(t,t.ARRAY_BUFFER,a,a.length,2,t.STATIC_DRAW,r)}if(s.metallicRoughness.length>0){const n=new Uint8Array(s.metallicRoughness);let i=!1;e.metallicRoughnessBuf=new ge(t,t.ARRAY_BUFFER,n,s.metallicRoughness.length,2,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n),a=!1;e.flagsBuf=new ge(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new ge(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}if(s.edgeIndices.length>0){const n=new Uint32Array(s.edgeIndices);e.edgeIndicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,n,s.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}isEmpty(){return!this._state.indicesBuf}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=e,n=this._portions[s],i=4*n.vertsBaseIndex,a=4*n.numVerts,r=this._scratchMemory.getUInt8Array(a),l=t[0],o=t[1],c=t[2],u=t[3];for(let e=0;em)&&(m=e,n.set(v),i&&h.triangleNormal(d,f,I,i),y=!0)}}return y&&i&&(h.transformVec3(this.model.worldNormalMatrix,i,i),h.normalizeVec3(i)),y}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}class ts extends at{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i,a,r;const l=[];for(l.push("#version 300 es"),l.push("// Instancing geometry drawing vertex shader"),l.push("uniform int renderPass;"),l.push("in vec3 position;"),l.push("in vec2 normal;"),l.push("in vec4 color;"),l.push("in float flags;"),e.entityOffsetsEnabled&&l.push("in vec3 offset;"),l.push("in vec4 modelMatrixCol0;"),l.push("in vec4 modelMatrixCol1;"),l.push("in vec4 modelMatrixCol2;"),l.push("in vec4 modelNormalMatrixCol0;"),l.push("in vec4 modelNormalMatrixCol1;"),l.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(l,!0),e.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;")),l.push("uniform vec4 lightAmbient;"),i=0,a=s.lights.length;i= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"),n&&(l.push("out vec4 vWorldPosition;"),l.push("out float vFlags;")),l.push("out vec4 vColor;"),l.push("void main(void) {"),l.push("int colorFlag = int(flags) & 0xF;"),l.push("if (colorFlag != renderPass) {"),l.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),l.push("} else {"),l.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),l.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&l.push(" worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix * worldPosition; "),l.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),l.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),l.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),i=0,a=s.lights.length;i0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class ss extends at{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState;let n,i;const a=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry flat-shading drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),a){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}for(r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),n=0,i=s.lights.length;n0,s=[];return s.push("#version 300 es"),s.push("// Instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing fill fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class is extends rt{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class as extends rt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class rs extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class ls extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class os extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec2 normal;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("in vec4 modelNormalMatrixCol0;"),s.push("in vec4 modelNormalMatrixCol1;"),s.push("in vec4 modelNormalMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class cs extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("in float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class us extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}class hs extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class ps extends at{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}const As={3e3:"linearToLinear",3001:"sRGBToLinear"};class ds extends at{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Instancing geometry quality drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),r.push("#define PI 3.14159265359"),r.push("#define RECIPROCAL_PI 0.31830988618"),r.push("#define RECIPROCAL_PI2 0.15915494"),r.push("#define EPSILON 1e-6"),r.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),r.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),r.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),r.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),r.push(" return normalize(surf_norm );"),r.push(" }"),r.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),r.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),r.push(" vec2 st0 = dFdx( uv.st );"),r.push(" vec2 st1 = dFdy( uv.st );"),r.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),r.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),r.push(" vec3 N = normalize( surf_norm );"),r.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),r.push(" mat3 tsn = mat3( S, T, N );"),r.push(" return normalize( tsn * mapN );"),r.push("}"),r.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),r.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),r.push("}"),r.push("struct IncidentLight {"),r.push(" vec3 color;"),r.push(" vec3 direction;"),r.push("};"),r.push("struct ReflectedLight {"),r.push(" vec3 diffuse;"),r.push(" vec3 specular;"),r.push("};"),r.push("struct Geometry {"),r.push(" vec3 position;"),r.push(" vec3 viewNormal;"),r.push(" vec3 worldNormal;"),r.push(" vec3 viewEyeDir;"),r.push("};"),r.push("struct Material {"),r.push(" vec3 diffuseColor;"),r.push(" float specularRoughness;"),r.push(" vec3 specularColor;"),r.push(" float shine;"),r.push("};"),r.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),r.push(" float r = ggxRoughness + 0.0001;"),r.push(" return (2.0 / (r * r) - 2.0);"),r.push("}"),r.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),r.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),r.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),r.push("}"),n.reflectionMaps.length>0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = "+As[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = "+As[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&s.push("out float vFlags;"),s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&s.push("vFlags = flags;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class Is extends at{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState;let i,a;const r=s.sectionPlanes.length>0,l=[];if(l.push("#version 300 es"),l.push("// Instancing geometry drawing fragment shader"),l.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),l.push("precision highp float;"),l.push("precision highp int;"),l.push("#else"),l.push("precision mediump float;"),l.push("precision mediump int;"),l.push("#endif"),e.logarithmicDepthBufferEnabled&&(l.push("in float isPerspective;"),l.push("uniform float logDepthBufFC;"),l.push("in float vFragDepth;")),l.push("uniform sampler2D uColorMap;"),this._withSAO&&(l.push("uniform sampler2D uOcclusionTexture;"),l.push("uniform vec4 uSAOParams;"),l.push("const float packUpscale = 256. / 255.;"),l.push("const float unpackDownScale = 255. / 256.;"),l.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),l.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),l.push("float unpackRGBToFloat( const in vec4 v ) {"),l.push(" return dot( v, unPackFactors );"),l.push("}")),l.push("uniform float gammaFactor;"),l.push("vec4 linearToLinear( in vec4 value ) {"),l.push(" return value;"),l.push("}"),l.push("vec4 sRGBToLinear( in vec4 value ) {"),l.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),l.push("}"),l.push("vec4 gammaToLinear( in vec4 value) {"),l.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),l.push("}"),t&&(l.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),l.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),l.push("}")),r){l.push("in vec4 vWorldPosition;"),l.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),l.push(" if (clippable) {"),l.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),l.push(" discard;"),l.push(" }"),l.push("}")}for(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),l.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),l.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),l.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),i=0,a=n.lights.length;i0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// Points instancing snap vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const gs=h.vec3();class Ts{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.canvas.gl,r=t._state,l=t._state.origin,o=r.geometry;e._origin[0]=l[0],e._origin[1]=l[1],e._origin[2]=l[2];const c=t.aabb,u=[h.safeInv(c[3]-c[0])*h.MAX_INT,h.safeInv(c[4]-c[1])*h.MAX_INT,h.safeInv(c[5]-c[2])*h.MAX_INT];if(e._coordinateScale[0]=h.safeInv(u[0]),e._coordinateScale[1]=h.safeInv(u[1]),e._coordinateScale[2]=h.safeInv(u[2]),!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const p=i.camera;let A=p.eye;e.pickViewMatrix&&(A=e.pickOrigin||A);const d=[A[0]-l[0],A[1]-l[1],A[2]-l[2]];a.uniform3fv(this._uCameraEyeRtc,d),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.layerNumber),a.uniform3fv(this._uCoordinateScaler,u),a.uniform1i(this._uRenderPass,s),a.uniform1i(this._uPickInvisible,e.pickInvisible);const f=e.pickViewMatrix||p.viewMatrix,I=l?B(f,l):f;if(a.uniformMatrix4fv(this._uViewMatrix,!1,I),a.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,p.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,t)}const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// Points instancing snap vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class Es{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new ws(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Ts(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const bs={};const Ds=new Uint8Array(4),Ps=new Float32Array(1),Rs=h.vec4([0,0,0,1]),Cs=h.vec4([0,0,0,1]),_s=h.vec4([0,0,0,1]),Bs=new Float32Array(3),Os=h.vec3(),Ss=h.vec3(),Ns=h.vec3(),xs=h.vec3(),Ls=h.vec3(),Ms=h.vec3(),Fs=h.vec3();class Hs{constructor(e){console.log("Creating TrianglesInstancingLayer"),this.model=e.model,this.sortId="TrianglesInstancingLayer"+(e.solid?"-solid":"-surface")+(e.normals?"-normals":"-autoNormals"),this.layerIndex=e.layerIndex,this._instancingRenderers=function(e){const t=e.id;let s=ms[t];return s||(s=new ys(e),ms[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete ms[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=bs[t];return s||(s=new Es(e),bs[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete bs[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Qe({numInstances:0,obb:h.OBB3(),origin:h.vec3(),geometry:e.geometry,textureSet:e.textureSet,pbrSupported:!1,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],e.origin&&this._state.origin.set(e.origin),this._finalized=!1,this.aabb=h.collapseAABB3(),this.solid=!!e.solid,this.numIndices=e.geometry.numIndices}createPortion(e){const t=e.color,s=e.metallic,n=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,r=e.sceneModelMatrix,l=e.aabb,o=e.pickColor;if(this._finalized)throw"Already finalized";const c=t[0],u=t[1],p=t[2];if(this._colors.push(c),this._colors.push(u),this._colors.push(p),this._colors.push(i),this._metallicRoughness.push(null!=s?s:0),this._metallicRoughness.push(null!=n?n:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){let e=h.transposeMat4(a,h.mat4()),t=h.inverseMat4(e);this._modelNormalMatrixCol0.push(t[0]),this._modelNormalMatrixCol0.push(t[4]),this._modelNormalMatrixCol0.push(t[8]),this._modelNormalMatrixCol0.push(t[12]),this._modelNormalMatrixCol1.push(t[1]),this._modelNormalMatrixCol1.push(t[5]),this._modelNormalMatrixCol1.push(t[9]),this._modelNormalMatrixCol1.push(t[13]),this._modelNormalMatrixCol2.push(t[2]),this._modelNormalMatrixCol2.push(t[6]),this._modelNormalMatrixCol2.push(t[10]),this._modelNormalMatrixCol2.push(t[14])}this._pickColors.push(o[0]),this._pickColors.push(o[1]),this._pickColors.push(o[2]),this._pickColors.push(o[3]);const A=this._state.geometry.positionsCompressed.length,d=this._state.geometry.positionsCompressed,f=this._state.geometry.positionsDecodeMatrix;for(let e=0;e0){let t=!1;e.colorsBuf=new ge(n,n.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,n.DYNAMIC_DRAW,t),this._colors=[]}if(this._metallicRoughness.length>0){const t=new Uint8Array(this._metallicRoughness);let s=!1;e.metallicRoughnessBuf=new ge(n,n.ARRAY_BUFFER,t,this._metallicRoughness.length,2,n.STATIC_DRAW,s)}if(a>0){let t=!1;e.flagsBuf=new ge(n,n.ARRAY_BUFFER,new Float32Array(a),a,1,n.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;e.offsetsBuf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,n.DYNAMIC_DRAW,t),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){const s=!1;e.positionsBuf=new ge(n,n.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,n.STATIC_DRAW,s),e.positionsDecodeMatrix=h.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){const s=new Uint8Array(t.colorsCompressed),i=!1;e.colorsBuf=new ge(n,n.ARRAY_BUFFER,s,s.length,4,n.STATIC_DRAW,i)}if(t.uvCompressed&&t.uvCompressed.length>0){const s=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new ge(n,n.ARRAY_BUFFER,s,s.length,2,n.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new ge(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,n.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new ge(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,n.STATIC_DRAW)),this._modelMatrixCol0.length>0){const t=!1;e.modelMatrixCol0Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelMatrixCol1Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelMatrixCol2Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol1Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol2Buf=new ge(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){const t=!1;e.pickColorsBuf=new ge(n,n.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,n.STATIC_DRAW,t),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&s&&s.colorTexture&&s.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!s&&!!s.colorTexture,this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Ds[0]=t[0],Ds[1]=t[1],Ds[2]=t[2],Ds[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Ds,4*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&V),l=!!(t&j),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?je.NOT_RENDERED:s?je.COLOR_TRANSPARENT:je.COLOR_OPAQUE,h=!n||c?je.NOT_RENDERED:r?je.SILHOUETTE_SELECTED:a?je.SILHOUETTE_HIGHLIGHTED:i?je.SILHOUETTE_XRAYED:je.NOT_RENDERED;let p=0;p=!n||c?je.NOT_RENDERED:r?je.EDGES_SELECTED:a?je.EDGES_HIGHLIGHTED:i?je.EDGES_XRAYED:l?s?je.EDGES_COLOR_TRANSPARENT:je.EDGES_COLOR_OPAQUE:je.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?je.PICK:je.NOT_RENDERED)<<12,A|=(t&F?1:0)<<16,Ps[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Ps,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Bs[0]=t[0],Bs[1]=t[1],Bs[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Bs,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}getEachVertex(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;const s=this._state,n=s.geometry,i=this._portions[e];if(!i)return void this.model.error("portion not found: "+e);const a=n.quantizedPositions,r=s.origin,l=i.offset,o=r[0]+l[0],c=r[1]+l[1],u=r[2]+l[2],p=Rs,A=i.matrix,d=this.model.sceneModelMatrix,f=s.positionsDecodeMatrix;for(let e=0,s=a.length;ev)&&(v=e,n.set(w),i&&h.triangleNormal(f,I,y,i),m=!0)}}return m&&i&&(h.transformVec3(l.normalMatrix,i,i),h.transformVec3(this.model.worldNormalMatrix,i,i),h.normalizeVec3(i)),m}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}class Us extends ct{drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Gs extends ct{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class Vs{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Us(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Gs(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const js={};class ks{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const Qs=h.vec4([0,0,0,1]),Ws=h.vec4([0,0,0,1]),zs=h.vec4([0,0,0,1]),Ks=h.OBB3();class Ys{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=js[t];return s||(s=new Vs(e),js[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete js[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new ks(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Qe({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:h.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=h.vec3(e.origin)),this.aabb=h.collapseAABB3()}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Ot(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.colors.length>0){const n=s.colors.length/4,i=new Float32Array(n);let a=!1;e.flagsBuf=new ge(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new ge(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2],c=t[3];for(let e=0;e0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 lightAmbient;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class qs extends ut{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 color;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class Js{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Xs(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new qs(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const Zs={};const $s=new Uint8Array(4),en=new Float32Array(1),tn=h.vec4([0,0,0,1]),sn=h.vec4([0,0,0,1]),nn=h.vec4([0,0,0,1]),an=new Float32Array(3);class rn{constructor(e){this.model=e.model,this.material=e.material,this.sortId="LinesInstancingLayer",this.layerIndex=e.layerIndex,this._linesInstancingRenderers=function(e){const t=e.id;let s=Zs[t];return s||(s=new Js(e),Zs[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Zs[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Qe({obb:h.OBB3(),numInstances:0,origin:null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],e.origin&&(this._state.origin=h.vec3(e.origin)),this._finalized=!1,this.aabb=h.collapseAABB3()}createPortion(e){const t=e.color,s=e.opacity,n=e.meshMatrix,i=e.worldMatrix,a=e.aabb;if(this._finalized)throw"Already finalized";const r=t[0],l=t[1],o=t[2];t[3],this._colors.push(r),this._colors.push(l),this._colors.push(o),this._colors.push(s),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(n[0]),this._modelMatrixCol0.push(n[4]),this._modelMatrixCol0.push(n[8]),this._modelMatrixCol0.push(n[12]),this._modelMatrixCol1.push(n[1]),this._modelMatrixCol1.push(n[5]),this._modelMatrixCol1.push(n[9]),this._modelMatrixCol1.push(n[13]),this._modelMatrixCol2.push(n[2]),this._modelMatrixCol2.push(n[6]),this._modelMatrixCol2.push(n[10]),this._modelMatrixCol2.push(n[14]),h.collapseAABB3(a);const c=this._state.obb,u=c.length;for(let e=0;e0){let t=!1;this._state.colorsBuf=new ge(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,t),this._colors=[]}if(s>0){let t=!1;this._state.flagsBuf=new ge(e,e.ARRAY_BUFFER,new Float32Array(s),s,1,e.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";$s[0]=t[0],$s[1]=t[1],$s[2]=t[2],$s[3]=t[3],this._state.colorsBuf.setData($s,4*e,4)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&V),l=!!(t&j),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?je.NOT_RENDERED:s?je.COLOR_TRANSPARENT:je.COLOR_OPAQUE,h=!n||c?je.NOT_RENDERED:r?je.SILHOUETTE_SELECTED:a?je.SILHOUETTE_HIGHLIGHTED:i?je.SILHOUETTE_XRAYED:je.NOT_RENDERED;let p=0;p=!n||c?je.NOT_RENDERED:r?je.EDGES_SELECTED:a?je.EDGES_HIGHLIGHTED:i?je.EDGES_XRAYED:l?s?je.EDGES_COLOR_TRANSPARENT:je.EDGES_COLOR_OPAQUE:je.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?je.PICK:je.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,en[0]=A,this._state.flagsBuf.setData(en,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(an[0]=t[0],an[1]=t[1],an[2]=t[2],this._state.offsetsBuf.setData(an,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,je.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,je.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesXRayed(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawOcclusion(e,t){}drawShadow(e,t){}drawPickMesh(e,t){}drawPickDepths(e,t){}drawPickNormals(e,t){}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}class ln extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial,n=[];return n.push("#version 300 es"),n.push("// Points batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class on extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}class cn extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class un extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batched pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batched pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class hn extends lt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push(" gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class pn{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new ln(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new on(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new cn(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new un(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new hn(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const An={};class dn{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]}}const fn=h.vec4(),In=h.vec4(),yn=h.vec4([0,0,0,1]),mn=h.vec4([0,0,0,1]),vn=h.vec4([0,0,0,1]),wn=h.OBB3();class gn{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=An[t];return s||(s=new pn(e),An[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete An[t],s._destroy()}))),s}(e.model.scene),this._buffer=new dn(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Qe({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:h.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=h.collapseAABB3(),this._portions=[],this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=h.vec3(e.origin)),this.aabb=h.collapseAABB3()}canCreatePortion(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}createPortion(e){if(this._finalized)throw"Already finalized";const t=e.positions,s=e.positionsCompressed,n=e.color,i=e.colorsCompressed,a=e.colors,r=e.meshMatrix,l=e.worldMatrix,o=e.worldAABB,c=e.pickColor,u=this._buffer,p=u.positions.length/3;let A;if(this._preCompressedPositionsExpected){if(!s)throw"positionsCompressed expected";for(let e=0,t=s.length;e0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Ot(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new ge(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n);let a=!1;e.flagsBuf=new ge(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new ge(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new ge(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized"}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2];for(let e=0;e0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class En extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 silhouetteColor;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class bn extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick mesh fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class Dn extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Pn extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Rn extends ot{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class Cn extends ot{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("gl_PointSize = pointSize;"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }"),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class _n{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Tn(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new En(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Rn(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new bn(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Dn(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Pn(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new Cn(this._scene)),this._shadowRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}const Bn={};const On=new Uint8Array(4),Sn=new Float32Array(1),Nn=h.vec4([0,0,0,1]),xn=h.vec4([0,0,0,1]),Ln=h.vec4([0,0,0,1]),Mn=new Float32Array(3);class Fn{constructor(e){this.model=e.model,this.material=e.material,this.sortId="PointsInstancingLayer",this.layerIndex=e.layerIndex,this._pointsInstancingRenderers=function(e){const t=e.id;let s=Bn[t];return s||(s=new _n(e),Bn[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Bn[t],s._destroy()}))),s}(e.model.scene),this._aabb=h.collapseAABB3(),this._state=new Qe({obb:h.OBB3(),numInstances:0,origin:e.origin?h.vec3(e.origin):null,geometry:e.geometry,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=h.collapseAABB3()}createPortion(e){const t=e.meshMatrix,s=e.worldMatrix,n=e.aabb,i=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(i[0]),this._pickColors.push(i[1]),this._pickColors.push(i[2]),this._pickColors.push(i[3]),h.collapseAABB3(n);const a=this._state.obb,r=a.length;for(let e=0;e0){let s=!1;this._state.flagsBuf=new ge(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,s)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new ge(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){const t=!1;this._state.pickColorsBuf=new ge(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,t),this._pickColors=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&x&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&G&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&U&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&V&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&F&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&j&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&M&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&L&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&x?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&G?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&U?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&F?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&L?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";On[0]=t[0],On[1]=t[1],On[2]=t[2],this._state.colorsBuf.setData(On,3*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&x),i=!!(t&U),a=!!(t&G),r=!!(t&V),l=!!(t&j),o=!!(t&M),c=!!(t&L);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?je.NOT_RENDERED:s?je.COLOR_TRANSPARENT:je.COLOR_OPAQUE,h=!n||c?je.NOT_RENDERED:r?je.SILHOUETTE_SELECTED:a?je.SILHOUETTE_HIGHLIGHTED:i?je.SILHOUETTE_XRAYED:je.NOT_RENDERED;let p=0;p=!n||c?je.NOT_RENDERED:r?je.EDGES_SELECTED:a?je.EDGES_HIGHLIGHTED:i?je.EDGES_XRAYED:l?s?je.EDGES_COLOR_TRANSPARENT:je.EDGES_COLOR_OPAQUE:je.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?je.PICK:je.NOT_RENDERED)<<12,A|=(t&F?255:0)<<16,Sn[0]=A,this._state.flagsBuf.setData(Sn,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Mn[0]=t[0],Mn[1]=t[1],Mn[2]=t[2],this._state.offsetsBuf.setData(Mn,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,je.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,je.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,je.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawEdgesXRayed(e,t){}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,je.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,je.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,je.PICK)}drawPickNormals(e,t){}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}class Hn{constructor(){this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}reset(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}class Un{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class Gn{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}function Vn(e,t,s=null){let n;const i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===s){const t=Fe(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===i)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(n=Fe(e,"WEBGL_compressed_texture_s3tc"),null===n)return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){const t=Fe(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===i)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){const t=Fe(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){const t=Fe(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===i)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){const t=Fe(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){const t=Fe(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===i)return 3001===s?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}const jn=new Uint8Array([0,0,0,1]);class kn{constructor({gl:e,target:t,format:s,type:n,wrapS:i,wrapT:a,wrapR:r,encoding:l,preloadColor:o,premultiplyAlpha:c,flipY:u}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=s||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!u,this.unpackAlignment=4,this.wrapS=i||1e3,this.wrapT=a||1e3,this.wrapR=r||1e3,this.encoding=l||3001,this.texture=e.createTexture(),o&&this.setPreloadColor(o),this.allocated=!0}setPreloadColor(e){e?(jn[0]=Math.floor(255*e[0]),jn[1]=Math.floor(255*e[1]),jn[2]=Math.floor(255*e[2]),jn[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(jn[0]=0,jn[1]=0,jn[2]=0,jn[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let s=0,n=e.length;s1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=Vn(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=Vn(s,this.wrapT);if(r&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,r),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=Vn(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}i?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Wn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Wn(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Vn(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Vn(s,this.magFilter)));const l=Vn(s,this.format,this.encoding),o=Vn(s,this.type),c=Qn(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==qn[e])return void qn[e].push({onLoad:t,onProgress:s,onError:n});qn[e]=[],qn[e].push({onLoad:t,onProgress:s,onError:n});const a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),r=this.mimeType,l=this.responseType;fetch(a).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const s=qn[e],n=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,r=0!==a;let l=0;const o=new ReadableStream({start(e){!function t(){n.read().then((({done:n,value:i})=>{if(n)e.close();else{l+=i.byteLength;const n=new ProgressEvent("progress",{lengthComputable:r,loaded:l,total:a});for(let e=0,t=s.length;e{switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,r)));case"json":return e.json();default:if(void 0===r)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(r),s=t&&t[1]?t[1].toLowerCase():void 0,n=new TextDecoder(s);return e.arrayBuffer().then((e=>n.decode(e)))}}})).then((t=>{zn.add(e,t);const s=qn[e];delete qn[e];for(let e=0,n=s.length;e{const s=qn[e];if(void 0===s)throw this.manager.itemError(e),t;delete qn[e];for(let e=0,n=s.length;e{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class Zn{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e{const n=this._getIdleWorker();-1!==n?(this._initWorker(n),this.workerStatus|=1<e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let $n=0;class ei{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new Zn,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const n=e.capabilities;this._workerConfig={astcSupported:n.astcSupported,etc1Supported:n.etc1Supported,etc2Supported:n.etc2Supported,dxtSupported:n.dxtSupported,bptcSupported:n.bptcSupported,pvrtcSupported:n.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new Jn;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new Jn;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const n=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,n]).then((([e,t])=>{const s=ei.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(ei.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(ei.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(ei.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([n])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),$n>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),$n++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((n,i)=>{const a=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e))).then((e=>{const s=e.data,{mipmaps:a,width:r,height:l,format:o,type:c,error:u,dfdTransferFn:h,dfdFlags:p}=s;if("error"===c)return i(u);t.setCompressedData({mipmaps:a,props:{format:o,minFilter:1===a.length?1006:1008,magFilter:1===a.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&p)}}),n()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),$n--}}ei.BasisFormat={ETC1S:0,UASTC_4x4:1},ei.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},ei.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},ei.BasisWorker=function(){let e,t,s;const n=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(r){const u=r.data;switch(u.type){case"init":e=u.config,h=u.transcoderBinary,t=new Promise((e=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:r,hasAlpha:h,mipmaps:p,format:A,dfdTransferFn:d,dfdFlags:f}=function(t){const r=new s.KTX2File(new Uint8Array(t));function u(){r.close(),r.delete()}if(!r.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=r.isUASTC()?a.UASTC_4x4:a.ETC1S,p=r.getWidth(),A=r.getHeight(),d=r.getLevels(),f=r.getHasAlpha(),I=r.getDFDTransferFunc(),y=r.getDFDFlags(),{transcoderFormat:m,engineFormat:v}=function(t,s,r,u){let h,p;const A=t===a.ETC1S?l:o;for(let n=0;n{delete ti[t],s.destroy()}))),s} /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT diff --git a/dist/xeokit-sdk.min.es.js b/dist/xeokit-sdk.min.es.js index fdd02d392..31162037e 100644 --- a/dist/xeokit-sdk.min.es.js +++ b/dist/xeokit-sdk.min.es.js @@ -1,4 +1,4 @@ -class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e={}){this._id=t.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==e.hideOnMouseDown&&(document.addEventListener("mousedown",(e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),e.items&&(this.items=e.items),this._hideOnAction=!1!==e.hideOnAction,this.context=e.context,this.enabled=!1!==e.enabled,this.hide()}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,n=s.length;e{const a=this._getNextId(),r=new s(a);for(let s=0,a=e.length;s0,c=this._getNextId(),u=s.getTitle||(()=>s.title||""),h=s.doAction||s.callback||(()=>{}),p=s.getEnabled||(()=>!0),A=s.getShown||(()=>!0),d=new i(c,u,h,p,A);if(d.parentMenu=r,l.items.push(d),o){const e=t(n);d.subMenu=e,e.parentItem=d}this._itemList.push(d),this._itemMap[d.id]=d}}return this._menuList.push(r),this._menuMap[r.id]=r,r};this._rootMenu=t(e)}_getNextId(){return"ContextMenu_"+this._id+"_"+this._nextId++}_createUI(){const e=t=>{this._createMenuUI(t);const s=t.groups;for(let t=0,n=s.length;t'),s.push("
    "),t)for(let e=0,n=t.length;e'+o+" [MORE]"):s.push('
  • '+o+"
  • ")}}s.push("
"),s.push("");const n=s.join("");document.body.insertAdjacentHTML("beforeend",n);const i=document.querySelector("."+e.id);e.menuElement=i,i.style["border-radius"]="4px",i.style.display="none",i.style["z-index"]=3e5,i.style.background="white",i.style.border="1px solid black",i.style["box-shadow"]="0 4px 5px 0 gray",i.oncontextmenu=e=>{e.preventDefault()};const a=this;let r=null;if(t)for(let e=0,s=t.length;e{e.preventDefault();const s=t.subMenu;if(!s)return void(r&&(a._hideMenu(r.id),r=null));if(r&&r.id!==s.id&&(a._hideMenu(r.id),r=null),!1===t.enabled)return;const n=t.itemElement,i=s.menuElement,l=n.getBoundingClientRect();i.getBoundingClientRect();l.right+200>window.innerWidth?a._showMenu(s.id,l.left-200,l.top-1):a._showMenu(s.id,l.right-5,l.top-1),r=s})),n||(t.itemElement.addEventListener("click",(e=>{e.preventDefault(),a._context&&!1!==t.enabled&&(t.doAction&&t.doAction(a._context),this._hideOnAction?a.hide():(a._updateItemsTitles(),a._updateItemsEnabledStatus()))})),t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault(),!1!==t.enabled&&t.doHover&&t.doHover(a._context)})))):console.error("ContextMenu item element not found: "+t.id)}}}_updateItemsTitles(){if(this._context)for(let e=0,t=this._itemList.length;ewindow.innerHeight&&(s=window.innerHeight-n),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=s+"px"}_hideMenuElement(e){e.style.display="none"}}class r{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let l=!0,o=l?Float64Array:Float32Array;const c=new o(16),u=new o(16),h=new o(4),p={setDoublePrecisionEnabled(e){l=e,o=l?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>l,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new o(e||2),vec3:e=>new o(e||3),vec4:e=>new o(e||4),mat3:e=>new o(e||9),mat3ToMat4:(e,t=new o(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new o(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new o(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new o(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>p.dotVec4(e,e),lenVec4:e=>Math.sqrt(p.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>p.dotVec3(e,e),sqLenVec2:e=>p.dotVec2(e,e),lenVec3:e=>Math.sqrt(p.sqLenVec3(e)),distVec3:(()=>{const e=new o(3);return(t,s)=>p.lenVec3(p.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(p.sqLenVec2(e)),distVec2:(()=>{const e=new o(2);return(t,s)=>p.lenVec2(p.subVec2(t,s,e))})(),rcpVec3:(e,t)=>p.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/p.lenVec4(e);return p.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/p.lenVec3(e);return p.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/p.lenVec2(e);return p.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=p.dotVec3(e,t)/Math.sqrt(p.sqLenVec3(e)*p.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new o(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=p.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=p.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=p.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||p.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>p.m4s(0),setMat4ToOnes:()=>p.m4s(1),diagonalMat4v:e=>new o([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>p.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>p.diagonalMat4c(e,e,e,e),identityMat4:(e=new o(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new o(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>p.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new o(9));const n=e[0],i=e[3],a=e[6],r=e[1],l=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+l*I+c*v,s[4]=r*d+l*y+c*w,s[7]=r*f+l*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=p.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||p.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||p.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new o(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,p.translationMat4v(e,i))})(),translationMat4s:(e,t)=>p.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>p.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=p.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,h,A,d,f,I;return u=l*o,h=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||p.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*h+d,s[7]=0,s[8]=r*A+f,s[9]=r*h-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>p.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=p.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=p.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new o(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,p.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>p.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=p.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,h=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=h+v,s[2]=A-m,s[3]=0,s[4]=h-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=p.vec4()){const n=p.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],h=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(h,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(h,-1,1)),Math.abs(h)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(h,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(h,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=p.mat4())=>(p.quaternionToRotationMat4(t,n),p.scaleMat4v(s,n),p.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new o(3),t=new o(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=p.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=p.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=p.lenVec3(e);p.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,h=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=h,t[9]*=h,t[10]*=h,p.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=p.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],h=t[1],A=t[2];if(i===u&&a===h&&r===A)return p.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-h,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>p.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=p.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=p.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];p.addVec4(i,n,c),p.subVec4(i,n,u);const a=2*n[2],r=u[0],l=u[1],o=u[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=c[0]/r,s[9]=c[1]/l,s[10]=-c[2]/o,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/o,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=p.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],p.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=p.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=p.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new o(16),t=new o(16),s=new o(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||p.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||p.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=p.vec4()){const n=e[0]*p.DEGTORAD/2,i=e[1]*p.DEGTORAD/2,a=e[2]*p.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),h=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"YXZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"ZXY"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"ZYX"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"YZX"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o-c*u*h):"XZY"===t&&(s[0]=c*l*o-r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o+c*u*h),s},mat4ToQuaternion(e,t=p.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let h;const A=s+r+u;return A>0?(h=.5/Math.sqrt(A+1),t[3]=.25/h,t[0]=(c-l)*h,t[1]=(i-o)*h,t[2]=(a-n)*h):s>r&&s>u?(h=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/h,t[0]=.25*h,t[1]=(n+a)/h,t[2]=(i+o)/h):r>u?(h=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/h,t[0]=(n+a)/h,t[1]=.25*h,t[2]=(l+c)/h):(h=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/h,t[0]=(i+o)/h,t[1]=(l+c)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,s=p.vec4()){const n=Math.sqrt(p.dotVec3(e,e)*p.dotVec3(t,t));let i=n+p.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):p.cross3Vec3(e,t,s),s[3]=i,p.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=p.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new o(16);return(t,s,n)=>(n=n||p.vec3(),p.quaternionToRotationMat4(t,e),p.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=p.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=p.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,h=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+h*-o-A*-l,s[1]=h*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-h*-r,s},quaternionToMat4(e,t){t=p.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,h=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+h,t[2]=f-u,t[4]=d-h,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=p.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>p.normalizeQuaternion(p.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=p.vec4()){const s=(e=p.normalizeQuaternion(e,h))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new o(e||6),AABB2:e=>new o(e||4),OBB3:e=>new o(e||32),OBB2:e=>new o(e||16),Sphere3:(e,t,s,n)=>new o([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new o(3),t=new o(3),s=new o(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],p.subVec3(t,e,s),Math.abs(p.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new o(3),t=new o(3),s=new o(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=p.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],h=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>h?u:h,Math.abs(p.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||p.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||p.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=p.AABB3())=>(e[0]=p.MAX_DOUBLE,e[1]=p.MAX_DOUBLE,e[2]=p.MAX_DOUBLE,e[3]=p.MIN_DOUBLE,e[4]=p.MIN_DOUBLE,e[5]=p.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=p.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new o(3);return(t,s,n)=>{s=s||p.AABB3();let i,a,r,l=p.MAX_DOUBLE,o=p.MAX_DOUBLE,c=p.MAX_DOUBLE,u=p.MIN_DOUBLE,h=p.MIN_DOUBLE,A=p.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>h&&(h=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=h,s[5]=A,s}})(),OBB3ToAABB3(e,t=p.AABB3()){let s,n,i,a=p.MAX_DOUBLE,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE,u=p.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=p.AABB3()){let s,n,i,a=p.MAX_DOUBLE,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE,u=p.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new o(3);return(t,s)=>{s=s||p.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new o(3),t=new o(3);return(s,n)=>{n=n||p.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=h);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new o(3),t=new o(3);return(s,n)=>{n=n||p.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ih&&(h=u);return n[3]=h,n}})(),getSphere3Center:(e,t=p.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=p.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=p.MAX_DOUBLE,e[1]=p.MAX_DOUBLE,e[2]=p.MIN_DOUBLE,e[3]=p.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=p.AABB2()){let s,n,i,a,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=p.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,h=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+h*h+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=h/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3);return(a,r,l,o,c,u)=>{u=u||p.vec3();const h=p.subVec3(o,l,e),A=p.subVec3(c,l,t),d=p.cross3Vec3(r,A,s),f=p.dotVec3(h,d);if(f<1e-6)return null;const I=p.subVec3(a,l,n),y=p.dotVec3(I,d);if(y<0||y>f)return null;const m=p.cross3Vec3(I,h,i),v=p.dotVec3(r,m);if(v<0||y+v>f)return null;const w=p.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new o(3),t=new o(3),s=new o(3),n=new o(3);return(i,a,r,l,o,c)=>{c=c||p.vec3(),a=p.normalizeVec3(a,e);const u=p.subVec3(l,r,t),h=p.subVec3(o,r,s),A=p.cross3Vec3(u,h,n);p.normalizeVec3(A,A);const d=-p.dotVec3(r,A),f=-(p.dotVec3(i,A)+d)/p.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new o(3),t=new o(3),s=new o(3);return(n,i,a,r,l)=>{const o=p.subVec3(r,i,e),c=p.subVec3(a,i,t),u=p.subVec3(n,i,s),h=p.dotVec3(o,o),A=p.dotVec3(o,c),d=p.dotVec3(o,u),f=p.dotVec3(c,c),I=p.dotVec3(c,u),y=h*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(h*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=p.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3),a=new o(3);return(r,l,o)=>{let c,u;const h=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3),a=new o(3),r=new o(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let h=0;h>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,h;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new o(4),t=new o(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,p.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],p.transformVec3(s,e,t),p.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new o(16),t=new o(16),s=new o(4),n=new o(4),i=new o(4),a=new o(4);return(r,l,o,c,u,h)=>{const A=p.mulMat4(o,l,e),d=p.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,p.transformVec4(d,s,n),p.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,p.transformVec4(d,i,a),p.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],p.subVec3(a,n,h),p.normalizeVec3(h)}})(),canvasPosToLocalRay:(()=>{const e=new o(3),t=new o(3);return(s,n,i,a,r,l,o)=>{p.canvasPosToWorldRay(s,n,i,r,e,t),p.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new o(16),t=new o(4),s=new o(4);return(n,i,a,r,l)=>{const o=p.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,p.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],p.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new o(6),l={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return l.triangles=s,l.leaf=!0,l;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),l.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};p.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=p.vec3(),u=p.vec3(),h=p.vec3(),A=p.vec3(),d=p.vec3(),f=p.vec3(),I=p.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class A{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const d={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var f=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{w.removeItem(e.id),delete R.scenes[e.id],delete v[e.id],d.components.scenes--}))},this.clear=function(){let e;for(const t in R.scenes)R.scenes.hasOwnProperty(t)&&(e=R.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete R.scenes[e.id]))},this.scheduleTask=function(e,t){g.push(e),g.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;g.length>0&&(e<0||n0&&b>0){var t=1e3/b;P+=t,E.push(t),E.length>=30&&(P-=E.shift()),d.frame.fps=Math.round(P/E.length)}!function(e){const t=R.runTasks(e+10),s=R.getNumTasks();d.frame.tasksRun=t,d.frame.tasksScheduled=s,d.frame.tasksBudget=10}(e),function(e){for(var t in T.time=e,R.scenes)if(R.scenes.hasOwnProperty(t)){var s=R.scenes[t];T.sceneId=t,T.startTime=s.startTime,T.deltaTime=null!=T.prevTime?T.time-T.prevTime:0,s.fire("tick",T,!0)}T.prevTime=e}(e),function(){const e=R.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=v[r],n||(n=v[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),D=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(C):requestAnimationFrame(C)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(C):requestAnimationFrame(C);class _{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof _))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+m.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(m.isNumeric(s)||m.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+m.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+m.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+m.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():R.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(p.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){Y.set(this._viewPos),Y[3]=1,p.transformPoint4(this.scene.camera.projMatrix,Y,X);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+X[0]/X[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-X[1]/X[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof K?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),S(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class J{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class Z{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class ${constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var ee=p.vec3(),te=p.vec3();class se extends _{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new q(s,t.origin),this._cornerMarker=new q(s,t.corner),this._targetMarker=new q(s,t.target),this._originWorld=p.vec3(),this._cornerWorld=p.vec3(),this._targetWorld=p.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new J(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new J(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new $(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(p.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);p.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,h=t.length;u{switch(a=!0,r=e.entity,l.set(e.worldPos),o.set(e.canvasPos),this._state){case 0:this.markerDiv.style.marginLeft=e.canvasPos[0]-5+"px",this.markerDiv.style.marginTop=e.canvasPos[1]-5+"px",this.markerDiv.style.background="pink",this.markerDiv.style.border="2px solid red";break;case 1:this._currentAngleMeasurement&&(this._currentAngleMeasurement.originWireVisible=!0,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.cornerVisible=!0,this._currentAngleMeasurement.angleVisible=!1,this._currentAngleMeasurement.corner.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer";break;case 2:this._currentAngleMeasurement&&(this._currentAngleMeasurement.targetWireVisible=!0,this._currentAngleMeasurement.targetVisible=!0,this._currentAngleMeasurement.angleVisible=!0,this._currentAngleMeasurement.target.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer"}})),this._onInputMouseDown=i.on("mousedown",(e=>{c=e[0],u=e[1]})),this._onInputMouseUp=i.on("mouseup",(e=>{if(!(e[0]>c+5||e[0]u+5||e[1]{if(a=!1,this.markerDiv.style.marginLeft="-100px",this.markerDiv.style.marginTop="-100px",this._currentAngleMeasurement){switch(this._state){case 0:this._currentAngleMeasurement.originVisible=!1;break;case 1:this._currentAngleMeasurement.cornerVisible=!1,this._currentAngleMeasurement.originWireVisible=!1,this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1;break;case 2:this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1}n.style.cursor="default"}})),n.addEventListener("touchstart",this._onCanvasTouchStart=e=>{const t=e.touches,s=e.changedTouches;1===t.length&&1===s.length&&ie(t[0],h)},{passive:!0}),n.addEventListener("touchend",this._onCanvasTouchEnd=e=>{const s=e.touches,n=e.changedTouches;if(0===s.length&&1===n.length){if(ie(n[0],A),A[0]>h[0]+5||A[0]h[1]+5||A[1]{this.fire("mouseOver",{plugin:this,angleMeasurement:t,measurement:t,event:e})},this._onMouseLeave=(e,t)=>{this.fire("mouseLeave",{plugin:this,angleMeasurement:t,measurement:t,event:e})},this._onContextMenu=(e,t)=>{this.fire("contextMenu",{plugin:this,angleMeasurement:t,measurement:t,event:e})}}getContainerElement(){return this._container}send(e,t){}get control(){return this._control}get measurements(){return this._measurements}createMeasurement(e={}){this.viewer.scene.components[e.id]&&(this.error("Viewer scene component with this ID already exists: "+e.id),delete e.id);const t=e.origin,s=e.corner,n=e.target,i=new se(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},corner:{entity:s.entity,worldPos:s.worldPos},target:{entity:n.entity,worldPos:n.worldPos},visible:e.visible,originVisible:!0,originWireVisible:!0,cornerVisible:!0,targetWireVisible:!0,targetVisible:!0,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[i.id]=i,i.on("destroyed",(()=>{delete this._measurements[i.id]})),this.fire("measurementCreated",i),i}destroyMeasurement(e){const t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("AngleMeasurement not found: "+e)}setLabelsShown(e){for(const[t,s]of Object.entries(this.measurements))s.labelShown=e}clear(){const e=Object.keys(this._measurements);for(var t=0,s=e.length;t{this.plugin.fire("markerClicked",this)}),this._marker.addEventListener("mouseenter",this._onMouseEnterExternalMarker=()=>{this.plugin.fire("markerMouseEnter",this)}),this._marker.addEventListener("mouseleave",this._onMouseLeaveExternalMarker=()=>{this.plugin.fire("markerMouseLeave",this)}),this._markerExternal=!0):(this._markerHTML=t.markerHTML,this._htmlDirty=!0,this._markerExternal=!1),t.labelElement?(this._label=t.labelElement,this._labelExternal=!0):(this._labelHTML=t.labelHTML,this._htmlDirty=!0,this._labelExternal=!1),this._markerShown=!!t.markerShown,this._labelShown=!!t.labelShown,this._values=t.values||{},this._layoutDirty=!0,this._visibilityDirty=!0,this._buildHTML(),this._onTick=this.scene.on("tick",(()=>{this._htmlDirty&&(this._buildHTML(),this._htmlDirty=!1,this._layoutDirty=!0,this._visibilityDirty=!0),(this._layoutDirty||this._visibilityDirty)&&(this._markerShown||this._labelShown)&&(this._updatePosition(),this._layoutDirty=!1),this._visibilityDirty&&(this._marker.style.visibility=this.visible&&this._markerShown?"visible":"hidden",this._label.style.visibility=this.visible&&this._markerShown&&this._labelShown?"visible":"hidden",this._visibilityDirty=!1)})),this.on("canvasPos",(()=>{this._layoutDirty=!0})),this.on("visible",(()=>{this._visibilityDirty=!0})),this.setMarkerShown(!1!==t.markerShown),this.setLabelShown(t.labelShown),this.eye=t.eye?t.eye.slice():null,this.look=t.look?t.look.slice():null,this.up=t.up?t.up.slice():null,this.projection=t.projection}_buildHTML(){if(!this._markerExternal){this._marker&&(this._container.removeChild(this._marker),this._marker=null);let e=this._markerHTML||"

";m.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._marker=t.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(()=>{this.plugin.fire("markerClicked",this)})),this._marker.addEventListener("mouseenter",(()=>{this.plugin.fire("markerMouseEnter",this)})),this._marker.addEventListener("mouseleave",(()=>{this.plugin.fire("markerMouseLeave",this)})),this._marker.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);let e=this._labelHTML||"

";m.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._label=t.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}}_updatePosition(){const e=this.scene.canvas.boundary,t=e[0],s=e[1],n=this.canvasPos;this._marker.style.left=Math.floor(t+n[0])-12+"px",this._marker.style.top=Math.floor(s+n[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+n[0]+20)+"px",this._label.style.top=Math.floor(s+n[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}_renderTemplate(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){const s=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),s)}return e}setMarkerShown(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}getMarkerShown(){return this._markerShown}setLabelShown(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}getLabelShown(){return this._labelShown}setField(e,t){this._values[e]=t||"",this._htmlDirty=!0}getField(e){return this._values[e]}setValues(e){for(var t in e)if(e.hasOwnProperty(t)){const s=e[t];this.setField(t,s)}}getValues(){return this._values}destroy(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),super.destroy()}}const le=p.vec3(),oe=p.vec3(),ce=p.vec3();class ue extends r{constructor(e,t){super("Annotations",e),this._labelHTML=t.labelHTML||"
",this._markerHTML=t.markerHTML||"
",this._container=t.container||document.body,this._values=t.values||{},this.annotations={},this.surfaceOffset=t.surfaceOffset}getContainerElement(){return this._container}send(e,t){if("clearAnnotations"===e)this.clear()}set surfaceOffset(e){null==e&&(e=.3),this._surfaceOffset=e}get surfaceOffset(){return this._surfaceOffset}createAnnotation(e){var t,s;if(this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id),e.pickResult=e.pickResult||e.pickRecord,e.pickResult){const n=e.pickResult;if(n.worldPos&&n.worldNormal){const e=p.normalizeVec3(n.worldNormal,le),i=p.mulVec3Scalar(e,this._surfaceOffset,oe);t=p.addVec3(n.worldPos,i,ce),s=n.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,s=e.entity;var n=null;e.markerElementId&&((n=document.getElementById(e.markerElementId))||this.error("Can't find DOM element for 'markerElementId' value '"+e.markerElementId+"' - defaulting to internally-generated empty DIV"));var i=null;e.labelElementId&&((i=document.getElementById(e.labelElementId))||this.error("Can't find DOM element for 'labelElementId' value '"+e.labelElementId+"' - defaulting to internally-generated empty DIV"));const a=new re(this.viewer.scene,{id:e.id,plugin:this,entity:s,worldPos:t,container:this._container,markerElement:n,labelElement:i,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:m.apply(e.values,m.apply(this._values,{})),markerShown:e.markerShown,labelShown:e.labelShown,eye:e.eye,look:e.look,up:e.up,projection:e.projection,visible:!1!==e.visible});return this.annotations[a.id]=a,a.on("destroyed",(()=>{delete this.annotations[a.id],this.fire("annotationDestroyed",a.id)})),this.fire("annotationCreated",a.id),a}destroyAnnotation(e){var t=this.annotations[e];t?t.destroy():this.log("Annotation not found: "+e)}clear(){const e=Object.keys(this.annotations);for(var t=0,s=e.length;t
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const pe={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},Ae=document.createElement("canvas");if(Ae){const e=Ae.getContext("webgl",{antialias:!0})||Ae.getContext("experimental-webgl",{antialias:!0});pe.WEBGL=!!e,pe.WEBGL&&(pe.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?pe.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?pe.FS_MAX_FLOAT_PRECISION="mediump":pe.FS_MAX_FLOAT_PRECISION="lowp":pe.FS_MAX_FLOAT_PRECISION="mediump",pe.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),pe.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),pe.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),pe.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),pe.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),pe.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),pe.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),pe.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),pe.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),pe.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){pe.SUPPORTED_EXTENSIONS[e]=!0})))}const de=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class fe extends _{constructor(e,t={}){super(e,t),this._backgroundColor=p.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new he(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+p.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function Ee(e){console.error(e.join("\n"))}class be{constructor(e,t){this.id=ge.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new me(e,e.VERTEX_SHADER,Te(this.source.vertex)),this._fragmentShader=new me(e,e.FRAGMENT_SHADER,Te(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void Ee(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void Ee(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void Ee(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void Ee(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void Ee(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;sthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}class Pe{constructor(e,t){this.scene=e,this.aabb=p.AABB3(),this.origin=p.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}_buildMarkerList(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}_buildPositions(){let e=0;for(let t=0;t-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Pe(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Pe(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new be(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=p.mat4();return()=>(e&&p.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,h=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Be[0]=a,Be[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,h),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Be),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new be(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new De(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new De(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const Se=new Float32Array(He(17,[0,1])),Ne=new Float32Array(He(17,[1,0])),xe=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Fe(n,t));return s}(17,4)),Le=new Float32Array(2);class Me{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new be(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new De(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new De(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new De(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=p.mat4();return()=>(e&&p.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Le[0]=r,Le[1]=l,n.uniform2fv(this._uViewport,Le),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,Ne):n.uniform2fv(this._uSampleOffsets,Se),n.uniform1fv(this._uSampleWeights,xe);const h=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,h,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Fe(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function He(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Ue{constructor(e,t,s){s=s||{},this.gl=t,this.allocated=!1,this.canvas=e,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}setSize(e){this.size=e}webglContextRestored(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}bind(e=null){if(this._touch(e),this.bound)return;const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}_touch(e=null){let t,s;const n=this.gl;if(this.size?(t=this.size[0],s=this.size[1]):(t=n.drawingBufferWidth,s=n.drawingBufferHeight),this.buffer){if(this.buffer.width===t&&this.buffer.height===s)return;n.deleteTexture(this.buffer.texture),n.deleteFramebuffer(this.buffer.framebuf),n.deleteRenderbuffer(this.buffer.renderbuf)}const i=n.createTexture();let a;n.bindTexture(n.TEXTURE_2D,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),e?n.texStorage2D(n.TEXTURE_2D,1,e,t,s):n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,s,0,n.RGBA,n.UNSIGNED_BYTE,null),this._hasDepthTexture&&(a=n.createTexture(),n.bindTexture(n.TEXTURE_2D,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.DEPTH_COMPONENT32F,t,s,0,n.DEPTH_COMPONENT,n.FLOAT,null));const r=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT32F,t,s);const l=n.createFramebuffer();if(n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,i,0),this._hasDepthTexture?n.framebufferTexture2D(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.TEXTURE_2D,a,0):n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,r),n.bindTexture(n.TEXTURE_2D,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,l),!n.isFramebuffer(l))throw"Invalid framebuffer";n.bindFramebuffer(n.FRAMEBUFFER,null);const o=n.checkFramebufferStatus(n.FRAMEBUFFER);switch(o){case n.FRAMEBUFFER_COMPLETE:break;case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case n.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+o}this.buffer={framebuf:l,renderbuf:r,texture:i,depthTexture:a,width:t,height:s},this.bound=!1}clear(){if(!this.bound)throw"Render buffer not bound";const e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}read(e,t,s=null,n=null,i=Uint8Array,a=4){const r=e,l=(this.buffer.height||this.gl.drawingBufferHeight)-t,o=new i(a),c=this.gl;return c.readPixels(r,l,1,1,s||c.RGBA,n||c.UNSIGNED_BYTE,o,0),o}readArray(e=null,t=null,s=Uint8Array,n=4){const i=new s(this.buffer.width*this.buffer.height*n),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}readImageAsCanvas(){const e=this.gl,t=this._getImageDataCache(),s=t.pixelData,n=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,s);const r=this.buffer.width,l=this.buffer.height,o=l/2|0,c=4*r,u=new Uint8Array(4*r);for(let e=0;eT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class ke{constructor(e,t,s,n,i=null,a=0){this.model=e,this.object=null,this.parent=null,this.id=t,this.aabb=null,this.layer=i,this.portionId=a,this._color=[s[0],s[1],s[2],n],this._colorize=[s[0],s[1],s[2],n],this._colorizing=!1,this._transparent=n<255,this.numTriangles=0,this.origin=null}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const s=e<255,n=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),n&&this.layer.setTransparent(this.portionId,t,s)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,s,n){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,s,n)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex(this.portionId,e)}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const Qe=new class{constructor(){this._uint8Arrays={},this._float32Arrays={}}_clear(){this._uint8Arrays={},this._float32Arrays={}}getUInt8Array(e){let t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}getFloat32Array(e){let t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}};let We=0;const ze={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},Ke=new e({});class Ye{constructor(e){this.id=Ke.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Ke.removeItem(this.id)}}const Xe=function(){const e=p.mat4(),t=p.mat4();return function(s,n){n=n||p.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return p.identityMat4(e),p.translationMat4v(s,e),p.identityMat4(t),p.scalingMat4v([l/u,o/u,c/u],t),p.mulMat4(e,t,n),n}}();var qe=function(){const e=p.mat4(),t=p.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function $e(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function et(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const tt={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=Ze(e,l,"floor","ceil"),n=$e(s),a=et(e,l,n),a>r&&(i=s,r=a),s=Ze(e,l,"ceil","ceil"),n=$e(s),a=et(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},st=new Float32Array([1,1,1,1]),nt=new Float32Array([0,0,0,1]),it=p.vec4(),at=p.vec3();class rt{constructor(e,t=!1,{instancing:s=!1,edges:n=!1}={}){this._scene=e,this._withSAO=t,this._instancing=s,this._edges=n,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}_getHash(){return this._scene._sectionPlanesState.getHash()}_buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}_buildVertexShader(){return[""]}_buildFragmentShader(){return[""]}_addMatricesUniformBlockLines(e,t=!1){return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}getValid(){return this._hash===this._getHash()}setSectionPlanesStateUniforms(e){const t=this._scene,{gl:s}=t.canvas,{model:n,layerIndex:i}=e,a=t._sectionPlanesState.sectionPlanes.length;if(a>0){const r=t._sectionPlanesState.sectionPlanes,l=i*a,o=n.renderFlags;for(let t=0;t0&&(this._uReflectionMap="reflectionMap"),s.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(let t=0,s=e._sectionPlanesState.sectionPlanes.length;t0&&d.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,d.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),d.lightMaps.length>0&&d.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,d.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),this._withSAO){const t=r.sao;if(t.possible){const s=l.drawingBufferWidth,n=l.drawingBufferHeight;it[0]=s,it[1]=n,it[2]=t.blendCutoff,it[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,it),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++}}if(n){const e=this._edges?"edgeColor":"fillColor",t=this._edges?"edgeAlpha":"fillAlpha";if(s===ze[(this._edges?"EDGES":"SILHOUETTE")+"_XRAYED"]){const s=r.xrayMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===ze[(this._edges?"EDGES":"SILHOUETTE")+"_HIGHLIGHTED"]){const s=r.highlightMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===ze[(this._edges?"EDGES":"SILHOUETTE")+"_SELECTED"]){const s=r.selectedMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else l.uniform4fv(this._uColor,this._edges?nt:st)}this._draw({geometry:h,state:o,frameCtx:e,incrementDrawState:i}),l.bindVertexArray(null)}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null,d.memory.programs--}}class lt extends rt{constructor(e,t,{instancing:s=!1,edges:n=!1}={}){super(e,t,{instancing:s,edges:n})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;if(this._edges)t.drawElements(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0);else{const e=n.pickElementsCount||s.indicesBuf.numItems,a=n.pickElementsOffset?n.pickElementsOffset*s.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,e,s.indicesBuf.itemType,a),i&&n.drawElements++}}}class ot extends lt{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class ct extends rt{constructor(e,t,{edges:s=!1}={}){super(e,t,{instancing:!0,edges:s})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,geometry:i,incrementDrawState:a}=e;this._edges?t.drawElementsInstanced(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances):(t.drawElementsInstanced(t.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),a&&n.drawElements++)}}class ut extends ct{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class ht extends rt{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArrays(t.POINTS,0,s.positionsBuf.numItems),i&&n.drawArrays++}}class pt extends rt{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,geometry:i,incrementDrawState:a}=e;t.drawArraysInstanced(t.POINTS,0,s.positionsBuf.numItems,s.numInstances),a&&n.drawArrays++}}class At extends rt{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElements(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0),i&&n.drawElements++}}class dt extends rt{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,geometry:n,frameCtx:i,incrementDrawState:a}=e;t.drawElementsInstanced(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),a&&i.drawElements++}}class ft extends lt{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i;const a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class It extends lt{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching flat-shading draw vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._lightsState,s=e._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),n){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,s=t.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}class mt extends ot{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class vt extends ot{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class wt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class gt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Tt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec3 worldNormal = octDecode(normal.xy); "),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class Et extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class bt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching depth fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}class Dt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Pt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry shadow vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push(" int colorFlag = int(flags) & 0xF;"),s.push(" bool visible = (colorFlag > 0);"),s.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push(" if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry shadow fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = encodeFloat( gl_FragCoord.z); "),s.push("}"),s}}class Rt extends lt{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Triangles batching quality draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),r.push("uniform sampler2D uAOMap;"),r.push("in vec4 vViewPosition;"),r.push("in vec3 vViewNormal;"),r.push("in vec4 vColor;"),r.push("in vec2 vUV;"),r.push("in vec2 vMetallicRoughness;"),n.lightMaps.length>0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick flat normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out float vFlags;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags = flags;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick flat normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class _t extends lt{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching color texture vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._lightsState,n=e._sectionPlanesState,i=n.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(let e=0,t=n.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(let e=0,t=n.sectionPlanes.length;e 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,t=s.lights.length;e5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]}}const Nt=p.mat4(),xt=p.mat4();function Lt(e,t,s){const n=e.length,i=new Uint16Array(n),a=t[0],r=t[1],l=t[2],o=t[3]-a,c=t[4]-r,u=t[5]-l,h=65525,A=h/o,d=h/c,f=h/u,I=e=>e>=0?e:0;for(let t=0;t=0?1:-1),t=(1-Math.abs(n))*(i>=0?1:-1),n=e,i=t}return new Int8Array([Math[t](127.5*n+(n<0?-1:0)),Math[s](127.5*i+(i<0?-1:0))])}function Ht(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}const Ut=p.vec3();class Gt{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;let c=a.eye;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];const u=t.aabb,h=[p.safeInv(u[3]-u[0])*p.MAX_INT,p.safeInv(u[4]-u[1])*p.MAX_INT,p.safeInv(u[5]-u[2])*p.MAX_INT];if(e._coordinateScale[0]=p.safeInv(h[0]),e._coordinateScale[1]=p.safeInv(h[1]),e._coordinateScale[2]=p.safeInv(h[2]),!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),e.pickViewMatrix&&(c=e.pickOrigin||c);const A=[c[0]-o[0],c[1]-o[1],c[2]-o[2]];r.uniform3fv(this._uCameraEyeRtc,A),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.layerNumber),r.uniform3fv(this._uCoordinateScaler,h),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform1i(this._uSolid,t.solid);const d=e.pickViewMatrix||a.viewMatrix,f=o?O(d,o):d;if(r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,a=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),s.push("uniform bool solid;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Vt=p.vec3();class jt{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];const c=t.aabb,u=[p.safeInv(c[3]-c[0])*p.MAX_INT,p.safeInv(c[4]-c[1])*p.MAX_INT,p.safeInv(c[5]-c[2])*p.MAX_INT];if(e._coordinateScale[0]=p.safeInv(u[0]),e._coordinateScale[1]=p.safeInv(u[1]),e._coordinateScale[2]=p.safeInv(u[2]),!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());let h=a.eye;e.pickViewMatrix&&(h=e.pickOrigin||h);const A=[h[0]-o[0],h[1]-o[1],h[2]-o[2]];r.uniform3fv(this._uCameraEyeRtc,A),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.layerNumber),r.uniform3fv(this._uCoordinateScaler,u),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);const d=e.pickViewMatrix||a.viewMatrix,f=o?O(d,o):d;if(r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,a=n.renderFlags;for(let t=0;t0;e.pointsMaterial._state;const s=[];return s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class kt{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Gt(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new jt(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Qt={};const Wt=p.mat4(),zt=p.mat4(),Kt=p.vec4([0,0,0,1]),Yt=p.vec4([0,0,0,1]),Xt=p.vec4([0,0,0,1]),qt=p.OBB3(),Jt=p.vec3(),Zt=p.vec3(),$t=p.vec3(),es=p.vec3(),ts=p.vec3(),ss=p.vec3(),ns=p.vec3();class is{constructor(e){console.log("Creating TrianglesBatchingLayer"),this.model=e.model,this.sortId="TrianglesBatchingLayer"+(e.solid?"-solid":"-surface")+(e.autoNormals?"-autonormals":"-normals")+(e.textureSet&&e.textureSet.colorTexture?"-colorTexture":"")+(e.textureSet&&e.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=Ot[t];return s||(s=new Bt(e),Ot[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Ot[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=Qt[t];return s||(s=new kt(e),Qt[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Qt[t],s._destroy()}))),s}(e.model.scene),this._buffer=new St(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ye({origin:p.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:e.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=p.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=p.mat4(e.positionsDecodeMatrix)),e.uvDecodeMatrix?(this._state.uvDecodeMatrix=p.mat3(e.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,e.origin&&this._state.origin.set(e.origin),this.aabb=p.collapseAABB3(),this.solid=!!e.solid}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(let e=0,t=i.length;e0){const e=Wt;I?p.inverseMat4(p.transposeMat4(I,zt),e):p.identityMat4(e,e),function(e,t,s,n,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let r,l,o,c,u,h,A=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(h=0;hu&&(o=r,u=c),r=Ft(d,"floor","ceil"),l=Ht(r),c=a(d,l),c>u&&(o=r,u=c),r=Ft(d,"ceil","ceil"),l=Ht(r),c=a(d,l),c>u&&(o=r,u=c),n[i+h+0]=o[0],n[i+h+1]=o[1],n[i+h+2]=0}(e,n,n.length,g.normals,g.normals.length)}if(l)for(let e=0,t=l.length;e0)for(let e=0,t=a.length;e0)for(let e=0,t=r.length;e0){const n=this._state.positionsDecodeMatrix?new Uint16Array(s.positions):Lt(s.positions,this._modelAABB,this._state.positionsDecodeMatrix=p.mat4());if(e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(let e=0,t=this._portions.length;e0){const n=new Int8Array(s.normals);let i=!0;e.normalsBuf=new De(t,t.ARRAY_BUFFER,n,s.normals.length,3,t.STATIC_DRAW,i)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new De(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.uv.length>0)if(e.uvDecodeMatrix){let n=!1;e.uvBuf=new De(t,t.ARRAY_BUFFER,s.uv,s.uv.length,2,t.STATIC_DRAW,n)}else{const n=tt.getUVBounds(s.uv),i=tt.compressUVs(s.uv,n.min,n.max),a=i.quantized;let r=!1;e.uvDecodeMatrix=p.mat3(i.decodeMatrix),e.uvBuf=new De(t,t.ARRAY_BUFFER,a,a.length,2,t.STATIC_DRAW,r)}if(s.metallicRoughness.length>0){const n=new Uint8Array(s.metallicRoughness);let i=!1;e.metallicRoughnessBuf=new De(t,t.ARRAY_BUFFER,n,s.metallicRoughness.length,2,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n),a=!1;e.flagsBuf=new De(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new De(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new De(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}if(s.edgeIndices.length>0){const n=new Uint32Array(s.edgeIndices);e.edgeIndicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,n,s.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}isEmpty(){return!this._state.indicesBuf}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=e,n=this._portions[s],i=4*n.vertsBaseIndex,a=4*n.numVerts,r=this._scratchMemory.getUInt8Array(a),l=t[0],o=t[1],c=t[2],u=t[3];for(let e=0;em)&&(m=e,n.set(v),i&&p.triangleNormal(d,f,I,i),y=!0)}}return y&&i&&(p.transformVec3(this.model.worldNormalMatrix,i,i),p.normalizeVec3(i)),y}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}class as extends ct{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i,a,r;const l=[];for(l.push("#version 300 es"),l.push("// Instancing geometry drawing vertex shader"),l.push("uniform int renderPass;"),l.push("in vec3 position;"),l.push("in vec2 normal;"),l.push("in vec4 color;"),l.push("in float flags;"),e.entityOffsetsEnabled&&l.push("in vec3 offset;"),l.push("in vec4 modelMatrixCol0;"),l.push("in vec4 modelMatrixCol1;"),l.push("in vec4 modelMatrixCol2;"),l.push("in vec4 modelNormalMatrixCol0;"),l.push("in vec4 modelNormalMatrixCol1;"),l.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(l,!0),e.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;")),l.push("uniform vec4 lightAmbient;"),i=0,a=s.lights.length;i= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"),n&&(l.push("out vec4 vWorldPosition;"),l.push("out float vFlags;")),l.push("out vec4 vColor;"),l.push("void main(void) {"),l.push("int colorFlag = int(flags) & 0xF;"),l.push("if (colorFlag != renderPass) {"),l.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),l.push("} else {"),l.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),l.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&l.push(" worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix * worldPosition; "),l.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),l.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),l.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),i=0,a=s.lights.length;i0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class rs extends ct{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState;let n,i;const a=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry flat-shading drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),a){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}for(r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),n=0,i=s.lights.length;n0,s=[];return s.push("#version 300 es"),s.push("// Instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing fill fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class os extends ut{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class cs extends ut{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class us extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class hs extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class ps extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec2 normal;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("in vec4 modelNormalMatrixCol0;"),s.push("in vec4 modelNormalMatrixCol1;"),s.push("in vec4 modelNormalMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class As extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("in float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class ds extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}class fs extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Is extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}const ys=1e3,ms=1001,vs=1002,ws=1003,gs=1004,Ts=1004,Es=1005,bs=1005,Ds=1006,Ps=1007,Rs=1007,Cs=1008,_s=1008,Bs=1009,Os=1010,Ss=1011,Ns=1012,xs=1013,Ls=1014,Ms=1015,Fs=1016,Hs=1017,Us=1018,Gs=1020,Vs=1021,js=1022,ks=1023,Qs=1024,Ws=1025,zs=1026,Ks=1027,Ys=1028,Xs=1029,qs=1030,Js=1031,Zs=1033,$s=33776,en=33777,tn=33778,sn=33779,nn=35840,an=35841,rn=35842,ln=35843,on=36196,cn=37492,un=37496,hn=37808,pn=37809,An=37810,dn=37811,fn=37812,In=37813,yn=37814,mn=37815,vn=37816,wn=37817,gn=37818,Tn=37819,En=37820,bn=37821,Dn=36492,Pn=3e3,Rn=3001,Cn=1e4,_n=10001,Bn=10002,On=10003,Sn={3e3:"linearToLinear",3001:"sRGBToLinear"};class Nn extends ct{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Instancing geometry quality drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),r.push("#define PI 3.14159265359"),r.push("#define RECIPROCAL_PI 0.31830988618"),r.push("#define RECIPROCAL_PI2 0.15915494"),r.push("#define EPSILON 1e-6"),r.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),r.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),r.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),r.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),r.push(" return normalize(surf_norm );"),r.push(" }"),r.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),r.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),r.push(" vec2 st0 = dFdx( uv.st );"),r.push(" vec2 st1 = dFdy( uv.st );"),r.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),r.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),r.push(" vec3 N = normalize( surf_norm );"),r.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),r.push(" mat3 tsn = mat3( S, T, N );"),r.push(" return normalize( tsn * mapN );"),r.push("}"),r.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),r.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),r.push("}"),r.push("struct IncidentLight {"),r.push(" vec3 color;"),r.push(" vec3 direction;"),r.push("};"),r.push("struct ReflectedLight {"),r.push(" vec3 diffuse;"),r.push(" vec3 specular;"),r.push("};"),r.push("struct Geometry {"),r.push(" vec3 position;"),r.push(" vec3 viewNormal;"),r.push(" vec3 worldNormal;"),r.push(" vec3 viewEyeDir;"),r.push("};"),r.push("struct Material {"),r.push(" vec3 diffuseColor;"),r.push(" float specularRoughness;"),r.push(" vec3 specularColor;"),r.push(" float shine;"),r.push("};"),r.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),r.push(" float r = ggxRoughness + 0.0001;"),r.push(" return (2.0 / (r * r) - 2.0);"),r.push("}"),r.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),r.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),r.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),r.push("}"),n.reflectionMaps.length>0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = "+Sn[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = "+Sn[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&s.push("out float vFlags;"),s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&s.push("vFlags = flags;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class Ln extends ct{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState;let i,a;const r=s.sectionPlanes.length>0,l=[];if(l.push("#version 300 es"),l.push("// Instancing geometry drawing fragment shader"),l.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),l.push("precision highp float;"),l.push("precision highp int;"),l.push("#else"),l.push("precision mediump float;"),l.push("precision mediump int;"),l.push("#endif"),e.logarithmicDepthBufferEnabled&&(l.push("in float isPerspective;"),l.push("uniform float logDepthBufFC;"),l.push("in float vFragDepth;")),l.push("uniform sampler2D uColorMap;"),this._withSAO&&(l.push("uniform sampler2D uOcclusionTexture;"),l.push("uniform vec4 uSAOParams;"),l.push("const float packUpscale = 256. / 255.;"),l.push("const float unpackDownScale = 255. / 256.;"),l.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),l.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),l.push("float unpackRGBToFloat( const in vec4 v ) {"),l.push(" return dot( v, unPackFactors );"),l.push("}")),l.push("uniform float gammaFactor;"),l.push("vec4 linearToLinear( in vec4 value ) {"),l.push(" return value;"),l.push("}"),l.push("vec4 sRGBToLinear( in vec4 value ) {"),l.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),l.push("}"),l.push("vec4 gammaToLinear( in vec4 value) {"),l.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),l.push("}"),t&&(l.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),l.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),l.push("}")),r){l.push("in vec4 vWorldPosition;"),l.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),l.push(" if (clippable) {"),l.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),l.push(" discard;"),l.push(" }"),l.push("}")}for(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),l.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),l.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),l.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),i=0,a=n.lights.length;i0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// Points instancing snap vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Gn=p.vec3();class Vn{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.canvas.gl,r=t._state,l=t._state.origin,o=r.geometry;e._origin[0]=l[0],e._origin[1]=l[1],e._origin[2]=l[2];const c=t.aabb,u=[p.safeInv(c[3]-c[0])*p.MAX_INT,p.safeInv(c[4]-c[1])*p.MAX_INT,p.safeInv(c[5]-c[2])*p.MAX_INT];if(e._coordinateScale[0]=p.safeInv(u[0]),e._coordinateScale[1]=p.safeInv(u[1]),e._coordinateScale[2]=p.safeInv(u[2]),!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const h=i.camera;let A=h.eye;e.pickViewMatrix&&(A=e.pickOrigin||A);const d=[A[0]-l[0],A[1]-l[1],A[2]-l[2]];a.uniform3fv(this._uCameraEyeRtc,d),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.layerNumber),a.uniform3fv(this._uCoordinateScaler,u),a.uniform1i(this._uRenderPass,s),a.uniform1i(this._uPickInvisible,e.pickInvisible);const f=e.pickViewMatrix||h.viewMatrix,I=l?O(f,l):f;if(a.uniformMatrix4fv(this._uViewMatrix,!1,I),a.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,h.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,t)}const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// Points instancing snap vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class jn{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Un(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Vn(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const kn={};const Qn=new Uint8Array(4),Wn=new Float32Array(1),zn=p.vec4([0,0,0,1]),Kn=p.vec4([0,0,0,1]),Yn=p.vec4([0,0,0,1]),Xn=new Float32Array(3),qn=p.vec3(),Jn=p.vec3(),Zn=p.vec3(),$n=p.vec3(),ei=p.vec3(),ti=p.vec3(),si=p.vec3();class ni{constructor(e){console.log("Creating TrianglesInstancingLayer"),this.model=e.model,this.sortId="TrianglesInstancingLayer"+(e.solid?"-solid":"-surface")+(e.normals?"-normals":"-autoNormals"),this.layerIndex=e.layerIndex,this._instancingRenderers=function(e){const t=e.id;let s=Fn[t];return s||(s=new Mn(e),Fn[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Fn[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=kn[t];return s||(s=new jn(e),kn[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete kn[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new Ye({numInstances:0,obb:p.OBB3(),origin:p.vec3(),geometry:e.geometry,textureSet:e.textureSet,pbrSupported:!1,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],e.origin&&this._state.origin.set(e.origin),this._finalized=!1,this.aabb=p.collapseAABB3(),this.solid=!!e.solid,this.numIndices=e.geometry.numIndices}createPortion(e){const t=e.color,s=e.metallic,n=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,r=e.sceneModelMatrix,l=e.aabb,o=e.pickColor;if(this._finalized)throw"Already finalized";const c=t[0],u=t[1],h=t[2];if(this._colors.push(c),this._colors.push(u),this._colors.push(h),this._colors.push(i),this._metallicRoughness.push(null!=s?s:0),this._metallicRoughness.push(null!=n?n:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){let e=p.transposeMat4(a,p.mat4()),t=p.inverseMat4(e);this._modelNormalMatrixCol0.push(t[0]),this._modelNormalMatrixCol0.push(t[4]),this._modelNormalMatrixCol0.push(t[8]),this._modelNormalMatrixCol0.push(t[12]),this._modelNormalMatrixCol1.push(t[1]),this._modelNormalMatrixCol1.push(t[5]),this._modelNormalMatrixCol1.push(t[9]),this._modelNormalMatrixCol1.push(t[13]),this._modelNormalMatrixCol2.push(t[2]),this._modelNormalMatrixCol2.push(t[6]),this._modelNormalMatrixCol2.push(t[10]),this._modelNormalMatrixCol2.push(t[14])}this._pickColors.push(o[0]),this._pickColors.push(o[1]),this._pickColors.push(o[2]),this._pickColors.push(o[3]);const A=this._state.geometry.positionsCompressed.length,d=this._state.geometry.positionsCompressed,f=this._state.geometry.positionsDecodeMatrix;for(let e=0;e0){let t=!1;e.colorsBuf=new De(n,n.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,n.DYNAMIC_DRAW,t),this._colors=[]}if(this._metallicRoughness.length>0){const t=new Uint8Array(this._metallicRoughness);let s=!1;e.metallicRoughnessBuf=new De(n,n.ARRAY_BUFFER,t,this._metallicRoughness.length,2,n.STATIC_DRAW,s)}if(a>0){let t=!1;e.flagsBuf=new De(n,n.ARRAY_BUFFER,new Float32Array(a),a,1,n.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;e.offsetsBuf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,n.DYNAMIC_DRAW,t),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){const s=!1;e.positionsBuf=new De(n,n.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,n.STATIC_DRAW,s),e.positionsDecodeMatrix=p.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){const s=new Uint8Array(t.colorsCompressed),i=!1;e.colorsBuf=new De(n,n.ARRAY_BUFFER,s,s.length,4,n.STATIC_DRAW,i)}if(t.uvCompressed&&t.uvCompressed.length>0){const s=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new De(n,n.ARRAY_BUFFER,s,s.length,2,n.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new De(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,n.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new De(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,n.STATIC_DRAW)),this._modelMatrixCol0.length>0){const t=!1;e.modelMatrixCol0Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelMatrixCol1Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelMatrixCol2Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol1Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol2Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){const t=!1;e.pickColorsBuf=new De(n,n.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,n.STATIC_DRAW,t),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&s&&s.colorTexture&&s.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!s&&!!s.colorTexture,this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Qn[0]=t[0],Qn[1]=t[1],Qn[2]=t[2],Qn[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Qn,4*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&M),i=!!(t&V),a=!!(t&j),r=!!(t&k),l=!!(t&Q),o=!!(t&H),c=!!(t&F);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?ze.NOT_RENDERED:s?ze.COLOR_TRANSPARENT:ze.COLOR_OPAQUE,h=!n||c?ze.NOT_RENDERED:r?ze.SILHOUETTE_SELECTED:a?ze.SILHOUETTE_HIGHLIGHTED:i?ze.SILHOUETTE_XRAYED:ze.NOT_RENDERED;let p=0;p=!n||c?ze.NOT_RENDERED:r?ze.EDGES_SELECTED:a?ze.EDGES_HIGHLIGHTED:i?ze.EDGES_XRAYED:l?s?ze.EDGES_COLOR_TRANSPARENT:ze.EDGES_COLOR_OPAQUE:ze.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?ze.PICK:ze.NOT_RENDERED)<<12,A|=(t&U?1:0)<<16,Wn[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Wn,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Xn[0]=t[0],Xn[1]=t[1],Xn[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Xn,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}getEachVertex(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;const s=this._state,n=s.geometry,i=this._portions[e];if(!i)return void this.model.error("portion not found: "+e);const a=n.quantizedPositions,r=s.origin,l=i.offset,o=r[0]+l[0],c=r[1]+l[1],u=r[2]+l[2],h=zn,A=i.matrix,d=this.model.sceneModelMatrix,f=s.positionsDecodeMatrix;for(let e=0,s=a.length;ev)&&(v=e,n.set(w),i&&p.triangleNormal(f,I,y,i),m=!0)}}return m&&i&&(p.transformVec3(l.normalMatrix,i,i),p.transformVec3(this.model.worldNormalMatrix,i,i),p.normalizeVec3(i)),m}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}class ii extends At{drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class ai extends At{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class ri{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new ii(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ai(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const li={};class oi{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const ci=p.vec4([0,0,0,1]),ui=p.vec4([0,0,0,1]),hi=p.vec4([0,0,0,1]),pi=p.OBB3();class Ai{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=li[t];return s||(s=new ri(e),li[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete li[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new oi(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ye({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:p.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=p.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=p.vec3(e.origin)),this.aabb=p.collapseAABB3()}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Lt(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new De(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.colors.length>0){const n=s.colors.length/4,i=new Float32Array(n);let a=!1;e.flagsBuf=new De(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new De(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2],c=t[3];for(let e=0;e0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 lightAmbient;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class fi extends dt{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 color;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class Ii{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new di(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new fi(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const yi={};const mi=new Uint8Array(4),vi=new Float32Array(1),wi=p.vec4([0,0,0,1]),gi=p.vec4([0,0,0,1]),Ti=p.vec4([0,0,0,1]),Ei=new Float32Array(3);class bi{constructor(e){this.model=e.model,this.material=e.material,this.sortId="LinesInstancingLayer",this.layerIndex=e.layerIndex,this._linesInstancingRenderers=function(e){const t=e.id;let s=yi[t];return s||(s=new Ii(e),yi[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete yi[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new Ye({obb:p.OBB3(),numInstances:0,origin:null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],e.origin&&(this._state.origin=p.vec3(e.origin)),this._finalized=!1,this.aabb=p.collapseAABB3()}createPortion(e){const t=e.color,s=e.opacity,n=e.meshMatrix,i=e.worldMatrix,a=e.aabb;if(this._finalized)throw"Already finalized";const r=t[0],l=t[1],o=t[2];t[3],this._colors.push(r),this._colors.push(l),this._colors.push(o),this._colors.push(s),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(n[0]),this._modelMatrixCol0.push(n[4]),this._modelMatrixCol0.push(n[8]),this._modelMatrixCol0.push(n[12]),this._modelMatrixCol1.push(n[1]),this._modelMatrixCol1.push(n[5]),this._modelMatrixCol1.push(n[9]),this._modelMatrixCol1.push(n[13]),this._modelMatrixCol2.push(n[2]),this._modelMatrixCol2.push(n[6]),this._modelMatrixCol2.push(n[10]),this._modelMatrixCol2.push(n[14]),p.collapseAABB3(a);const c=this._state.obb,u=c.length;for(let e=0;e0){let t=!1;this._state.colorsBuf=new De(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,t),this._colors=[]}if(s>0){let t=!1;this._state.flagsBuf=new De(e,e.ARRAY_BUFFER,new Float32Array(s),s,1,e.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";mi[0]=t[0],mi[1]=t[1],mi[2]=t[2],mi[3]=t[3],this._state.colorsBuf.setData(mi,4*e,4)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&M),i=!!(t&V),a=!!(t&j),r=!!(t&k),l=!!(t&Q),o=!!(t&H),c=!!(t&F);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?ze.NOT_RENDERED:s?ze.COLOR_TRANSPARENT:ze.COLOR_OPAQUE,h=!n||c?ze.NOT_RENDERED:r?ze.SILHOUETTE_SELECTED:a?ze.SILHOUETTE_HIGHLIGHTED:i?ze.SILHOUETTE_XRAYED:ze.NOT_RENDERED;let p=0;p=!n||c?ze.NOT_RENDERED:r?ze.EDGES_SELECTED:a?ze.EDGES_HIGHLIGHTED:i?ze.EDGES_XRAYED:l?s?ze.EDGES_COLOR_TRANSPARENT:ze.EDGES_COLOR_OPAQUE:ze.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?ze.PICK:ze.NOT_RENDERED)<<12,A|=(t&U?255:0)<<16,vi[0]=A,this._state.flagsBuf.setData(vi,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ei[0]=t[0],Ei[1]=t[1],Ei[2]=t[2],this._state.offsetsBuf.setData(Ei,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,ze.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,ze.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesXRayed(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawOcclusion(e,t){}drawShadow(e,t){}drawPickMesh(e,t){}drawPickDepths(e,t){}drawPickNormals(e,t){}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}class Di extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial,n=[];return n.push("#version 300 es"),n.push("// Points batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Pi extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}class Ri extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class Ci extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batched pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batched pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class _i extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push(" gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class Bi{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Di(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Pi(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Ri(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Ci(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new _i(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const Oi={};class Si{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]}}const Ni=p.vec4(),xi=p.vec4(),Li=p.vec4([0,0,0,1]),Mi=p.vec4([0,0,0,1]),Fi=p.vec4([0,0,0,1]),Hi=p.OBB3();class Ui{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=Oi[t];return s||(s=new Bi(e),Oi[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Oi[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Si(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ye({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:p.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=p.collapseAABB3(),this._portions=[],this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=p.vec3(e.origin)),this.aabb=p.collapseAABB3()}canCreatePortion(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}createPortion(e){if(this._finalized)throw"Already finalized";const t=e.positions,s=e.positionsCompressed,n=e.color,i=e.colorsCompressed,a=e.colors,r=e.meshMatrix,l=e.worldMatrix,o=e.worldAABB,c=e.pickColor,u=this._buffer,h=u.positions.length/3;let A;if(this._preCompressedPositionsExpected){if(!s)throw"positionsCompressed expected";for(let e=0,t=s.length;e0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Lt(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new De(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n);let a=!1;e.flagsBuf=new De(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new De(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new De(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized"}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2];for(let e=0;e0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Vi extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 silhouetteColor;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class ji extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick mesh fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class ki extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Qi extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Wi extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class zi extends pt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("gl_PointSize = pointSize;"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }"),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Ki{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Gi(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Vi(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Wi(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new ji(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new ki(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Qi(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new zi(this._scene)),this._shadowRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}const Yi={};const Xi=new Uint8Array(4),qi=new Float32Array(1),Ji=p.vec4([0,0,0,1]),Zi=p.vec4([0,0,0,1]),$i=p.vec4([0,0,0,1]),ea=new Float32Array(3);class ta{constructor(e){this.model=e.model,this.material=e.material,this.sortId="PointsInstancingLayer",this.layerIndex=e.layerIndex,this._pointsInstancingRenderers=function(e){const t=e.id;let s=Yi[t];return s||(s=new Ki(e),Yi[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Yi[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new Ye({obb:p.OBB3(),numInstances:0,origin:e.origin?p.vec3(e.origin):null,geometry:e.geometry,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=p.collapseAABB3()}createPortion(e){const t=e.meshMatrix,s=e.worldMatrix,n=e.aabb,i=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(i[0]),this._pickColors.push(i[1]),this._pickColors.push(i[2]),this._pickColors.push(i[3]),p.collapseAABB3(n);const a=this._state.obb,r=a.length;for(let e=0;e0){let s=!1;this._state.flagsBuf=new De(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,s)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){const t=!1;this._state.pickColorsBuf=new De(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,t),this._pickColors=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Xi[0]=t[0],Xi[1]=t[1],Xi[2]=t[2],this._state.colorsBuf.setData(Xi,3*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&M),i=!!(t&V),a=!!(t&j),r=!!(t&k),l=!!(t&Q),o=!!(t&H),c=!!(t&F);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?ze.NOT_RENDERED:s?ze.COLOR_TRANSPARENT:ze.COLOR_OPAQUE,h=!n||c?ze.NOT_RENDERED:r?ze.SILHOUETTE_SELECTED:a?ze.SILHOUETTE_HIGHLIGHTED:i?ze.SILHOUETTE_XRAYED:ze.NOT_RENDERED;let p=0;p=!n||c?ze.NOT_RENDERED:r?ze.EDGES_SELECTED:a?ze.EDGES_HIGHLIGHTED:i?ze.EDGES_XRAYED:l?s?ze.EDGES_COLOR_TRANSPARENT:ze.EDGES_COLOR_OPAQUE:ze.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?ze.PICK:ze.NOT_RENDERED)<<12,A|=(t&U?255:0)<<16,qi[0]=A,this._state.flagsBuf.setData(qi,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(ea[0]=t[0],ea[1]=t[1],ea[2]=t[2],this._state.offsetsBuf.setData(ea,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,ze.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,ze.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawEdgesXRayed(e,t){}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,ze.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,ze.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,ze.PICK)}drawPickNormals(e,t){}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}class sa{constructor(){this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}reset(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}class na{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class ia{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}function aa(e,t,s=null){let n;const i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===s){const t=Ve(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===i)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(n=Ve(e,"WEBGL_compressed_texture_s3tc"),null===n)return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){const t=Ve(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===i)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){const t=Ve(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){const t=Ve(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===i)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){const t=Ve(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){const t=Ve(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===i)return 3001===s?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}const ra=new Uint8Array([0,0,0,1]);class la{constructor({gl:e,target:t,format:s,type:n,wrapS:i,wrapT:a,wrapR:r,encoding:l,preloadColor:o,premultiplyAlpha:c,flipY:u}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=s||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!u,this.unpackAlignment=4,this.wrapS=i||1e3,this.wrapT=a||1e3,this.wrapR=r||1e3,this.encoding=l||3001,this.texture=e.createTexture(),o&&this.setPreloadColor(o),this.allocated=!0}setPreloadColor(e){e?(ra[0]=Math.floor(255*e[0]),ra[1]=Math.floor(255*e[1]),ra[2]=Math.floor(255*e[2]),ra[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(ra[0]=0,ra[1]=0,ra[2]=0,ra[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let s=0,n=e.length;s1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=aa(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=aa(s,this.wrapT);if(r&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,r),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=aa(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}i?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,ca(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,ca(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,aa(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,aa(s,this.magFilter)));const l=aa(s,this.format,this.encoding),o=aa(s,this.type),c=oa(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==da[e])return void da[e].push({onLoad:t,onProgress:s,onError:n});da[e]=[],da[e].push({onLoad:t,onProgress:s,onError:n});const a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),r=this.mimeType,l=this.responseType;fetch(a).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const s=da[e],n=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,r=0!==a;let l=0;const o=new ReadableStream({start(e){!function t(){n.read().then((({done:n,value:i})=>{if(n)e.close();else{l+=i.byteLength;const n=new ProgressEvent("progress",{lengthComputable:r,loaded:l,total:a});for(let e=0,t=s.length;e{switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,r)));case"json":return e.json();default:if(void 0===r)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(r),s=t&&t[1]?t[1].toLowerCase():void 0,n=new TextDecoder(s);return e.arrayBuffer().then((e=>n.decode(e)))}}})).then((t=>{ua.add(e,t);const s=da[e];delete da[e];for(let e=0,n=s.length;e{const s=da[e];if(void 0===s)throw this.manager.itemError(e),t;delete da[e];for(let e=0,n=s.length;e{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class Ia{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e{const n=this._getIdleWorker();-1!==n?(this._initWorker(n),this.workerStatus|=1<e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let ya=0;class ma{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new Ia,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const n=e.capabilities;this._workerConfig={astcSupported:n.astcSupported,etc1Supported:n.etc1Supported,etc2Supported:n.etc2Supported,dxtSupported:n.dxtSupported,bptcSupported:n.bptcSupported,pvrtcSupported:n.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new fa;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new fa;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const n=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,n]).then((([e,t])=>{const s=ma.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(ma.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(ma.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(ma.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([n])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),ya>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),ya++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((n,i)=>{const a=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e))).then((e=>{const s=e.data,{mipmaps:a,width:r,height:l,format:o,type:c,error:u,dfdTransferFn:h,dfdFlags:p}=s;if("error"===c)return i(u);t.setCompressedData({mipmaps:a,props:{format:o,minFilter:1===a.length?1006:1008,magFilter:1===a.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&p)}}),n()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),ya--}}ma.BasisFormat={ETC1S:0,UASTC_4x4:1},ma.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},ma.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},ma.BasisWorker=function(){let e,t,s;const n=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(r){const u=r.data;switch(u.type){case"init":e=u.config,h=u.transcoderBinary,t=new Promise((e=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:r,hasAlpha:h,mipmaps:p,format:A,dfdTransferFn:d,dfdFlags:f}=function(t){const r=new s.KTX2File(new Uint8Array(t));function u(){r.close(),r.delete()}if(!r.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=r.isUASTC()?a.UASTC_4x4:a.ETC1S,p=r.getWidth(),A=r.getHeight(),d=r.getLevels(),f=r.getHasAlpha(),I=r.getDFDTransferFunc(),y=r.getDFDFlags(),{transcoderFormat:m,engineFormat:v}=function(t,s,r,u){let h,p;const A=t===a.ETC1S?l:o;for(let n=0;n{delete va[t],s.destroy()}))),s} +class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e={}){this._id=t.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==e.hideOnMouseDown&&(document.addEventListener("mousedown",(e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),e.items&&(this.items=e.items),this._hideOnAction=!1!==e.hideOnAction,this.context=e.context,this.enabled=!1!==e.enabled,this.hide()}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,n=s.length;e{const a=this._getNextId(),r=new s(a);for(let s=0,a=e.length;s0,c=this._getNextId(),u=s.getTitle||(()=>s.title||""),h=s.doAction||s.callback||(()=>{}),p=s.getEnabled||(()=>!0),A=s.getShown||(()=>!0),d=new i(c,u,h,p,A);if(d.parentMenu=r,l.items.push(d),o){const e=t(n);d.subMenu=e,e.parentItem=d}this._itemList.push(d),this._itemMap[d.id]=d}}return this._menuList.push(r),this._menuMap[r.id]=r,r};this._rootMenu=t(e)}_getNextId(){return"ContextMenu_"+this._id+"_"+this._nextId++}_createUI(){const e=t=>{this._createMenuUI(t);const s=t.groups;for(let t=0,n=s.length;t'),s.push("
    "),t)for(let e=0,n=t.length;e'+o+" [MORE]"):s.push('
  • '+o+"
  • ")}}s.push("
"),s.push("");const n=s.join("");document.body.insertAdjacentHTML("beforeend",n);const i=document.querySelector("."+e.id);e.menuElement=i,i.style["border-radius"]="4px",i.style.display="none",i.style["z-index"]=3e5,i.style.background="white",i.style.border="1px solid black",i.style["box-shadow"]="0 4px 5px 0 gray",i.oncontextmenu=e=>{e.preventDefault()};const a=this;let r=null;if(t)for(let e=0,s=t.length;e{e.preventDefault();const s=t.subMenu;if(!s)return void(r&&(a._hideMenu(r.id),r=null));if(r&&r.id!==s.id&&(a._hideMenu(r.id),r=null),!1===t.enabled)return;const n=t.itemElement,i=s.menuElement,l=n.getBoundingClientRect();i.getBoundingClientRect();l.right+200>window.innerWidth?a._showMenu(s.id,l.left-200,l.top-1):a._showMenu(s.id,l.right-5,l.top-1),r=s})),n||(t.itemElement.addEventListener("click",(e=>{e.preventDefault(),a._context&&!1!==t.enabled&&(t.doAction&&t.doAction(a._context),this._hideOnAction?a.hide():(a._updateItemsTitles(),a._updateItemsEnabledStatus()))})),t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault(),!1!==t.enabled&&t.doHover&&t.doHover(a._context)})))):console.error("ContextMenu item element not found: "+t.id)}}}_updateItemsTitles(){if(this._context)for(let e=0,t=this._itemList.length;ewindow.innerHeight&&(s=window.innerHeight-n),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=s+"px"}_hideMenuElement(e){e.style.display="none"}}class r{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let l=!0,o=l?Float64Array:Float32Array;const c=new o(16),u=new o(16),h=new o(4),p={setDoublePrecisionEnabled(e){l=e,o=l?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>l,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new o(e||2),vec3:e=>new o(e||3),vec4:e=>new o(e||4),mat3:e=>new o(e||9),mat3ToMat4:(e,t=new o(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new o(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new o(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new o(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>p.dotVec4(e,e),lenVec4:e=>Math.sqrt(p.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>p.dotVec3(e,e),sqLenVec2:e=>p.dotVec2(e,e),lenVec3:e=>Math.sqrt(p.sqLenVec3(e)),distVec3:(()=>{const e=new o(3);return(t,s)=>p.lenVec3(p.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(p.sqLenVec2(e)),distVec2:(()=>{const e=new o(2);return(t,s)=>p.lenVec2(p.subVec2(t,s,e))})(),rcpVec3:(e,t)=>p.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/p.lenVec4(e);return p.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/p.lenVec3(e);return p.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/p.lenVec2(e);return p.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=p.dotVec3(e,t)/Math.sqrt(p.sqLenVec3(e)*p.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new o(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=p.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=p.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=p.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||p.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>p.m4s(0),setMat4ToOnes:()=>p.m4s(1),diagonalMat4v:e=>new o([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>p.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>p.diagonalMat4c(e,e,e,e),identityMat4:(e=new o(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new o(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>p.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new o(9));const n=e[0],i=e[3],a=e[6],r=e[1],l=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+l*I+c*v,s[4]=r*d+l*y+c*w,s[7]=r*f+l*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=p.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||p.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||p.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new o(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,p.translationMat4v(e,i))})(),translationMat4s:(e,t)=>p.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>p.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=p.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,h,A,d,f,I;return u=l*o,h=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||p.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*h+d,s[7]=0,s[8]=r*A+f,s[9]=r*h-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>p.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=p.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=p.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new o(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,p.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>p.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=p.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,h=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=h+v,s[2]=A-m,s[3]=0,s[4]=h-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=p.vec4()){const n=p.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],h=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(h,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(h,-1,1)),Math.abs(h)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(h,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(h,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=p.mat4())=>(p.quaternionToRotationMat4(t,n),p.scaleMat4v(s,n),p.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new o(3),t=new o(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=p.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=p.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=p.lenVec3(e);p.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,h=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=h,t[9]*=h,t[10]*=h,p.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=p.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],h=t[1],A=t[2];if(i===u&&a===h&&r===A)return p.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-h,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>p.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=p.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=p.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];p.addVec4(i,n,c),p.subVec4(i,n,u);const a=2*n[2],r=u[0],l=u[1],o=u[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=c[0]/r,s[9]=c[1]/l,s[10]=-c[2]/o,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/o,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=p.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],p.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=p.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=p.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new o(16),t=new o(16),s=new o(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||p.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||p.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=p.vec4()){const n=e[0]*p.DEGTORAD/2,i=e[1]*p.DEGTORAD/2,a=e[2]*p.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),h=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"YXZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"ZXY"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"ZYX"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"YZX"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o-c*u*h):"XZY"===t&&(s[0]=c*l*o-r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o+c*u*h),s},mat4ToQuaternion(e,t=p.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let h;const A=s+r+u;return A>0?(h=.5/Math.sqrt(A+1),t[3]=.25/h,t[0]=(c-l)*h,t[1]=(i-o)*h,t[2]=(a-n)*h):s>r&&s>u?(h=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/h,t[0]=.25*h,t[1]=(n+a)/h,t[2]=(i+o)/h):r>u?(h=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/h,t[0]=(n+a)/h,t[1]=.25*h,t[2]=(l+c)/h):(h=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/h,t[0]=(i+o)/h,t[1]=(l+c)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,s=p.vec4()){const n=Math.sqrt(p.dotVec3(e,e)*p.dotVec3(t,t));let i=n+p.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):p.cross3Vec3(e,t,s),s[3]=i,p.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=p.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new o(16);return(t,s,n)=>(n=n||p.vec3(),p.quaternionToRotationMat4(t,e),p.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=p.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=p.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,h=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+h*-o-A*-l,s[1]=h*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-h*-r,s},quaternionToMat4(e,t){t=p.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,h=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+h,t[2]=f-u,t[4]=d-h,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=p.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>p.normalizeQuaternion(p.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=p.vec4()){const s=(e=p.normalizeQuaternion(e,h))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new o(e||6),AABB2:e=>new o(e||4),OBB3:e=>new o(e||32),OBB2:e=>new o(e||16),Sphere3:(e,t,s,n)=>new o([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new o(3),t=new o(3),s=new o(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],p.subVec3(t,e,s),Math.abs(p.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new o(3),t=new o(3),s=new o(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=p.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],h=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>h?u:h,Math.abs(p.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||p.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||p.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=p.AABB3())=>(e[0]=p.MAX_DOUBLE,e[1]=p.MAX_DOUBLE,e[2]=p.MAX_DOUBLE,e[3]=p.MIN_DOUBLE,e[4]=p.MIN_DOUBLE,e[5]=p.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=p.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new o(3);return(t,s,n)=>{s=s||p.AABB3();let i,a,r,l=p.MAX_DOUBLE,o=p.MAX_DOUBLE,c=p.MAX_DOUBLE,u=p.MIN_DOUBLE,h=p.MIN_DOUBLE,A=p.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>h&&(h=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=h,s[5]=A,s}})(),OBB3ToAABB3(e,t=p.AABB3()){let s,n,i,a=p.MAX_DOUBLE,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE,u=p.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=p.AABB3()){let s,n,i,a=p.MAX_DOUBLE,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE,u=p.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new o(3);return(t,s)=>{s=s||p.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new o(3),t=new o(3);return(s,n)=>{n=n||p.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=h);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new o(3),t=new o(3);return(s,n)=>{n=n||p.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ih&&(h=u);return n[3]=h,n}})(),getSphere3Center:(e,t=p.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=p.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=p.MAX_DOUBLE,e[1]=p.MAX_DOUBLE,e[2]=p.MIN_DOUBLE,e[3]=p.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=p.AABB2()){let s,n,i,a,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=p.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,h=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+h*h+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=h/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3);return(a,r,l,o,c,u)=>{u=u||p.vec3();const h=p.subVec3(o,l,e),A=p.subVec3(c,l,t),d=p.cross3Vec3(r,A,s),f=p.dotVec3(h,d);if(f<1e-6)return null;const I=p.subVec3(a,l,n),y=p.dotVec3(I,d);if(y<0||y>f)return null;const m=p.cross3Vec3(I,h,i),v=p.dotVec3(r,m);if(v<0||y+v>f)return null;const w=p.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new o(3),t=new o(3),s=new o(3),n=new o(3);return(i,a,r,l,o,c)=>{c=c||p.vec3(),a=p.normalizeVec3(a,e);const u=p.subVec3(l,r,t),h=p.subVec3(o,r,s),A=p.cross3Vec3(u,h,n);p.normalizeVec3(A,A);const d=-p.dotVec3(r,A),f=-(p.dotVec3(i,A)+d)/p.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new o(3),t=new o(3),s=new o(3);return(n,i,a,r,l)=>{const o=p.subVec3(r,i,e),c=p.subVec3(a,i,t),u=p.subVec3(n,i,s),h=p.dotVec3(o,o),A=p.dotVec3(o,c),d=p.dotVec3(o,u),f=p.dotVec3(c,c),I=p.dotVec3(c,u),y=h*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(h*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=p.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3),a=new o(3);return(r,l,o)=>{let c,u;const h=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3),a=new o(3),r=new o(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let h=0;h>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,h;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new o(4),t=new o(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,p.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],p.transformVec3(s,e,t),p.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new o(16),t=new o(16),s=new o(4),n=new o(4),i=new o(4),a=new o(4);return(r,l,o,c,u,h)=>{const A=p.mulMat4(o,l,e),d=p.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,p.transformVec4(d,s,n),p.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,p.transformVec4(d,i,a),p.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],p.subVec3(a,n,h),p.normalizeVec3(h)}})(),canvasPosToLocalRay:(()=>{const e=new o(3),t=new o(3);return(s,n,i,a,r,l,o)=>{p.canvasPosToWorldRay(s,n,i,r,e,t),p.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new o(16),t=new o(4),s=new o(4);return(n,i,a,r,l)=>{const o=p.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,p.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],p.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new o(6),l={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return l.triangles=s,l.leaf=!0,l;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),l.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};p.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=p.vec3(),u=p.vec3(),h=p.vec3(),A=p.vec3(),d=p.vec3(),f=p.vec3(),I=p.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class A{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const d={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var f=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{w.removeItem(e.id),delete R.scenes[e.id],delete v[e.id],d.components.scenes--}))},this.clear=function(){let e;for(const t in R.scenes)R.scenes.hasOwnProperty(t)&&(e=R.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete R.scenes[e.id]))},this.scheduleTask=function(e,t){g.push(e),g.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;g.length>0&&(e<0||n0&&b>0){var t=1e3/b;P+=t,E.push(t),E.length>=30&&(P-=E.shift()),d.frame.fps=Math.round(P/E.length)}!function(e){const t=R.runTasks(e+10),s=R.getNumTasks();d.frame.tasksRun=t,d.frame.tasksScheduled=s,d.frame.tasksBudget=10}(e),function(e){for(var t in T.time=e,R.scenes)if(R.scenes.hasOwnProperty(t)){var s=R.scenes[t];T.sceneId=t,T.startTime=s.startTime,T.deltaTime=null!=T.prevTime?T.time-T.prevTime:0,s.fire("tick",T,!0)}T.prevTime=e}(e),function(){const e=R.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=v[r],n||(n=v[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),D=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(C):requestAnimationFrame(C)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(C):requestAnimationFrame(C);class _{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof _))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+m.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(m.isNumeric(s)||m.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+m.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+m.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+m.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():R.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(p.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){Y.set(this._viewPos),Y[3]=1,p.transformPoint4(this.scene.camera.projMatrix,Y,X);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+X[0]/X[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-X[1]/X[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof K?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),S(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class J{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class Z{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class ${constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var ee=p.vec3(),te=p.vec3();class se extends _{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new q(s,t.origin),this._cornerMarker=new q(s,t.corner),this._targetMarker=new q(s,t.target),this._originWorld=p.vec3(),this._cornerWorld=p.vec3(),this._targetWorld=p.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new J(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new J(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new $(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(p.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);p.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,h=t.length;u{switch(a=!0,r=e.entity,l.set(e.worldPos),o.set(e.canvasPos),this._state){case 0:this.markerDiv.style.marginLeft=e.canvasPos[0]-5+"px",this.markerDiv.style.marginTop=e.canvasPos[1]-5+"px",this.markerDiv.style.background="pink",this.markerDiv.style.border="2px solid red";break;case 1:this._currentAngleMeasurement&&(this._currentAngleMeasurement.originWireVisible=!0,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.cornerVisible=!0,this._currentAngleMeasurement.angleVisible=!1,this._currentAngleMeasurement.corner.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer";break;case 2:this._currentAngleMeasurement&&(this._currentAngleMeasurement.targetWireVisible=!0,this._currentAngleMeasurement.targetVisible=!0,this._currentAngleMeasurement.angleVisible=!0,this._currentAngleMeasurement.target.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer"}})),this._onInputMouseDown=i.on("mousedown",(e=>{c=e[0],u=e[1]})),this._onInputMouseUp=i.on("mouseup",(e=>{if(!(e[0]>c+5||e[0]u+5||e[1]{if(a=!1,this.markerDiv.style.marginLeft="-100px",this.markerDiv.style.marginTop="-100px",this._currentAngleMeasurement){switch(this._state){case 0:this._currentAngleMeasurement.originVisible=!1;break;case 1:this._currentAngleMeasurement.cornerVisible=!1,this._currentAngleMeasurement.originWireVisible=!1,this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1;break;case 2:this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1}n.style.cursor="default"}})),n.addEventListener("touchstart",this._onCanvasTouchStart=e=>{const t=e.touches,s=e.changedTouches;1===t.length&&1===s.length&&ie(t[0],h)},{passive:!0}),n.addEventListener("touchend",this._onCanvasTouchEnd=e=>{const s=e.touches,n=e.changedTouches;if(0===s.length&&1===n.length){if(ie(n[0],A),A[0]>h[0]+5||A[0]h[1]+5||A[1]{this.fire("mouseOver",{plugin:this,angleMeasurement:t,measurement:t,event:e})},this._onMouseLeave=(e,t)=>{this.fire("mouseLeave",{plugin:this,angleMeasurement:t,measurement:t,event:e})},this._onContextMenu=(e,t)=>{this.fire("contextMenu",{plugin:this,angleMeasurement:t,measurement:t,event:e})}}getContainerElement(){return this._container}send(e,t){}get control(){return this._control}get measurements(){return this._measurements}createMeasurement(e={}){this.viewer.scene.components[e.id]&&(this.error("Viewer scene component with this ID already exists: "+e.id),delete e.id);const t=e.origin,s=e.corner,n=e.target,i=new se(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},corner:{entity:s.entity,worldPos:s.worldPos},target:{entity:n.entity,worldPos:n.worldPos},visible:e.visible,originVisible:!0,originWireVisible:!0,cornerVisible:!0,targetWireVisible:!0,targetVisible:!0,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[i.id]=i,i.on("destroyed",(()=>{delete this._measurements[i.id]})),this.fire("measurementCreated",i),i}destroyMeasurement(e){const t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("AngleMeasurement not found: "+e)}setLabelsShown(e){for(const[t,s]of Object.entries(this.measurements))s.labelShown=e}clear(){const e=Object.keys(this._measurements);for(var t=0,s=e.length;t{this.plugin.fire("markerClicked",this)}),this._marker.addEventListener("mouseenter",this._onMouseEnterExternalMarker=()=>{this.plugin.fire("markerMouseEnter",this)}),this._marker.addEventListener("mouseleave",this._onMouseLeaveExternalMarker=()=>{this.plugin.fire("markerMouseLeave",this)}),this._markerExternal=!0):(this._markerHTML=t.markerHTML,this._htmlDirty=!0,this._markerExternal=!1),t.labelElement?(this._label=t.labelElement,this._labelExternal=!0):(this._labelHTML=t.labelHTML,this._htmlDirty=!0,this._labelExternal=!1),this._markerShown=!!t.markerShown,this._labelShown=!!t.labelShown,this._values=t.values||{},this._layoutDirty=!0,this._visibilityDirty=!0,this._buildHTML(),this._onTick=this.scene.on("tick",(()=>{this._htmlDirty&&(this._buildHTML(),this._htmlDirty=!1,this._layoutDirty=!0,this._visibilityDirty=!0),(this._layoutDirty||this._visibilityDirty)&&(this._markerShown||this._labelShown)&&(this._updatePosition(),this._layoutDirty=!1),this._visibilityDirty&&(this._marker.style.visibility=this.visible&&this._markerShown?"visible":"hidden",this._label.style.visibility=this.visible&&this._markerShown&&this._labelShown?"visible":"hidden",this._visibilityDirty=!1)})),this.on("canvasPos",(()=>{this._layoutDirty=!0})),this.on("visible",(()=>{this._visibilityDirty=!0})),this.setMarkerShown(!1!==t.markerShown),this.setLabelShown(t.labelShown),this.eye=t.eye?t.eye.slice():null,this.look=t.look?t.look.slice():null,this.up=t.up?t.up.slice():null,this.projection=t.projection}_buildHTML(){if(!this._markerExternal){this._marker&&(this._container.removeChild(this._marker),this._marker=null);let e=this._markerHTML||"

";m.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._marker=t.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(()=>{this.plugin.fire("markerClicked",this)})),this._marker.addEventListener("mouseenter",(()=>{this.plugin.fire("markerMouseEnter",this)})),this._marker.addEventListener("mouseleave",(()=>{this.plugin.fire("markerMouseLeave",this)})),this._marker.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);let e=this._labelHTML||"

";m.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._label=t.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}}_updatePosition(){const e=this.scene.canvas.boundary,t=e[0],s=e[1],n=this.canvasPos;this._marker.style.left=Math.floor(t+n[0])-12+"px",this._marker.style.top=Math.floor(s+n[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+n[0]+20)+"px",this._label.style.top=Math.floor(s+n[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}_renderTemplate(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){const s=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),s)}return e}setMarkerShown(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}getMarkerShown(){return this._markerShown}setLabelShown(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}getLabelShown(){return this._labelShown}setField(e,t){this._values[e]=t||"",this._htmlDirty=!0}getField(e){return this._values[e]}setValues(e){for(var t in e)if(e.hasOwnProperty(t)){const s=e[t];this.setField(t,s)}}getValues(){return this._values}destroy(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),super.destroy()}}const le=p.vec3(),oe=p.vec3(),ce=p.vec3();class ue extends r{constructor(e,t){super("Annotations",e),this._labelHTML=t.labelHTML||"
",this._markerHTML=t.markerHTML||"
",this._container=t.container||document.body,this._values=t.values||{},this.annotations={},this.surfaceOffset=t.surfaceOffset}getContainerElement(){return this._container}send(e,t){if("clearAnnotations"===e)this.clear()}set surfaceOffset(e){null==e&&(e=.3),this._surfaceOffset=e}get surfaceOffset(){return this._surfaceOffset}createAnnotation(e){var t,s;if(this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id),e.pickResult=e.pickResult||e.pickRecord,e.pickResult){const n=e.pickResult;if(n.worldPos&&n.worldNormal){const e=p.normalizeVec3(n.worldNormal,le),i=p.mulVec3Scalar(e,this._surfaceOffset,oe);t=p.addVec3(n.worldPos,i,ce),s=n.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,s=e.entity;var n=null;e.markerElementId&&((n=document.getElementById(e.markerElementId))||this.error("Can't find DOM element for 'markerElementId' value '"+e.markerElementId+"' - defaulting to internally-generated empty DIV"));var i=null;e.labelElementId&&((i=document.getElementById(e.labelElementId))||this.error("Can't find DOM element for 'labelElementId' value '"+e.labelElementId+"' - defaulting to internally-generated empty DIV"));const a=new re(this.viewer.scene,{id:e.id,plugin:this,entity:s,worldPos:t,container:this._container,markerElement:n,labelElement:i,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:m.apply(e.values,m.apply(this._values,{})),markerShown:e.markerShown,labelShown:e.labelShown,eye:e.eye,look:e.look,up:e.up,projection:e.projection,visible:!1!==e.visible});return this.annotations[a.id]=a,a.on("destroyed",(()=>{delete this.annotations[a.id],this.fire("annotationDestroyed",a.id)})),this.fire("annotationCreated",a.id),a}destroyAnnotation(e){var t=this.annotations[e];t?t.destroy():this.log("Annotation not found: "+e)}clear(){const e=Object.keys(this.annotations);for(var t=0,s=e.length;t
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const pe={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},Ae=document.createElement("canvas");if(Ae){const e=Ae.getContext("webgl",{antialias:!0})||Ae.getContext("experimental-webgl",{antialias:!0});pe.WEBGL=!!e,pe.WEBGL&&(pe.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?pe.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?pe.FS_MAX_FLOAT_PRECISION="mediump":pe.FS_MAX_FLOAT_PRECISION="lowp":pe.FS_MAX_FLOAT_PRECISION="mediump",pe.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),pe.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),pe.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),pe.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),pe.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),pe.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),pe.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),pe.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),pe.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),pe.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){pe.SUPPORTED_EXTENSIONS[e]=!0})))}const de=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class fe extends _{constructor(e,t={}){super(e,t),this._backgroundColor=p.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new he(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+p.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function Ee(e){console.error(e.join("\n"))}class be{constructor(e,t){this.id=ge.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new me(e,e.VERTEX_SHADER,Te(this.source.vertex)),this._fragmentShader=new me(e,e.FRAGMENT_SHADER,Te(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void Ee(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void Ee(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void Ee(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void Ee(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void Ee(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;sthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}class Pe{constructor(e,t){this.scene=e,this.aabb=p.AABB3(),this.origin=p.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}_buildMarkerList(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}_buildPositions(){let e=0;for(let t=0;t-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Pe(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Pe(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new be(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=p.mat4();return()=>(e&&p.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,h=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Be[0]=a,Be[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,h),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Be),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new be(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new De(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new De(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const Se=new Float32Array(He(17,[0,1])),Ne=new Float32Array(He(17,[1,0])),xe=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Fe(n,t));return s}(17,4)),Le=new Float32Array(2);class Me{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new be(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new De(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new De(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new De(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=p.mat4();return()=>(e&&p.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Le[0]=r,Le[1]=l,n.uniform2fv(this._uViewport,Le),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,Ne):n.uniform2fv(this._uSampleOffsets,Se),n.uniform1fv(this._uSampleWeights,xe);const h=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,h,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Fe(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function He(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Ue{constructor(e,t,s){s=s||{},this.gl=t,this.allocated=!1,this.canvas=e,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}setSize(e){this.size=e}webglContextRestored(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}bind(e=null){if(this._touch(e),this.bound)return;const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}_touch(e=null){let t,s;const n=this.gl;if(this.size?(t=this.size[0],s=this.size[1]):(t=n.drawingBufferWidth,s=n.drawingBufferHeight),this.buffer){if(this.buffer.width===t&&this.buffer.height===s)return;n.deleteTexture(this.buffer.texture),n.deleteFramebuffer(this.buffer.framebuf),n.deleteRenderbuffer(this.buffer.renderbuf)}const i=n.createTexture();let a;n.bindTexture(n.TEXTURE_2D,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),e?n.texStorage2D(n.TEXTURE_2D,1,e,t,s):n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,s,0,n.RGBA,n.UNSIGNED_BYTE,null),this._hasDepthTexture&&(a=n.createTexture(),n.bindTexture(n.TEXTURE_2D,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.DEPTH_COMPONENT32F,t,s,0,n.DEPTH_COMPONENT,n.FLOAT,null));const r=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT32F,t,s);const l=n.createFramebuffer();if(n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,i,0),this._hasDepthTexture?n.framebufferTexture2D(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.TEXTURE_2D,a,0):n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,r),n.bindTexture(n.TEXTURE_2D,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,l),!n.isFramebuffer(l))throw"Invalid framebuffer";n.bindFramebuffer(n.FRAMEBUFFER,null);const o=n.checkFramebufferStatus(n.FRAMEBUFFER);switch(o){case n.FRAMEBUFFER_COMPLETE:break;case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case n.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+o}this.buffer={framebuf:l,renderbuf:r,texture:i,depthTexture:a,width:t,height:s},this.bound=!1}clear(){if(!this.bound)throw"Render buffer not bound";const e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}read(e,t,s=null,n=null,i=Uint8Array,a=4){const r=e,l=(this.buffer.height||this.gl.drawingBufferHeight)-t,o=new i(a),c=this.gl;return c.readPixels(r,l,1,1,s||c.RGBA,n||c.UNSIGNED_BYTE,o,0),o}readArray(e=null,t=null,s=Uint8Array,n=4){const i=new s(this.buffer.width*this.buffer.height*n),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}readImageAsCanvas(){const e=this.gl,t=this._getImageDataCache(),s=t.pixelData,n=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,s);const r=this.buffer.width,l=this.buffer.height,o=l/2|0,c=4*r,u=new Uint8Array(4*r);for(let e=0;eT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class ke{constructor(e,t,s,n,i=null,a=0){this.model=e,this.object=null,this.parent=null,this.id=t,this.aabb=null,this.layer=i,this.portionId=a,this._color=[s[0],s[1],s[2],n],this._colorize=[s[0],s[1],s[2],n],this._colorizing=!1,this._transparent=n<255,this.numTriangles=0,this.origin=null}_finalize(e){this.layer.initFlags(this.portionId,e,this._transparent)}_finalize2(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}_setVisible(e){this.layer.setVisible(this.portionId,e,this._transparent)}_setColor(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}_setColorize(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}_setOpacity(e,t){const s=e<255,n=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),n&&this.layer.setTransparent(this.portionId,t,s)}_setOffset(e){this.layer.setOffset(this.portionId,e)}_setHighlighted(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}_setXRayed(e){this.layer.setXRayed(this.portionId,e,this._transparent)}_setSelected(e){this.layer.setSelected(this.portionId,e,this._transparent)}_setEdges(e){this.layer.setEdges(this.portionId,e,this._transparent)}_setClippable(e){this.layer.setClippable(this.portionId,e,this._transparent)}_setCollidable(e){this.layer.setCollidable(this.portionId,e)}_setPickable(e){this.layer.setPickable(this.portionId,e,this._transparent)}_setCulled(e){this.layer.setCulled(this.portionId,e,this._transparent)}canPickTriangle(){return!1}drawPickTriangles(e,t){}pickTriangleSurface(e){}precisionRayPickSurface(e,t,s,n){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,s,n)}canPickWorldPos(){return!0}drawPickDepths(e){this.model.drawPickDepths(e)}drawPickNormals(e){this.model.drawPickNormals(e)}delegatePickedEntity(){return this.parent}getEachVertex(e){this.layer.getEachVertex(this.portionId,e)}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const Qe=new class{constructor(){this._uint8Arrays={},this._float32Arrays={}}_clear(){this._uint8Arrays={},this._float32Arrays={}}getUInt8Array(e){let t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}getFloat32Array(e){let t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}};let We=0;const ze={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},Ke=new e({});class Ye{constructor(e){this.id=Ke.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Ke.removeItem(this.id)}}const Xe=function(){const e=p.mat4(),t=p.mat4();return function(s,n){n=n||p.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return p.identityMat4(e),p.translationMat4v(s,e),p.identityMat4(t),p.scalingMat4v([l/u,o/u,c/u],t),p.mulMat4(e,t,n),n}}();var qe=function(){const e=p.mat4(),t=p.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function $e(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function et(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const tt={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=Ze(e,l,"floor","ceil"),n=$e(s),a=et(e,l,n),a>r&&(i=s,r=a),s=Ze(e,l,"ceil","ceil"),n=$e(s),a=et(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},st=new Float32Array([1,1,1,1]),nt=new Float32Array([0,0,0,1]),it=p.vec4(),at=p.vec3();class rt{constructor(e,t=!1,{instancing:s=!1,edges:n=!1}={}){this._scene=e,this._withSAO=t,this._instancing=s,this._edges=n,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}_getHash(){return this._scene._sectionPlanesState.getHash()}_buildShader(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}_buildVertexShader(){return[""]}_buildFragmentShader(){return[""]}_addMatricesUniformBlockLines(e,t=!1){return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}getValid(){return this._hash===this._getHash()}setSectionPlanesStateUniforms(e){const t=this._scene,{gl:s}=t.canvas,{model:n,layerIndex:i}=e,a=t._sectionPlanesState.sectionPlanes.length;if(a>0){const r=t._sectionPlanesState.sectionPlanes,l=i*a,o=n.renderFlags;for(let t=0;t0&&(this._uReflectionMap="reflectionMap"),s.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(let t=0,s=e._sectionPlanesState.sectionPlanes.length;t0&&A.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,A.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),A.lightMaps.length>0&&A.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,A.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++),this._withSAO){const t=r.sao;if(t.possible){const s=l.drawingBufferWidth,n=l.drawingBufferHeight;it[0]=s,it[1]=n,it[2]=t.blendCutoff,it[3]=t.blendFactor,l.uniform4fv(this._uSAOParams,it),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%a,e.bindTexture++}}if(n){const e=this._edges?"edgeColor":"fillColor",t=this._edges?"edgeAlpha":"fillAlpha";if(s===ze[(this._edges?"EDGES":"SILHOUETTE")+"_XRAYED"]){const s=r.xrayMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===ze[(this._edges?"EDGES":"SILHOUETTE")+"_HIGHLIGHTED"]){const s=r.highlightMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else if(s===ze[(this._edges?"EDGES":"SILHOUETTE")+"_SELECTED"]){const s=r.selectedMaterial._state,n=s[e],i=s[t];l.uniform4f(this._uColor,n[0],n[1],n[2],i)}else l.uniform4fv(this._uColor,this._edges?nt:st)}this._draw({state:o,frameCtx:e,incrementDrawState:i}),l.bindVertexArray(null)}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null,d.memory.programs--}}class lt extends rt{constructor(e,t,{instancing:s=!1,edges:n=!1}={}){super(e,t,{instancing:s,edges:n})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;if(this._edges)t.drawElements(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0);else{const e=n.pickElementsCount||s.indicesBuf.numItems,a=n.pickElementsOffset?n.pickElementsOffset*s.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,e,s.indicesBuf.itemType,a),i&&n.drawElements++}}}class ot extends lt{constructor(e,t){super(e,t,{instancing:!1,edges:!0})}}class ct extends rt{constructor(e,t,{edges:s=!1}={}){super(e,t,{instancing:!0,edges:s})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;this._edges?t.drawElementsInstanced(t.LINES,s.edgeIndicesBuf.numItems,s.edgeIndicesBuf.itemType,0,s.numInstances):(t.drawElementsInstanced(t.TRIANGLES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++)}}class ut extends ct{constructor(e,t){super(e,t,{instancing:!0,edges:!0})}}class ht extends rt{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArrays(t.POINTS,0,s.positionsBuf.numItems),i&&n.drawArrays++}}class pt extends rt{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawArraysInstanced(t.POINTS,0,s.positionsBuf.numItems,s.numInstances),i&&n.drawArrays++}}class At extends rt{_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElements(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0),i&&n.drawElements++}}class dt extends rt{constructor(e,t){super(e,t,{instancing:!0})}_draw(e){const{gl:t}=this._scene.canvas,{state:s,frameCtx:n,incrementDrawState:i}=e;t.drawElementsInstanced(t.LINES,s.indicesBuf.numItems,s.indicesBuf.itemType,0,s.numInstances),i&&n.drawElements++}}class ft extends lt{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i;const a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(let e=0,t=s.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(let e=0,t=s.lights.length;e0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching draw fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class It extends lt{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching flat-shading draw vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._lightsState,s=e._sectionPlanesState,n=s.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),n){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,s=t.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}class mt extends ot{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class vt extends ot{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry edges drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class wt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class gt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Tt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec3 worldNormal = octDecode(normal.xy); "),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class Et extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class bt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching depth fragment shader"),n.push("precision highp float;"),n.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),n.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),n.push("}"),n}}class Dt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Pt extends lt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Batched geometry shadow vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 outColor;"),s.push("void main(void) {"),s.push(" int colorFlag = int(flags) & 0xF;"),s.push(" bool visible = (colorFlag > 0);"),s.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push(" if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Batched geometry shadow fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),t){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(let t=0;t> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var n=0;n 0.0) { discard; }"),s.push(" }")}return s.push(" outColor = encodeFloat( gl_FragCoord.z); "),s.push("}"),s}}class Rt extends lt{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Triangles batching quality draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),r.push("uniform sampler2D uAOMap;"),r.push("in vec4 vViewPosition;"),r.push("in vec3 vViewNormal;"),r.push("in vec4 vColor;"),r.push("in vec2 vUV;"),r.push("in vec2 vMetallicRoughness;"),n.lightMaps.length>0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching pick flat normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("out vec4 vWorldPosition;"),t&&s.push("out float vFlags;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),t&&s.push(" vFlags = flags;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Triangles batching pick flat normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class _t extends lt{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles batching color texture vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._lightsState,n=e._sectionPlanesState,i=n.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(let e=0,t=n.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(let e=0,t=n.sectionPlanes.length;e 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(let e=0,t=s.lights.length;e5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]}}const Nt=p.mat4(),xt=p.mat4();function Lt(e,t,s){const n=e.length,i=new Uint16Array(n),a=t[0],r=t[1],l=t[2],o=t[3]-a,c=t[4]-r,u=t[5]-l,h=65525,A=h/o,d=h/c,f=h/u,I=e=>e>=0?e:0;for(let t=0;t=0?1:-1),t=(1-Math.abs(n))*(i>=0?1:-1),n=e,i=t}return new Int8Array([Math[t](127.5*n+(n<0?-1:0)),Math[s](127.5*i+(i<0?-1:0))])}function Ht(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}const Ut=p.vec3();class Gt{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;let c=a.eye;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];const u=t.aabb,h=[p.safeInv(u[3]-u[0])*p.MAX_INT,p.safeInv(u[4]-u[1])*p.MAX_INT,p.safeInv(u[5]-u[2])*p.MAX_INT];if(e._coordinateScale[0]=p.safeInv(h[0]),e._coordinateScale[1]=p.safeInv(h[1]),e._coordinateScale[2]=p.safeInv(h[2]),!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),e.pickViewMatrix&&(c=e.pickOrigin||c);const A=[c[0]-o[0],c[1]-o[1],c[2]-o[2]];r.uniform3fv(this._uCameraEyeRtc,A),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.layerNumber),r.uniform3fv(this._uCoordinateScaler,h),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible),r.uniform1i(this._uSolid,t.solid);const d=e.pickViewMatrix||a.viewMatrix,f=o?O(d,o):d;if(r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,a=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),s.push("uniform bool solid;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("out float isPerspective;")),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Vt=p.vec3();class jt{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.camera,r=i.canvas.gl,l=t._state,o=t._state.origin;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];const c=t.aabb,u=[p.safeInv(c[3]-c[0])*p.MAX_INT,p.safeInv(c[4]-c[1])*p.MAX_INT,p.safeInv(c[5]-c[2])*p.MAX_INT];if(e._coordinateScale[0]=p.safeInv(u[0]),e._coordinateScale[1]=p.safeInv(u[1]),e._coordinateScale[2]=p.safeInv(u[2]),!this._program&&(this._allocate(),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());let h=a.eye;e.pickViewMatrix&&(h=e.pickOrigin||h);const A=[h[0]-o[0],h[1]-o[1],h[2]-o[2]];r.uniform3fv(this._uCameraEyeRtc,A),r.uniform2fv(this.uVectorA,e.snapVectorA),r.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),r.uniform1i(this._uLayerNumber,e.layerNumber),r.uniform3fv(this._uCoordinateScaler,u),r.uniform1i(this._uRenderPass,s),r.uniform1i(this._uPickInvisible,e.pickInvisible);const d=e.pickViewMatrix||a.viewMatrix,f=o?O(d,o):d;if(r.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),r.uniformMatrix4fv(this._uViewMatrix,!1,f),r.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);r.uniform1f(this._uLogDepthBufFC,t)}const I=i._sectionPlanesState.sectionPlanes.length;if(I>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*I,a=n.renderFlags;for(let t=0;t0;e.pointsMaterial._state;const s=[];return s.push("#version 300 es"),s.push("// SnapBatchingDepthRenderer vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push(" } else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push(" }"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class kt{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Gt(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new jt(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const Qt={};const Wt=p.mat4(),zt=p.mat4(),Kt=p.vec4([0,0,0,1]),Yt=p.vec4([0,0,0,1]),Xt=p.vec4([0,0,0,1]),qt=p.OBB3(),Jt=p.vec3(),Zt=p.vec3(),$t=p.vec3(),es=p.vec3(),ts=p.vec3(),ss=p.vec3(),ns=p.vec3();class is{constructor(e){console.log("Creating TrianglesBatchingLayer"),this.model=e.model,this.sortId="TrianglesBatchingLayer"+(e.solid?"-solid":"-surface")+(e.autoNormals?"-autonormals":"-normals")+(e.textureSet&&e.textureSet.colorTexture?"-colorTexture":"")+(e.textureSet&&e.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=Ot[t];return s||(s=new Bt(e),Ot[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Ot[t],s._destroy()}))),s}(e.model.scene),this._snapBatchingRenderers=function(e){const t=e.id;let s=Qt[t];return s||(s=new kt(e),Qt[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Qt[t],s._destroy()}))),s}(e.model.scene),this._buffer=new St(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ye({origin:p.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:e.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=p.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=p.mat4(e.positionsDecodeMatrix)),e.uvDecodeMatrix?(this._state.uvDecodeMatrix=p.mat3(e.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,e.origin&&this._state.origin.set(e.origin),this.aabb=p.collapseAABB3(),this.solid=!!e.solid}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(let e=0,t=i.length;e0){const e=Wt;I?p.inverseMat4(p.transposeMat4(I,zt),e):p.identityMat4(e,e),function(e,t,s,n,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}let r,l,o,c,u,h,A=new Float32Array([0,0,0,0]),d=new Float32Array([0,0,0,0]);for(h=0;hu&&(o=r,u=c),r=Ft(d,"floor","ceil"),l=Ht(r),c=a(d,l),c>u&&(o=r,u=c),r=Ft(d,"ceil","ceil"),l=Ht(r),c=a(d,l),c>u&&(o=r,u=c),n[i+h+0]=o[0],n[i+h+1]=o[1],n[i+h+2]=0}(e,n,n.length,g.normals,g.normals.length)}if(l)for(let e=0,t=l.length;e0)for(let e=0,t=a.length;e0)for(let e=0,t=r.length;e0){const n=this._state.positionsDecodeMatrix?new Uint16Array(s.positions):Lt(s.positions,this._modelAABB,this._state.positionsDecodeMatrix=p.mat4());if(e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(let e=0,t=this._portions.length;e0){const n=new Int8Array(s.normals);let i=!0;e.normalsBuf=new De(t,t.ARRAY_BUFFER,n,s.normals.length,3,t.STATIC_DRAW,i)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new De(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.uv.length>0)if(e.uvDecodeMatrix){let n=!1;e.uvBuf=new De(t,t.ARRAY_BUFFER,s.uv,s.uv.length,2,t.STATIC_DRAW,n)}else{const n=tt.getUVBounds(s.uv),i=tt.compressUVs(s.uv,n.min,n.max),a=i.quantized;let r=!1;e.uvDecodeMatrix=p.mat3(i.decodeMatrix),e.uvBuf=new De(t,t.ARRAY_BUFFER,a,a.length,2,t.STATIC_DRAW,r)}if(s.metallicRoughness.length>0){const n=new Uint8Array(s.metallicRoughness);let i=!1;e.metallicRoughnessBuf=new De(t,t.ARRAY_BUFFER,n,s.metallicRoughness.length,2,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n),a=!1;e.flagsBuf=new De(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new De(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new De(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}if(s.edgeIndices.length>0){const n=new Uint32Array(s.edgeIndices);e.edgeIndicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,n,s.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}isEmpty(){return!this._state.indicesBuf}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=e,n=this._portions[s],i=4*n.vertsBaseIndex,a=4*n.numVerts,r=this._scratchMemory.getUInt8Array(a),l=t[0],o=t[1],c=t[2],u=t[3];for(let e=0;em)&&(m=e,n.set(v),i&&p.triangleNormal(d,f,I,i),y=!0)}}return y&&i&&(p.transformVec3(this.model.worldNormalMatrix,i,i),p.normalizeVec3(i)),y}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}class as extends ct{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0;let i,a,r;const l=[];for(l.push("#version 300 es"),l.push("// Instancing geometry drawing vertex shader"),l.push("uniform int renderPass;"),l.push("in vec3 position;"),l.push("in vec2 normal;"),l.push("in vec4 color;"),l.push("in float flags;"),e.entityOffsetsEnabled&&l.push("in vec3 offset;"),l.push("in vec4 modelMatrixCol0;"),l.push("in vec4 modelMatrixCol1;"),l.push("in vec4 modelMatrixCol2;"),l.push("in vec4 modelNormalMatrixCol0;"),l.push("in vec4 modelNormalMatrixCol1;"),l.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(l,!0),e.logarithmicDepthBufferEnabled&&(l.push("uniform float logDepthBufFC;"),l.push("out float vFragDepth;"),l.push("bool isPerspectiveMatrix(mat4 m) {"),l.push(" return (m[2][3] == - 1.0);"),l.push("}"),l.push("out float isPerspective;")),l.push("uniform vec4 lightAmbient;"),i=0,a=s.lights.length;i= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),l.push(" }"),l.push(" return normalize(v);"),l.push("}"),n&&(l.push("out vec4 vWorldPosition;"),l.push("out float vFlags;")),l.push("out vec4 vColor;"),l.push("void main(void) {"),l.push("int colorFlag = int(flags) & 0xF;"),l.push("if (colorFlag != renderPass) {"),l.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),l.push("} else {"),l.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),l.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&l.push(" worldPosition.xyz = worldPosition.xyz + offset;"),l.push("vec4 viewPosition = viewMatrix * worldPosition; "),l.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),l.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),l.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),i=0,a=s.lights.length;i0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),this._withSAO&&(n.push("uniform sampler2D uOcclusionTexture;"),n.push("uniform vec4 uSAOParams;"),n.push("const float packUpscale = 256. / 255.;"),n.push("const float unpackDownScale = 255. / 256.;"),n.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),n.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),n.push("float unpackRGBToFloat( const in vec4 v ) {"),n.push(" return dot( v, unPackFactors );"),n.push("}")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),n.push(" discard;"),n.push(" }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(n.push(" float viewportWidth = uSAOParams[0];"),n.push(" float viewportHeight = uSAOParams[1];"),n.push(" float blendCutoff = uSAOParams[2];"),n.push(" float blendFactor = uSAOParams[3];"),n.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),n.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),n.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):n.push(" outColor = vColor;"),n.push("}"),n}}class rs extends ct{_getHash(){const e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState;let n,i;const a=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry flat-shading drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),a){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}for(r.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),r.push("float lambertian = 1.0;"),r.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),r.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),r.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),n=0,i=s.lights.length;n0,s=[];return s.push("#version 300 es"),s.push("// Instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 color;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing fill fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class os extends ut{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("uniform vec4 color;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(color.r, color.g, color.b, color.a);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class cs extends ut{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Triangles instancing edges vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int edgeFlag = int(flags) >> 8 & 0xF;"),s.push("if (edgeFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry edges drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class us extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry picking vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 pickColor;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vPickColor;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry picking fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class hs extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push(" vViewPosition = viewPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class ps extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec2 normal;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("in vec4 modelNormalMatrixCol0;"),s.push("in vec4 modelNormalMatrixCol1;"),s.push("in vec4 modelNormalMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vWorldNormal;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),s.push(" vWorldNormal = worldNormal;"),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class As extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing occlusion vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("in float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class ds extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry depth drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec2 vHighPrecisionZW;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("vHighPrecisionZW = gl_Position.zw;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}class fs extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec3 normal;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s,!0),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec3 octDecode(vec2 oct) {"),s.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),s.push(" if (v.z < 0.0) {"),s.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),s.push(" }"),s.push(" return normalize(v);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec3 vViewNormal;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),s.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" vViewNormal = viewNormal;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Is extends ct{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}const ys=1e3,ms=1001,vs=1002,ws=1003,gs=1004,Ts=1004,Es=1005,bs=1005,Ds=1006,Ps=1007,Rs=1007,Cs=1008,_s=1008,Bs=1009,Os=1010,Ss=1011,Ns=1012,xs=1013,Ls=1014,Ms=1015,Fs=1016,Hs=1017,Us=1018,Gs=1020,Vs=1021,js=1022,ks=1023,Qs=1024,Ws=1025,zs=1026,Ks=1027,Ys=1028,Xs=1029,qs=1030,Js=1031,Zs=1033,$s=33776,en=33777,tn=33778,sn=33779,nn=35840,an=35841,rn=35842,ln=35843,on=36196,cn=37492,un=37496,hn=37808,pn=37809,An=37810,dn=37811,fn=37812,In=37813,yn=37814,mn=37815,vn=37816,wn=37817,gn=37818,Tn=37819,En=37820,bn=37821,Dn=36492,Pn=3e3,Rn=3001,Cn=1e4,_n=10001,Bn=10002,On=10003,Sn={3e3:"linearToLinear",3001:"sRGBToLinear"};class Nn extends ct{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState,s=e._lightsState,n=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),s.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),n&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),s.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState,i=s.sectionPlanes.length>0,a=s.clippingCaps,r=[];r.push("#version 300 es"),r.push("// Instancing geometry quality drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform sampler2D uColorMap;"),r.push("uniform sampler2D uMetallicRoughMap;"),r.push("uniform sampler2D uEmissiveMap;"),r.push("uniform sampler2D uNormalMap;"),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n.reflectionMaps.length>0&&r.push("uniform samplerCube reflectionMap;"),n.lightMaps.length>0&&r.push("uniform samplerCube lightMap;"),r.push("uniform vec4 lightAmbient;");for(let e=0,t=n.lights.length;e0&&r.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(r,!0),r.push("#define PI 3.14159265359"),r.push("#define RECIPROCAL_PI 0.31830988618"),r.push("#define RECIPROCAL_PI2 0.15915494"),r.push("#define EPSILON 1e-6"),r.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),r.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),r.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),r.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),r.push(" return normalize(surf_norm );"),r.push(" }"),r.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),r.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),r.push(" vec2 st0 = dFdx( uv.st );"),r.push(" vec2 st1 = dFdy( uv.st );"),r.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),r.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),r.push(" vec3 N = normalize( surf_norm );"),r.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),r.push(" mat3 tsn = mat3( S, T, N );"),r.push(" return normalize( tsn * mapN );"),r.push("}"),r.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),r.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),r.push("}"),r.push("struct IncidentLight {"),r.push(" vec3 color;"),r.push(" vec3 direction;"),r.push("};"),r.push("struct ReflectedLight {"),r.push(" vec3 diffuse;"),r.push(" vec3 specular;"),r.push("};"),r.push("struct Geometry {"),r.push(" vec3 position;"),r.push(" vec3 viewNormal;"),r.push(" vec3 worldNormal;"),r.push(" vec3 viewEyeDir;"),r.push("};"),r.push("struct Material {"),r.push(" vec3 diffuseColor;"),r.push(" float specularRoughness;"),r.push(" vec3 specularColor;"),r.push(" float shine;"),r.push("};"),r.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),r.push(" float r = ggxRoughness + 0.0001;"),r.push(" return (2.0 / (r * r) - 2.0);"),r.push("}"),r.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),r.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),r.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),r.push("}"),n.reflectionMaps.length>0&&(r.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),r.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),r.push(" vec3 envMapColor = "+Sn[n.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),r.push(" return envMapColor;"),r.push("}")),r.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),r.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),r.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),r.push("}"),r.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" return 1.0 / ( gl * gv );"),r.push("}"),r.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),r.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),r.push(" return 0.5 / max( gv + gl, EPSILON );"),r.push("}"),r.push("float D_GGX(const in float alpha, const in float dotNH) {"),r.push(" float a2 = ( alpha * alpha );"),r.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),r.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float alpha = ( roughness * roughness );"),r.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),r.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),r.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),r.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),r.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),r.push(" vec3 F = F_Schlick( specularColor, dotLH );"),r.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),r.push(" float D = D_GGX( alpha, dotNH );"),r.push(" return F * (G * D);"),r.push("}"),r.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),r.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),r.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),r.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),r.push(" vec4 r = roughness * c0 + c1;"),r.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),r.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),r.push(" return specularColor * AB.x + AB.y;"),r.push("}"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&(r.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),n.lightMaps.length>0&&(r.push(" vec3 irradiance = "+Sn[n.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),r.push(" irradiance *= PI;"),r.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),n.reflectionMaps.length>0&&(r.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),r.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),r.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),r.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),r.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),r.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),r.push("}")),r.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),r.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),r.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),r.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),r.push("}"),r.push("out vec4 outColor;"),r.push("void main(void) {"),i){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e (0.002 * vClipPosition.w)) {"),r.push(" discard;"),r.push(" }"),r.push(" if (dist > 0.0) { "),r.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" return;"),r.push("}")):(r.push(" if (dist > 0.0) { "),r.push(" discard;"),r.push(" }")),r.push("}")}r.push("IncidentLight light;"),r.push("Material material;"),r.push("Geometry geometry;"),r.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),r.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),r.push("float opacity = float(vColor.a) / 255.0;"),r.push("vec3 baseColor = rgb;"),r.push("float specularF0 = 1.0;"),r.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),r.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),r.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),r.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),r.push("baseColor *= colorTexel.rgb;"),r.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),r.push("metallic *= metalRoughTexel.b;"),r.push("roughness *= metalRoughTexel.g;"),r.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),r.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),r.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),r.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),r.push("geometry.position = vViewPosition.xyz;"),r.push("geometry.viewNormal = -normalize(viewNormal);"),r.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),n.lightMaps.length>0&&r.push("geometry.worldNormal = normalize(vWorldNormal);"),(n.lightMaps.length>0||n.reflectionMaps.length>0)&&r.push("computePBRLightMapping(geometry, material, reflectedLight);");for(let e=0,t=n.lights.length;e0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry normals vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&s.push("out float vFlags;"),s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),s.push(" vWorldPosition = worldPosition;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&s.push("vFlags = flags;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry normals fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("in vec4 vWorldPosition;"),s){n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),n.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),n.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),n.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),n.push("}"),n}}class Ln extends ct{_getHash(){const e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry drawing vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in vec2 uv;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),s.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vViewPosition;"),s.push("out vec4 vColor;"),s.push("out vec2 vUV;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vViewPosition = viewPosition;"),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),s.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e.gammaOutput,s=e._sectionPlanesState,n=e._lightsState;let i,a;const r=s.sectionPlanes.length>0,l=[];if(l.push("#version 300 es"),l.push("// Instancing geometry drawing fragment shader"),l.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),l.push("precision highp float;"),l.push("precision highp int;"),l.push("#else"),l.push("precision mediump float;"),l.push("precision mediump int;"),l.push("#endif"),e.logarithmicDepthBufferEnabled&&(l.push("in float isPerspective;"),l.push("uniform float logDepthBufFC;"),l.push("in float vFragDepth;")),l.push("uniform sampler2D uColorMap;"),this._withSAO&&(l.push("uniform sampler2D uOcclusionTexture;"),l.push("uniform vec4 uSAOParams;"),l.push("const float packUpscale = 256. / 255.;"),l.push("const float unpackDownScale = 255. / 256.;"),l.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),l.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),l.push("float unpackRGBToFloat( const in vec4 v ) {"),l.push(" return dot( v, unPackFactors );"),l.push("}")),l.push("uniform float gammaFactor;"),l.push("vec4 linearToLinear( in vec4 value ) {"),l.push(" return value;"),l.push("}"),l.push("vec4 sRGBToLinear( in vec4 value ) {"),l.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),l.push("}"),l.push("vec4 gammaToLinear( in vec4 value) {"),l.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),l.push("}"),t&&(l.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),l.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),l.push("}")),r){l.push("in vec4 vWorldPosition;"),l.push("in float vFlags;");for(let e=0,t=s.sectionPlanes.length;e> 16 & 0xF) == 1;"),l.push(" if (clippable) {"),l.push(" float dist = 0.0;");for(let e=0,t=s.sectionPlanes.length;e 0.0) { "),l.push(" discard;"),l.push(" }"),l.push("}")}for(l.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),l.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),l.push("float lambertian = 1.0;"),l.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),l.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),l.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),i=0,a=n.lights.length;i0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// Points instancing snap vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.z += 0.0001;"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}const Gn=p.vec3();class Vn{constructor(e){this._scene=e,this._hash=this._getHash(),this._allocate()}getValid(){return this._hash===this._getHash()}_getHash(){return this._scene._sectionPlanesState.getHash()}drawLayer(e,t,s){const n=t.model,i=n.scene,a=i.canvas.gl,r=t._state,l=t._state.origin,o=r.geometry;e._origin[0]=l[0],e._origin[1]=l[1],e._origin[2]=l[2];const c=t.aabb,u=[p.safeInv(c[3]-c[0])*p.MAX_INT,p.safeInv(c[4]-c[1])*p.MAX_INT,p.safeInv(c[5]-c[2])*p.MAX_INT];if(e._coordinateScale[0]=p.safeInv(u[0]),e._coordinateScale[1]=p.safeInv(u[1]),e._coordinateScale[2]=p.safeInv(u[2]),!this._program&&(this._allocate(t),this.errors))return;e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());const h=i.camera;let A=h.eye;e.pickViewMatrix&&(A=e.pickOrigin||A);const d=[A[0]-l[0],A[1]-l[1],A[2]-l[2]];a.uniform3fv(this._uCameraEyeRtc,d),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.layerNumber),a.uniform3fv(this._uCoordinateScaler,u),a.uniform1i(this._uRenderPass,s),a.uniform1i(this._uPickInvisible,e.pickInvisible);const f=e.pickViewMatrix||h.viewMatrix,I=l?O(f,l):f;if(a.uniformMatrix4fv(this._uViewMatrix,!1,I),a.uniformMatrix4fv(this._uWorldMatrix,!1,n.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,h.projMatrix),i.logarithmicDepthBufferEnabled){const t=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,t)}const y=i._sectionPlanesState.sectionPlanes.length;if(y>0){const e=i._sectionPlanesState.sectionPlanes,s=t.layerIndex*y,r=n.renderFlags;for(let t=0;t0,s=[];return s.push("#version 300 es"),s.push("// Points instancing snap vertex shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("precision highp usampler2D;"),s.push("precision highp isampler2D;"),s.push("precision highp sampler2D;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("precision mediump usampler2D;"),s.push("precision mediump isampler2D;"),s.push("precision mediump sampler2D;"),s.push("#endif"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform bool pickInvisible;"),s.push("uniform mat4 worldMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),s.push("uniform mat4 positionsDecodeMatrix;"),s.push("uniform vec3 uCameraEyeRtc;"),s.push("uniform vec2 snapVectorA;"),s.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;"),s.push("bool isPerspectiveMatrix(mat4 m) {"),s.push(" return (m[2][3] == - 1.0);"),s.push("}"),s.push("out float isPerspective;")),s.push("vec2 remapClipPos(vec2 clipPos) {"),s.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),s.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),s.push(" return vec2(x, y);"),s.push("}"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out highp vec3 relativeToOriginPosition;"),s.push("void main(void) {"),s.push("int pickFlag = int(flags) >> 12 & 0xF;"),s.push("if (pickFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("relativeToOriginPosition = worldPosition.xyz;"),s.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push(" vWorldPosition = worldPosition;"),s.push(" vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),s.push("float tmp = clipPos.w;"),s.push("clipPos.xyzw /= tmp;"),s.push("clipPos.xy = remapClipPos(clipPos.xy);"),s.push("clipPos.xyzw *= tmp;"),e.logarithmicDepthBufferEnabled&&(s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("in float isPerspective;"),n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform int layerNumber;"),n.push("uniform vec3 coordinateScaler;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),n.push("}"),n}webglContextRestored(){this._program=null}destroy(){this._program&&this._program.destroy(),this._program=null}}class jn{constructor(e){this._scene=e}_compile(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}get snapDepthBufInitRenderer(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Un(this._scene,!1)),this._snapDepthBufInitRenderer}get snapDepthRenderer(){return this._snapDepthRenderer||(this._snapDepthRenderer=new Vn(this._scene)),this._snapDepthRenderer}_destroy(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}const kn={};const Qn=new Uint8Array(4),Wn=new Float32Array(1),zn=p.vec4([0,0,0,1]),Kn=p.vec4([0,0,0,1]),Yn=p.vec4([0,0,0,1]),Xn=new Float32Array(3),qn=p.vec3(),Jn=p.vec3(),Zn=p.vec3(),$n=p.vec3(),ei=p.vec3(),ti=p.vec3(),si=p.vec3();class ni{constructor(e){console.log("Creating TrianglesInstancingLayer"),this.model=e.model,this.sortId="TrianglesInstancingLayer"+(e.solid?"-solid":"-surface")+(e.normals?"-normals":"-autoNormals"),this.layerIndex=e.layerIndex,this._instancingRenderers=function(e){const t=e.id;let s=Fn[t];return s||(s=new Mn(e),Fn[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Fn[t],s._destroy()}))),s}(e.model.scene),this._snapInstancingRenderers=function(e){const t=e.id;let s=kn[t];return s||(s=new jn(e),kn[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete kn[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new Ye({numInstances:0,obb:p.OBB3(),origin:p.vec3(),geometry:e.geometry,textureSet:e.textureSet,pbrSupported:!1,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],e.origin&&this._state.origin.set(e.origin),this._finalized=!1,this.aabb=p.collapseAABB3(),this.solid=!!e.solid,this.numIndices=e.geometry.numIndices}createPortion(e){const t=e.color,s=e.metallic,n=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,r=e.sceneModelMatrix,l=e.aabb,o=e.pickColor;if(this._finalized)throw"Already finalized";const c=t[0],u=t[1],h=t[2];if(this._colors.push(c),this._colors.push(u),this._colors.push(h),this._colors.push(i),this._metallicRoughness.push(null!=s?s:0),this._metallicRoughness.push(null!=n?n:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){let e=p.transposeMat4(a,p.mat4()),t=p.inverseMat4(e);this._modelNormalMatrixCol0.push(t[0]),this._modelNormalMatrixCol0.push(t[4]),this._modelNormalMatrixCol0.push(t[8]),this._modelNormalMatrixCol0.push(t[12]),this._modelNormalMatrixCol1.push(t[1]),this._modelNormalMatrixCol1.push(t[5]),this._modelNormalMatrixCol1.push(t[9]),this._modelNormalMatrixCol1.push(t[13]),this._modelNormalMatrixCol2.push(t[2]),this._modelNormalMatrixCol2.push(t[6]),this._modelNormalMatrixCol2.push(t[10]),this._modelNormalMatrixCol2.push(t[14])}this._pickColors.push(o[0]),this._pickColors.push(o[1]),this._pickColors.push(o[2]),this._pickColors.push(o[3]);const A=this._state.geometry.positionsCompressed.length,d=this._state.geometry.positionsCompressed,f=this._state.geometry.positionsDecodeMatrix;for(let e=0;e0){let t=!1;e.colorsBuf=new De(n,n.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,n.DYNAMIC_DRAW,t),this._colors=[]}if(this._metallicRoughness.length>0){const t=new Uint8Array(this._metallicRoughness);let s=!1;e.metallicRoughnessBuf=new De(n,n.ARRAY_BUFFER,t,this._metallicRoughness.length,2,n.STATIC_DRAW,s)}if(a>0){let t=!1;e.flagsBuf=new De(n,n.ARRAY_BUFFER,new Float32Array(a),a,1,n.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;e.offsetsBuf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,n.DYNAMIC_DRAW,t),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){const s=!1;e.positionsBuf=new De(n,n.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,n.STATIC_DRAW,s),e.positionsDecodeMatrix=p.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){const s=new Uint8Array(t.colorsCompressed),i=!1;e.colorsBuf=new De(n,n.ARRAY_BUFFER,s,s.length,4,n.STATIC_DRAW,i)}if(t.uvCompressed&&t.uvCompressed.length>0){const s=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new De(n,n.ARRAY_BUFFER,s,s.length,2,n.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new De(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,n.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new De(n,n.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,n.STATIC_DRAW)),this._modelMatrixCol0.length>0){const t=!1;e.modelMatrixCol0Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelMatrixCol1Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelMatrixCol2Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol1Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,n.STATIC_DRAW,t),e.modelNormalMatrixCol2Buf=new De(n,n.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,n.STATIC_DRAW,t),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){const t=!1;e.pickColorsBuf=new De(n,n.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,n.STATIC_DRAW,t),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&s&&s.colorTexture&&s.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!s&&!!s.colorTexture,this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Qn[0]=t[0],Qn[1]=t[1],Qn[2]=t[2],Qn[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Qn,4*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&M),i=!!(t&V),a=!!(t&j),r=!!(t&k),l=!!(t&Q),o=!!(t&H),c=!!(t&F);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?ze.NOT_RENDERED:s?ze.COLOR_TRANSPARENT:ze.COLOR_OPAQUE,h=!n||c?ze.NOT_RENDERED:r?ze.SILHOUETTE_SELECTED:a?ze.SILHOUETTE_HIGHLIGHTED:i?ze.SILHOUETTE_XRAYED:ze.NOT_RENDERED;let p=0;p=!n||c?ze.NOT_RENDERED:r?ze.EDGES_SELECTED:a?ze.EDGES_HIGHLIGHTED:i?ze.EDGES_XRAYED:l?s?ze.EDGES_COLOR_TRANSPARENT:ze.EDGES_COLOR_OPAQUE:ze.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?ze.PICK:ze.NOT_RENDERED)<<12,A|=(t&U?1:0)<<16,Wn[0]=A,this._state.flagsBuf&&this._state.flagsBuf.setData(Wn,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Xn[0]=t[0],Xn[1]=t[1],Xn[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Xn,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}getEachVertex(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;const s=this._state,n=s.geometry,i=this._portions[e];if(!i)return void this.model.error("portion not found: "+e);const a=n.quantizedPositions,r=s.origin,l=i.offset,o=r[0]+l[0],c=r[1]+l[1],u=r[2]+l[2],h=zn,A=i.matrix,d=this.model.sceneModelMatrix,f=s.positionsDecodeMatrix;for(let e=0,s=a.length;ev)&&(v=e,n.set(w),i&&p.triangleNormal(f,I,y,i),m=!0)}}return m&&i&&(p.transformVec3(l.normalMatrix,i,i),p.transformVec3(this.model.worldNormalMatrix,i,i),p.normalizeVec3(i)),m}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}class ii extends At{drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push("worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class ai extends At{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines batching silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),this._addMatricesUniformBlockLines(s),s.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines batching silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class ri{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new ii(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ai(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const li={};class oi{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]}}const ci=p.vec4([0,0,0,1]),ui=p.vec4([0,0,0,1]),hi=p.vec4([0,0,0,1]),pi=p.OBB3();class Ai{constructor(e){this.layerIndex=e.layerIndex,this._batchingRenderers=function(e){const t=e.id;let s=li[t];return s||(s=new ri(e),li[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete li[t],s._destroy()}))),s}(e.model.scene),this.model=e.model,this._buffer=new oi(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ye({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:p.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=p.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=p.vec3(e.origin)),this.aabb=p.collapseAABB3()}canCreatePortion(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Lt(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new De(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.DYNAMIC_DRAW,i)}if(s.colors.length>0){const n=s.colors.length/4,i=new Float32Array(n);let a=!1;e.flagsBuf=new De(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new De(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}if(s.indices.length>0){const n=new Uint32Array(s.indices);e.indicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,n,s.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);this._setFlags(e,t,s,!0)}flushInitFlags(){this._setDeferredFlags()}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2],c=t[3];for(let e=0;e0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing color vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),s.push("in vec4 color;"),s.push("in float flags;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 lightAmbient;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("out vec4 vColor;"),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("if (colorFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),s.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class fi extends dt{drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Lines instancing silhouette vertex shader"),s.push("uniform int renderPass;"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(s),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),s.push("uniform vec4 color;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),s.push("if (silhouetteFlag != renderPass) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&s.push("vFragDepth = 1.0 + clipPos.w;"),s.push("gl_Position = clipPos;"),s.push("}"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Lines instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = color;"),n.push("}"),n}}class Ii{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new di(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new fi(this._scene)),this._silhouetteRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}const yi={};const mi=new Uint8Array(4),vi=new Float32Array(1),wi=p.vec4([0,0,0,1]),gi=p.vec4([0,0,0,1]),Ti=p.vec4([0,0,0,1]),Ei=new Float32Array(3);class bi{constructor(e){this.model=e.model,this.material=e.material,this.sortId="LinesInstancingLayer",this.layerIndex=e.layerIndex,this._linesInstancingRenderers=function(e){const t=e.id;let s=yi[t];return s||(s=new Ii(e),yi[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete yi[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new Ye({obb:p.OBB3(),numInstances:0,origin:null,geometry:e.geometry,positionsDecodeMatrix:e.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],e.origin&&(this._state.origin=p.vec3(e.origin)),this._finalized=!1,this.aabb=p.collapseAABB3()}createPortion(e){const t=e.color,s=e.opacity,n=e.meshMatrix,i=e.worldMatrix,a=e.aabb;if(this._finalized)throw"Already finalized";const r=t[0],l=t[1],o=t[2];t[3],this._colors.push(r),this._colors.push(l),this._colors.push(o),this._colors.push(s),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(n[0]),this._modelMatrixCol0.push(n[4]),this._modelMatrixCol0.push(n[8]),this._modelMatrixCol0.push(n[12]),this._modelMatrixCol1.push(n[1]),this._modelMatrixCol1.push(n[5]),this._modelMatrixCol1.push(n[9]),this._modelMatrixCol1.push(n[13]),this._modelMatrixCol2.push(n[2]),this._modelMatrixCol2.push(n[6]),this._modelMatrixCol2.push(n[10]),this._modelMatrixCol2.push(n[14]),p.collapseAABB3(a);const c=this._state.obb,u=c.length;for(let e=0;e0){let t=!1;this._state.colorsBuf=new De(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,t),this._colors=[]}if(s>0){let t=!1;this._state.flagsBuf=new De(e,e.ARRAY_BUFFER,new Float32Array(s),s,1,e.DYNAMIC_DRAW,t)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";mi[0]=t[0],mi[1]=t[1],mi[2]=t[2],mi[3]=t[3],this._state.colorsBuf.setData(mi,4*e,4)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&M),i=!!(t&V),a=!!(t&j),r=!!(t&k),l=!!(t&Q),o=!!(t&H),c=!!(t&F);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?ze.NOT_RENDERED:s?ze.COLOR_TRANSPARENT:ze.COLOR_OPAQUE,h=!n||c?ze.NOT_RENDERED:r?ze.SILHOUETTE_SELECTED:a?ze.SILHOUETTE_HIGHLIGHTED:i?ze.SILHOUETTE_XRAYED:ze.NOT_RENDERED;let p=0;p=!n||c?ze.NOT_RENDERED:r?ze.EDGES_SELECTED:a?ze.EDGES_HIGHLIGHTED:i?ze.EDGES_XRAYED:l?s?ze.EDGES_COLOR_TRANSPARENT:ze.EDGES_COLOR_OPAQUE:ze.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?ze.PICK:ze.NOT_RENDERED)<<12,A|=(t&U?255:0)<<16,vi[0]=A,this._state.flagsBuf.setData(vi,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Ei[0]=t[0],Ei[1]=t[1],Ei[2]=t[2],this._state.offsetsBuf.setData(Ei,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,ze.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,ze.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesXRayed(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawOcclusion(e,t){}drawShadow(e,t){}drawPickMesh(e,t){}drawPickDepths(e,t){}drawPickNormals(e,t){}destroy(){const e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}class Di extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{incrementDrawState:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial,n=[];return n.push("#version 300 es"),n.push("// Points batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Pi extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}class Ri extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching pick mesh vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var i=0;i 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vPickColor; "),n.push("}"),n}}class Ci extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batched pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("gl_PointSize += 10.0;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batched pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class _i extends ht{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push(" gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push(" }"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points batching occlusion fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push(" }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),n.push("}"),n}}class Bi{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Di(this._scene)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Pi(this._scene)),this._silhouetteRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Ri(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Ci(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new _i(this._scene)),this._occlusionRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}const Oi={};class Si{constructor(e=5e6){e>5e6&&(e=5e6),this.maxVerts=e,this.maxIndices=3*e,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]}}const Ni=p.vec4(),xi=p.vec4(),Li=p.vec4([0,0,0,1]),Mi=p.vec4([0,0,0,1]),Fi=p.vec4([0,0,0,1]),Hi=p.OBB3();class Ui{constructor(e){this.model=e.model,this.sortId="PointsBatchingLayer",this.layerIndex=e.layerIndex,this._pointsBatchingRenderers=function(e){const t=e.id;let s=Oi[t];return s||(s=new Bi(e),Oi[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Oi[t],s._destroy()}))),s}(e.model.scene),this._buffer=new Si(e.maxGeometryBatchSize),this._scratchMemory=e.scratchMemory,this._state=new Ye({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:p.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=p.collapseAABB3(),this._portions=[],this._finalized=!1,e.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(e.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,e.origin&&(this._state.origin=p.vec3(e.origin)),this.aabb=p.collapseAABB3()}canCreatePortion(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}createPortion(e){if(this._finalized)throw"Already finalized";const t=e.positions,s=e.positionsCompressed,n=e.color,i=e.colorsCompressed,a=e.colors,r=e.meshMatrix,l=e.worldMatrix,o=e.worldAABB,c=e.pickColor,u=this._buffer,h=u.positions.length/3;let A;if(this._preCompressedPositionsExpected){if(!s)throw"positionsCompressed expected";for(let e=0,t=s.length;e0)if(this._preCompressedPositionsExpected){const n=new Uint16Array(s.positions);e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}else{const n=Lt(new Float32Array(s.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new De(t,t.ARRAY_BUFFER,n,s.positions.length,3,t.STATIC_DRAW)}if(s.colors.length>0){const n=new Uint8Array(s.colors);let i=!1;e.colorsBuf=new De(t,t.ARRAY_BUFFER,n,s.colors.length,4,t.STATIC_DRAW,i)}if(s.positions.length>0){const n=s.positions.length/3,i=new Float32Array(n);let a=!1;e.flagsBuf=new De(t,t.ARRAY_BUFFER,i,i.length,1,t.DYNAMIC_DRAW,a)}if(s.pickColors.length>0){const n=new Uint8Array(s.pickColors);let i=!1;e.pickColorsBuf=new De(t,t.ARRAY_BUFFER,n,s.pickColors.length,4,t.STATIC_DRAW,i)}if(this.model.scene.entityOffsetsEnabled&&s.offsets.length>0){const n=new Float32Array(s.offsets);e.offsetsBuf=new De(t,t.ARRAY_BUFFER,n,s.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized"}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";const s=2*e,n=4*this._portions[s],i=4*this._portions[s+1],a=this._scratchMemory.getUInt8Array(i),r=t[0],l=t[1],o=t[2];for(let e=0;e0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),s.filterIntensity&&n.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),s.filterIntensity&&(n.push("float intensity = float(color.a) / 255.0;"),n.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {")),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),s.filterIntensity&&n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing color fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Vi extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}drawLayer(e,t,s){super.drawLayer(e,t,s,{colorUniform:!0})}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 silhouetteColor;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing silhouette fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vColor;"),n.push("}"),n}}class ji extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick mesh vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick mesh fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("outColor = vPickColor; "),n.push("}"),n}}class ki extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing pick depth fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),n.push("uniform float pickZNear;"),n.push("uniform float pickZFar;"),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),n.push(" outColor = packDepth(zNormalizedDepth); "),n.push("}"),n}}class Qi extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Points instancing occlusion vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0;e 1.0) {"),n.push(" discard;"),n.push(" }")),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0;e 0.0) { discard; }"),n.push("}")}return n.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push("}"),n}}class Wi extends pt{_getHash(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=e.pointsMaterial._state,n=[];return n.push("#version 300 es"),n.push("// Points instancing depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),s.perspectivePoints&&n.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),s.perspectivePoints?(n.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),n.push("gl_PointSize = max(gl_PointSize, "+Math.floor(s.minPerspectivePointSize)+".0);"),n.push("gl_PointSize = min(gl_PointSize, "+Math.floor(s.maxPerspectivePointSize)+".0);")):n.push("gl_PointSize = pointSize;"),n.push("}"),n.push("}"),n}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState;let s,n;const i=t.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),s=0,n=t.sectionPlanes.length;s 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),s=0,n=t.sectionPlanes.length;s 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),e.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}class zi extends pt{_buildVertexShader(){const e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,s=[];return s.push("#version 300 es"),s.push("// Instancing geometry shadow drawing vertex shader"),s.push("in vec3 position;"),e.entityOffsetsEnabled&&s.push("in vec3 offset;"),s.push("in vec4 color;"),s.push("in float flags;"),s.push("in vec4 modelMatrixCol0;"),s.push("in vec4 modelMatrixCol1;"),s.push("in vec4 modelMatrixCol2;"),s.push("uniform mat4 shadowViewMatrix;"),s.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(s),s.push("uniform float pointSize;"),t&&(s.push("out vec4 vWorldPosition;"),s.push("out float vFlags;")),s.push("void main(void) {"),s.push("int colorFlag = int(flags) & 0xF;"),s.push("bool visible = (colorFlag > 0);"),s.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),s.push("if (!visible || transparent) {"),s.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),s.push("} else {"),s.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),s.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&s.push(" worldPosition.xyz = worldPosition.xyz + offset;"),s.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(s.push("vWorldPosition = worldPosition;"),s.push("vFlags = flags;")),s.push(" gl_Position = shadowProjMatrix * viewPosition;"),s.push("}"),s.push("gl_PointSize = pointSize;"),s.push("}"),s}_buildFragmentShader(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Instancing geometry depth drawing fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(let e=0,s=t.sectionPlanes.length;e 1.0) {"),n.push(" discard;"),n.push(" }"),s){n.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(let e=0,s=t.sectionPlanes.length;e 0.0) { discard; }"),n.push("}")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),n.push("}"),n}}class Ki{constructor(e){this._scene=e}_compile(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}get colorRenderer(){return this._colorRenderer||(this._colorRenderer=new Gi(this._scene,!1)),this._colorRenderer}get silhouetteRenderer(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Vi(this._scene)),this._silhouetteRenderer}get depthRenderer(){return this._depthRenderer||(this._depthRenderer=new Wi(this._scene)),this._depthRenderer}get pickMeshRenderer(){return this._pickMeshRenderer||(this._pickMeshRenderer=new ji(this._scene)),this._pickMeshRenderer}get pickDepthRenderer(){return this._pickDepthRenderer||(this._pickDepthRenderer=new ki(this._scene)),this._pickDepthRenderer}get occlusionRenderer(){return this._occlusionRenderer||(this._occlusionRenderer=new Qi(this._scene)),this._occlusionRenderer}get shadowRenderer(){return this._shadowRenderer||(this._shadowRenderer=new zi(this._scene)),this._shadowRenderer}_destroy(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}const Yi={};const Xi=new Uint8Array(4),qi=new Float32Array(1),Ji=p.vec4([0,0,0,1]),Zi=p.vec4([0,0,0,1]),$i=p.vec4([0,0,0,1]),ea=new Float32Array(3);class ta{constructor(e){this.model=e.model,this.material=e.material,this.sortId="PointsInstancingLayer",this.layerIndex=e.layerIndex,this._pointsInstancingRenderers=function(e){const t=e.id;let s=Yi[t];return s||(s=new Ki(e),Yi[t]=s,s._compile(),e.on("compile",(()=>{s._compile()})),e.on("destroyed",(()=>{delete Yi[t],s._destroy()}))),s}(e.model.scene),this._aabb=p.collapseAABB3(),this._state=new Ye({obb:p.OBB3(),numInstances:0,origin:e.origin?p.vec3(e.origin):null,geometry:e.geometry,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=e.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=p.collapseAABB3()}createPortion(e){const t=e.meshMatrix,s=e.worldMatrix,n=e.aabb,i=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(i[0]),this._pickColors.push(i[1]),this._pickColors.push(i[2]),this._pickColors.push(i[3]),p.collapseAABB3(n);const a=this._state.obb,r=a.length;for(let e=0;e0){let s=!1;this._state.flagsBuf=new De(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,s)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){const t=!1;this._state.offsetsBuf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,t),this._offsets=[]}if(this._modelMatrixCol0.length>0){const t=!1;this._state.modelMatrixCol0Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol1Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,t),this._state.modelMatrixCol2Buf=new De(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,t),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){const t=!1;this._state.pickColorsBuf=new De(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,t),this._pickColors=[]}this._state.geometry=null,this._finalized=!0}initFlags(e,t,s){t&M&&(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++),t&j&&(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++),t&V&&(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++),t&k&&(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++),t&U&&(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++),t&Q&&(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++),t&H&&(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&F&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,s)}setVisible(e,t,s){if(!this._finalized)throw"Not finalized";t&M?(this._numVisibleLayerPortions++,this.model.numVisibleLayerPortions++):(this._numVisibleLayerPortions--,this.model.numVisibleLayerPortions--),this._setFlags(e,t,s)}setHighlighted(e,t,s){if(!this._finalized)throw"Not finalized";t&j?(this._numHighlightedLayerPortions++,this.model.numHighlightedLayerPortions++):(this._numHighlightedLayerPortions--,this.model.numHighlightedLayerPortions--),this._setFlags(e,t,s)}setXRayed(e,t,s){if(!this._finalized)throw"Not finalized";t&V?(this._numXRayedLayerPortions++,this.model.numXRayedLayerPortions++):(this._numXRayedLayerPortions--,this.model.numXRayedLayerPortions--),this._setFlags(e,t,s)}setSelected(e,t,s){if(!this._finalized)throw"Not finalized";t&k?(this._numSelectedLayerPortions++,this.model.numSelectedLayerPortions++):(this._numSelectedLayerPortions--,this.model.numSelectedLayerPortions--),this._setFlags(e,t,s)}setEdges(e,t,s){if(!this._finalized)throw"Not finalized";t&Q?(this._numEdgesLayerPortions++,this.model.numEdgesLayerPortions++):(this._numEdgesLayerPortions--,this.model.numEdgesLayerPortions--),this._setFlags(e,t,s)}setClippable(e,t){if(!this._finalized)throw"Not finalized";t&U?(this._numClippableLayerPortions++,this.model.numClippableLayerPortions++):(this._numClippableLayerPortions--,this.model.numClippableLayerPortions--),this._setFlags(e,t)}setCollidable(e,t){if(!this._finalized)throw"Not finalized"}setPickable(e,t,s){if(!this._finalized)throw"Not finalized";t&H?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,s)}setCulled(e,t,s){if(!this._finalized)throw"Not finalized";t&F?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,s)}setColor(e,t){if(!this._finalized)throw"Not finalized";Xi[0]=t[0],Xi[1]=t[1],Xi[2]=t[2],this._state.colorsBuf.setData(Xi,3*e)}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}_setFlags(e,t,s){if(!this._finalized)throw"Not finalized";const n=!!(t&M),i=!!(t&V),a=!!(t&j),r=!!(t&k),l=!!(t&Q),o=!!(t&H),c=!!(t&F);let u,h;u=!n||c||i||a&&!this.model.scene.highlightMaterial.glowThrough||r&&!this.model.scene.selectedMaterial.glowThrough?ze.NOT_RENDERED:s?ze.COLOR_TRANSPARENT:ze.COLOR_OPAQUE,h=!n||c?ze.NOT_RENDERED:r?ze.SILHOUETTE_SELECTED:a?ze.SILHOUETTE_HIGHLIGHTED:i?ze.SILHOUETTE_XRAYED:ze.NOT_RENDERED;let p=0;p=!n||c?ze.NOT_RENDERED:r?ze.EDGES_SELECTED:a?ze.EDGES_HIGHLIGHTED:i?ze.EDGES_XRAYED:l?s?ze.EDGES_COLOR_TRANSPARENT:ze.EDGES_COLOR_OPAQUE:ze.NOT_RENDERED;let A=0;A|=u,A|=h<<4,A|=p<<8,A|=(n&&!c&&o?ze.PICK:ze.NOT_RENDERED)<<12,A|=(t&U?255:0)<<16,qi[0]=A,this._state.flagsBuf.setData(qi,e)}setOffset(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(ea[0]=t[0],ea[1]=t[1],ea[2]=t[2],this._state.offsetsBuf.setData(ea,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}drawColorOpaque(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,ze.COLOR_OPAQUE)}drawColorTransparent(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,ze.COLOR_TRANSPARENT)}drawDepth(e,t){}drawNormals(e,t){}drawSilhouetteXRayed(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_XRAYED)}drawSilhouetteHighlighted(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_HIGHLIGHTED)}drawSilhouetteSelected(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,ze.SILHOUETTE_SELECTED)}drawEdgesColorOpaque(e,t){}drawEdgesColorTransparent(e,t){}drawEdgesHighlighted(e,t){}drawEdgesSelected(e,t){}drawEdgesXRayed(e,t){}drawOcclusion(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,ze.COLOR_OPAQUE)}drawShadow(e,t){}drawPickMesh(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,ze.PICK)}drawPickDepths(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,ze.PICK)}drawPickNormals(e,t){}destroy(){const e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}class sa{constructor(){this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}reset(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}class na{constructor(e){this.id=e.id,this.colorTexture=e.colorTexture,this.metallicRoughnessTexture=e.metallicRoughnessTexture,this.normalsTexture=e.normalsTexture,this.emissiveTexture=e.emissiveTexture,this.occlusionTexture=e.occlusionTexture}destroy(){}}class ia{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}function aa(e,t,s=null){let n;const i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===s){const t=Ve(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===t)return null;if(33776===i)return t.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return t.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(n=Ve(e,"WEBGL_compressed_texture_s3tc"),null===n)return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){const t=Ve(e,"WEBGL_compressed_texture_pvrtc");if(null===t)return null;if(35840===i)return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){const t=Ve(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){const t=Ve(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===i)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:t.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){const t=Ve(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){const t=Ve(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===i)return 3001===s?t.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:t.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}const ra=new Uint8Array([0,0,0,1]);class la{constructor({gl:e,target:t,format:s,type:n,wrapS:i,wrapT:a,wrapR:r,encoding:l,preloadColor:o,premultiplyAlpha:c,flipY:u}){this.gl=e,this.target=t||e.TEXTURE_2D,this.format=s||1023,this.type=n||1009,this.internalFormat=null,this.premultiplyAlpha=!!c,this.flipY=!!u,this.unpackAlignment=4,this.wrapS=i||1e3,this.wrapT=a||1e3,this.wrapR=r||1e3,this.encoding=l||3001,this.texture=e.createTexture(),o&&this.setPreloadColor(o),this.allocated=!0}setPreloadColor(e){e?(ra[0]=Math.floor(255*e[0]),ra[1]=Math.floor(255*e[1]),ra[2]=Math.floor(255*e[2]),ra[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(ra[0]=0,ra[1]=0,ra[2]=0,ra[3]=255);const t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP){const e=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let s=0,n=e.length;s1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=aa(s,this.wrapS);a&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,a);const r=aa(s,this.wrapT);if(r&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,r),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=aa(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}i?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,ca(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,ca(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,aa(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,aa(s,this.magFilter)));const l=aa(s,this.format,this.encoding),o=aa(s,this.type),c=oa(s,this.internalFormat,l,o,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,n,c,e[0].width,e[0].height);for(let t=0,n=e.length;t{t&&t(i),this.manager.itemEnd(e)}),0),i;if(void 0!==da[e])return void da[e].push({onLoad:t,onProgress:s,onError:n});da[e]=[],da[e].push({onLoad:t,onProgress:s,onError:n});const a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),r=this.mimeType,l=this.responseType;fetch(a).then((t=>{if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const s=da[e],n=t.body.getReader(),i=t.headers.get("Content-Length"),a=i?parseInt(i):0,r=0!==a;let l=0;const o=new ReadableStream({start(e){!function t(){n.read().then((({done:n,value:i})=>{if(n)e.close();else{l+=i.byteLength;const n=new ProgressEvent("progress",{lengthComputable:r,loaded:l,total:a});for(let e=0,t=s.length;e{switch(l){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((e=>(new DOMParser).parseFromString(e,r)));case"json":return e.json();default:if(void 0===r)return e.text();{const t=/charset="?([^;"\s]*)"?/i.exec(r),s=t&&t[1]?t[1].toLowerCase():void 0,n=new TextDecoder(s);return e.arrayBuffer().then((e=>n.decode(e)))}}})).then((t=>{ua.add(e,t);const s=da[e];delete da[e];for(let e=0,n=s.length;e{const s=da[e];if(void 0===s)throw this.manager.itemError(e),t;delete da[e];for(let e=0,n=s.length;e{this.manager.itemEnd(e)})),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}}class Ia{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e{const n=this._getIdleWorker();-1!==n?(this._initWorker(n),this.workerStatus|=1<e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}let ya=0;class ma{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new Ia,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const n=e.capabilities;this._workerConfig={astcSupported:n.astcSupported,etc1Supported:n.etc1Supported,etc2Supported:n.etc2Supported,dxtSupported:n.dxtSupported,bptcSupported:n.bptcSupported,pvrtcSupported:n.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new fa;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new fa;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const n=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,n]).then((([e,t])=>{const s=ma.BasisWorker.toString(),n=["/* constants */","let _EngineFormat = "+JSON.stringify(ma.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(ma.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(ma.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([n])),this._transcoderBinary=t,this._workerPool.setWorkerCreator((()=>{const e=new Worker(this._workerSourceURL),t=this._transcoderBinary.slice(0);return e.postMessage({type:"init",config:this._workerConfig,transcoderBinary:t},[t]),e}))})),ya>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),ya++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((n,i)=>{const a=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e))).then((e=>{const s=e.data,{mipmaps:a,width:r,height:l,format:o,type:c,error:u,dfdTransferFn:h,dfdFlags:p}=s;if("error"===c)return i(u);t.setCompressedData({mipmaps:a,props:{format:o,minFilter:1===a.length?1006:1008,magFilter:1===a.length?1006:1008,encoding:2===h?3001:3e3,premultiplyAlpha:!!(1&p)}}),n()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),ya--}}ma.BasisFormat={ETC1S:0,UASTC_4x4:1},ma.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},ma.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},ma.BasisWorker=function(){let e,t,s;const n=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(r){const u=r.data;switch(u.type){case"init":e=u.config,h=u.transcoderBinary,t=new Promise((e=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:r,hasAlpha:h,mipmaps:p,format:A,dfdTransferFn:d,dfdFlags:f}=function(t){const r=new s.KTX2File(new Uint8Array(t));function u(){r.close(),r.delete()}if(!r.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");const h=r.isUASTC()?a.UASTC_4x4:a.ETC1S,p=r.getWidth(),A=r.getHeight(),d=r.getLevels(),f=r.getHasAlpha(),I=r.getDFDTransferFunc(),y=r.getDFDFlags(),{transcoderFormat:m,engineFormat:v}=function(t,s,r,u){let h,p;const A=t===a.ETC1S?l:o;for(let n=0;n{delete va[t],s.destroy()}))),s} /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT diff --git a/dist/xeokit-sdk.min.es5.js b/dist/xeokit-sdk.min.es5.js index 108274b99..4b218f283 100644 --- a/dist/xeokit-sdk.min.es5.js +++ b/dist/xeokit-sdk.min.es5.js @@ -1,4 +1,4 @@ -var e,t=l().mark(eT),n=l().mark(tT),r=l().mark(pD);function i(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||A(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var o=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(o&&l){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),b(n),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;b(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:P(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},e}function u(e,t,n,r,i,a,s){try{var o=e[a](s),l=o.value}catch(e){return void n(e)}o.done?t(l):Promise.resolve(l).then(r,i)}function c(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function s(e){u(a,r,i,s,o,"next",e)}function o(e){u(a,r,i,s,o,"throw",e)}s(void 0)}))}}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=A(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}(e,t)||A(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._id=k.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==n.hideOnMouseDown&&(document.addEventListener("mousedown",(function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),n.items&&(this.items=n.items),this._hideOnAction=!1!==n.hideOnAction,this.context=n.context,this.enabled=!1!==n.enabled,this.hide()}return P(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r0,c=t._getNextId(),f=a.getTitle||function(){return a.title||""},p=a.doAction||a.callback||function(){},A=a.getEnabled||function(){return!0},d=a.getShown||function(){return!0},v=new Q(c,f,p,A,d);if(v.parentMenu=i,l.items.push(v),u){var h=e(s);v.subMenu=h,h.parentItem=v}t._itemList.push(v),t._itemMap[v.id]=v},c=0,f=o.length;c'),r.push("
    "),n)for(var i=0,a=n.length;i'+A+" [MORE]"):r.push('
  • '+A+"
  • ")}}r.push("
"),r.push("");var d=r.join("");document.body.insertAdjacentHTML("beforeend",d);var v=document.querySelector("."+e.id);e.menuElement=v,v.style["border-radius"]="4px",v.style.display="none",v.style["z-index"]=3e5,v.style.background="white",v.style.border="1px solid black",v.style["box-shadow"]="0 4px 5px 0 gray",v.oncontextmenu=function(e){e.preventDefault()};var h=this,I=null;if(n)for(var y=0,m=n.length;ywindow.innerWidth?h._showMenu(t.id,a.left-200,a.top-1):h._showMenu(t.id,a.right-5,a.top-1),I=t}}else I&&(h._hideMenu(I.id),I=null)})),i||(r.itemElement.addEventListener("click",(function(e){e.preventDefault(),h._context&&!1!==r.enabled&&(r.doAction&&r.doAction(h._context),t._hideOnAction?h.hide():(h._updateItemsTitles(),h._updateItemsEnabledStatus()))})),r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==r.enabled&&r.doHover&&r.doHover(h._context)})))},T=0,E=w.length;Twindow.innerHeight&&(n=window.innerHeight-r),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=n+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),z=function(){function e(t,n,r){b(this,e),this.id=r&&r.id?r.id:t,this.viewer=n,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,n.addPlugin(this)}return P(e,[{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){console.log("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"warn",value:function(e){console.warn("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"error",value:function(e){console.error("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.removePlugin(this)}}]),e}(),K=!0,Y=K?Float64Array:Float32Array,X=new Y(16),q=new Y(16),J=new Y(4),Z={setDoublePrecisionEnabled:function(e){Y=(K=e)?Float64Array:Float32Array},getDoublePrecisionEnabled:function(){return K},MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId:function(e,t){var n=t.indexOf("#");return n===e.length&&t.startsWith(e)?t.substring(n+1):t},globalizeObjectId:function(e,t){return e+"#"+t},safeInv:function(e){var t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:function(e){return new Y(e||2)},vec3:function(e){return new Y(e||3)},vec4:function(e){return new Y(e||4)},mat3:function(e){return new Y(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Y(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},mat4:function(e){return new Y(e||16)},mat4ToMat3:function(e,t){},doublesToFloats:function(e,t,n){for(var r=new Y(2),i=0,a=e.length;i>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&n]).concat(e[n>>8&255],"-").concat(e[n>>16&15|64]).concat(e[n>>24&255],"-").concat(e[63&r|128]).concat(e[r>>8&255],"-").concat(e[r>>16&255]).concat(e[r>>24&255]).concat(e[255&i]).concat(e[i>>8&255]).concat(e[i>>16&255]).concat(e[i>>24&255])}}(),clamp:function(e,t,n){return Math.max(t,Math.min(n,e))},fmod:function(e,t){if(e1?1:n,Math.acos(n)},vec3FromMat4Scale:function(){var e=new Y(3);return function(t,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],n[0]=Z.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],n[1]=Z.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],n[2]=Z.lenVec3(e),n}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var n=0,r=(t=Array.prototype.slice.call(t)).length;n0&&void 0!==arguments[0]?arguments[0]:new Y(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},identityMat3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Y(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},isIdentityMat4:function(e){return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]},negateMat4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t},addMat4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n[4]=e[4]+t[4],n[5]=e[5]+t[5],n[6]=e[6]+t[6],n[7]=e[7]+t[7],n[8]=e[8]+t[8],n[9]=e[9]+t[9],n[10]=e[10]+t[10],n[11]=e[11]+t[11],n[12]=e[12]+t[12],n[13]=e[13]+t[13],n[14]=e[14]+t[14],n[15]=e[15]+t[15],n},addMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n[4]=e[4]+t,n[5]=e[5]+t,n[6]=e[6]+t,n[7]=e[7]+t,n[8]=e[8]+t,n[9]=e[9]+t,n[10]=e[10]+t,n[11]=e[11]+t,n[12]=e[12]+t,n[13]=e[13]+t,n[14]=e[14]+t,n[15]=e[15]+t,n},addScalarMat4:function(e,t,n){return Z.addMat4Scalar(t,e,n)},subMat4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n[4]=e[4]-t[4],n[5]=e[5]-t[5],n[6]=e[6]-t[6],n[7]=e[7]-t[7],n[8]=e[8]-t[8],n[9]=e[9]-t[9],n[10]=e[10]-t[10],n[11]=e[11]-t[11],n[12]=e[12]-t[12],n[13]=e[13]-t[13],n[14]=e[14]-t[14],n[15]=e[15]-t[15],n},subMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n[4]=e[4]-t,n[5]=e[5]-t,n[6]=e[6]-t,n[7]=e[7]-t,n[8]=e[8]-t,n[9]=e[9]-t,n[10]=e[10]-t,n[11]=e[11]-t,n[12]=e[12]-t,n[13]=e[13]-t,n[14]=e[14]-t,n[15]=e[15]-t,n},subScalarMat4:function(e,t,n){return n||(n=t),n[0]=e-t[0],n[1]=e-t[1],n[2]=e-t[2],n[3]=e-t[3],n[4]=e-t[4],n[5]=e-t[5],n[6]=e-t[6],n[7]=e-t[7],n[8]=e-t[8],n[9]=e-t[9],n[10]=e-t[10],n[11]=e-t[11],n[12]=e-t[12],n[13]=e-t[13],n[14]=e-t[14],n[15]=e-t[15],n},mulMat4:function(e,t,n){n||(n=e);var r=e[0],i=e[1],a=e[2],s=e[3],o=e[4],l=e[5],u=e[6],c=e[7],f=e[8],p=e[9],A=e[10],d=e[11],v=e[12],h=e[13],I=e[14],y=e[15],m=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],L=t[15];return n[0]=m*r+w*o+g*f+T*v,n[1]=m*i+w*l+g*p+T*h,n[2]=m*a+w*u+g*A+T*I,n[3]=m*s+w*c+g*d+T*y,n[4]=E*r+b*o+D*f+P*v,n[5]=E*i+b*l+D*p+P*h,n[6]=E*a+b*u+D*A+P*I,n[7]=E*s+b*c+D*d+P*y,n[8]=R*r+C*o+_*f+B*v,n[9]=R*i+C*l+_*p+B*h,n[10]=R*a+C*u+_*A+B*I,n[11]=R*s+C*c+_*d+B*y,n[12]=O*r+S*o+N*f+L*v,n[13]=O*i+S*l+N*p+L*h,n[14]=O*a+S*u+N*A+L*I,n[15]=O*s+S*c+N*d+L*y,n},mulMat3:function(e,t,n){n||(n=new Y(9));var r=e[0],i=e[3],a=e[6],s=e[1],o=e[4],l=e[7],u=e[2],c=e[5],f=e[8],p=t[0],A=t[3],d=t[6],v=t[1],h=t[4],I=t[7],y=t[2],m=t[5],w=t[8];return n[0]=r*p+i*v+a*y,n[3]=r*A+i*h+a*m,n[6]=r*d+i*I+a*w,n[1]=s*p+o*v+l*y,n[4]=s*A+o*h+l*m,n[7]=s*d+o*I+l*w,n[2]=u*p+c*v+f*y,n[5]=u*A+c*h+f*m,n[8]=u*d+c*I+f*w,n},mulMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n[4]=e[4]*t,n[5]=e[5]*t,n[6]=e[6]*t,n[7]=e[7]*t,n[8]=e[8]*t,n[9]=e[9]*t,n[10]=e[10]*t,n[11]=e[11]*t,n[12]=e[12]*t,n[13]=e[13]*t,n[14]=e[14]*t,n[15]=e[15]*t,n},mulMat4v4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=t[0],i=t[1],a=t[2],s=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12]*s,n[1]=e[1]*r+e[5]*i+e[9]*a+e[13]*s,n[2]=e[2]*r+e[6]*i+e[10]*a+e[14]*s,n[3]=e[3]*r+e[7]*i+e[11]*a+e[15]*s,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],a=e[13],s=e[12],o=e[9];if(!t||e===t){var l=e[1],u=e[2],c=e[3],f=e[6],p=e[7],A=e[11];return e[1]=n,e[2]=i,e[3]=s,e[4]=l,e[6]=o,e[7]=a,e[8]=u,e[9]=f,e[11]=r,e[12]=c,e[13]=p,e[14]=A,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=s,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=r,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3:function(e,t){if(t===e){var n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4:function(e){var t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],s=e[5],o=e[6],l=e[7],u=e[8],c=e[9],f=e[10],p=e[11],A=e[12],d=e[13],v=e[14],h=e[15];return A*c*o*i-u*d*o*i-A*s*f*i+a*d*f*i+u*s*v*i-a*c*v*i-A*c*r*l+u*d*r*l+A*n*f*l-t*d*f*l-u*n*v*l+t*c*v*l+A*s*r*p-a*d*r*p-A*n*o*p+t*d*o*p+a*n*v*p-t*s*v*p-u*s*r*h+a*c*r*h+u*n*o*h-t*c*o*h-a*n*f*h+t*s*f*h},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],a=e[3],s=e[4],o=e[5],l=e[6],u=e[7],c=e[8],f=e[9],p=e[10],A=e[11],d=e[12],v=e[13],h=e[14],I=e[15],y=n*o-r*s,m=n*l-i*s,w=n*u-a*s,g=r*l-i*o,T=r*u-a*o,E=i*u-a*l,b=c*v-f*d,D=c*h-p*d,P=c*I-A*d,R=f*h-p*v,C=f*I-A*v,_=p*I-A*h,B=1/(y*_-m*C+w*R+g*P-T*D+E*b);return t[0]=(o*_-l*C+u*R)*B,t[1]=(-r*_+i*C-a*R)*B,t[2]=(v*E-h*T+I*g)*B,t[3]=(-f*E+p*T-A*g)*B,t[4]=(-s*_+l*P-u*D)*B,t[5]=(n*_-i*P+a*D)*B,t[6]=(-d*E+h*w-I*m)*B,t[7]=(c*E-p*w+A*m)*B,t[8]=(s*C-o*P+u*b)*B,t[9]=(-n*C+r*P-a*b)*B,t[10]=(d*T-v*w+I*y)*B,t[11]=(-c*T+f*w-A*y)*B,t[12]=(-s*R+o*D-l*b)*B,t[13]=(n*R-r*D+i*b)*B,t[14]=(-d*g+v*m-h*y)*B,t[15]=(c*g-f*m+p*y)*B,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var n=t||Z.identityMat4();return n[12]=e[0],n[13]=e[1],n[14]=e[2],n},translationMat3v:function(e,t){var n=t||Z.identityMat3();return n[6]=e[0],n[7]=e[1],n},translationMat4c:(H=new Y(3),function(e,t,n,r){return H[0]=e,H[1]=t,H[2]=n,Z.translationMat4v(H,r)}),translationMat4s:function(e,t){return Z.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return Z.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,n,r){var i=r[3];r[0]+=i*e,r[1]+=i*t,r[2]+=i*n;var a=r[7];r[4]+=a*e,r[5]+=a*t,r[6]+=a*n;var s=r[11];r[8]+=s*e,r[9]+=s*t,r[10]+=s*n;var o=r[15];return r[12]+=o*e,r[13]+=o*t,r[14]+=o*n,r},setMat4Translation:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=e[15],n},rotationMat4v:function(e,t,n){var r,i,a,s,o,l,u=Z.normalizeVec4([t[0],t[1],t[2],0],[]),c=Math.sin(e),f=Math.cos(e),p=1-f,A=u[0],d=u[1],v=u[2];return r=A*d,i=d*v,a=v*A,s=A*c,o=d*c,l=v*c,(n=n||Z.mat4())[0]=p*A*A+f,n[1]=p*r+l,n[2]=p*a-o,n[3]=0,n[4]=p*r-l,n[5]=p*d*d+f,n[6]=p*i+s,n[7]=0,n[8]=p*a+o,n[9]=p*i-s,n[10]=p*v*v+f,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},rotationMat4c:function(e,t,n,r,i){return Z.rotationMat4v(e,[t,n,r],i)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.identityMat4();return t[0]=e[0],t[5]=e[1],t[10]=e[2],t},scalingMat3v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new Y(3);return function(t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,Z.scalingMat4v(e,i)}}(),scaleMat4c:function(e,t,n,r){return r[0]*=e,r[4]*=t,r[8]*=n,r[1]*=e,r[5]*=t,r[9]*=n,r[2]*=e,r[6]*=t,r[10]*=n,r[3]*=e,r[7]*=t,r[11]*=n,r},scaleMat4v:function(e,t){var n=e[0],r=e[1],i=e[2];return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,t},scalingMat4s:function(e){return Z.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.mat4(),r=e[0],i=e[1],a=e[2],s=e[3],o=r+r,l=i+i,u=a+a,c=r*o,f=r*l,p=r*u,A=i*l,d=i*u,v=a*u,h=s*o,I=s*l,y=s*u;return n[0]=1-(A+v),n[1]=f+y,n[2]=p-I,n[3]=0,n[4]=f-y,n[5]=1-(c+v),n[6]=d+h,n[7]=0,n[8]=p+I,n[9]=d-h,n[10]=1-(c+A),n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n},mat4ToEuler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=Z.clamp,i=e[0],a=e[4],s=e[8],o=e[1],l=e[5],u=e[9],c=e[2],f=e[6],p=e[10];return"XYZ"===t?(n[1]=Math.asin(r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(-u,p),n[2]=Math.atan2(-a,i)):(n[0]=Math.atan2(f,l),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(u,-1,1)),Math.abs(u)<.99999?(n[1]=Math.atan2(s,p),n[2]=Math.atan2(o,l)):(n[1]=Math.atan2(-c,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(f,-1,1)),Math.abs(f)<.99999?(n[1]=Math.atan2(-c,p),n[2]=Math.atan2(-a,l)):(n[1]=0,n[2]=Math.atan2(o,i))):"ZYX"===t?(n[1]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[0]=Math.atan2(f,p),n[2]=Math.atan2(o,i)):(n[0]=0,n[2]=Math.atan2(-a,l))):"YZX"===t?(n[2]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-u,l),n[1]=Math.atan2(-c,i)):(n[0]=0,n[1]=Math.atan2(s,p))):"XZY"===t&&(n[2]=Math.asin(-r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(f,l),n[1]=Math.atan2(s,i)):(n[0]=Math.atan2(-u,p),n[1]=0)),n},composeMat4:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Z.mat4();return Z.quaternionToRotationMat4(t,r),Z.scaleMat4v(n,r),Z.translateMat4v(e,r),r},decomposeMat4:function(){var e=new Y(3),t=new Y(16);return function(n,r,i,a){e[0]=n[0],e[1]=n[1],e[2]=n[2];var s=Z.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var o=Z.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var l=Z.lenVec3(e);Z.determinantMat4(n)<0&&(s=-s),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var u=1/s,c=1/o,f=1/l;return t[0]*=u,t[1]*=u,t[2]*=u,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=f,t[9]*=f,t[10]*=f,Z.mat4ToQuaternion(t,i),a[0]=s,a[1]=o,a[2]=l,this}}(),getColMat4:function(e,t){var n=4*t;return[e[n],e[n+1],e[n+2],e[n+3]]},setRowMat4:function(e,t,n){e[t]=n[0],e[t+4]=n[1],e[t+8]=n[2],e[t+12]=n[3]},lookAtMat4v:function(e,t,n,r){r||(r=Z.mat4());var i,a,s,o,l,u,c,f,p,A,d=e[0],v=e[1],h=e[2],I=n[0],y=n[1],m=n[2],w=t[0],g=t[1],T=t[2];return d===w&&v===g&&h===T?Z.identityMat4():(i=d-w,a=v-g,s=h-T,o=y*(s*=A=1/Math.sqrt(i*i+a*a+s*s))-m*(a*=A),l=m*(i*=A)-I*s,u=I*a-y*i,(A=Math.sqrt(o*o+l*l+u*u))?(o*=A=1/A,l*=A,u*=A):(o=0,l=0,u=0),c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,(A=Math.sqrt(c*c+f*f+p*p))?(c*=A=1/A,f*=A,p*=A):(c=0,f=0,p=0),r[0]=o,r[1]=c,r[2]=i,r[3]=0,r[4]=l,r[5]=f,r[6]=a,r[7]=0,r[8]=u,r[9]=p,r[10]=s,r[11]=0,r[12]=-(o*d+l*v+u*h),r[13]=-(c*d+f*v+p*h),r[14]=-(i*d+a*v+s*h),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,a,s,o,l){return Z.lookAtMat4v([e,t,n],[r,i,a],[s,o,l],[])},orthoMat4c:function(e,t,n,r,i,a,s){s||(s=Z.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2/l,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=-2/u,s[11]=0,s[12]=-(e+t)/o,s[13]=-(r+n)/l,s[14]=-(a+i)/u,s[15]=1,s},frustumMat4v:function(e,t,n){n||(n=Z.mat4());var r=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];Z.addVec4(i,r,X),Z.subVec4(i,r,q);var a=2*r[2],s=q[0],o=q[1],l=q[2];return n[0]=a/s,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=a/o,n[6]=0,n[7]=0,n[8]=X[0]/s,n[9]=X[1]/o,n[10]=-X[2]/l,n[11]=-1,n[12]=0,n[13]=0,n[14]=-a*i[2]/l,n[15]=0,n},frustumMat4:function(e,t,n,r,i,a,s){s||(s=Z.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2*i/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2*i/l,s[6]=0,s[7]=0,s[8]=(t+e)/o,s[9]=(r+n)/l,s[10]=-(a+i)/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i*2/u,s[15]=0,s},perspectiveMat4:function(e,t,n,r,i){var a=[],s=[];return a[2]=n,s[2]=r,s[1]=a[2]*Math.tan(e/2),a[1]=-s[1],s[0]=s[1]*t,a[0]=-s[0],Z.frustumMat4v(a,s,i)},compareMat4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]},transformPoint3:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec3(),r=t[0],i=t[1],a=t[2];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12],n[1]=e[1]*r+e[5]*i+e[9]*a+e[13],n[2]=e[2]*r+e[6]*i+e[10]*a+e[14],n},transformPoint4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4();return n[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],n[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],n[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],n[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],n},transformPoints3:function(e,t,n){for(var r,i,a,s,o,l=n||[],u=t.length,c=e[0],f=e[1],p=e[2],A=e[3],d=e[4],v=e[5],h=e[6],I=e[7],y=e[8],m=e[9],w=e[10],g=e[11],T=e[12],E=e[13],b=e[14],D=e[15],P=0;P2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2];e[3];var f=e[4],p=e[5],A=e[6];e[7];var d=e[8],v=e[9],h=e[10];e[11];var I=e[12],y=e[13],m=e[14];for(e[15],n=0;n2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n3&&void 0!==arguments[3]?arguments[3]:e,i=Math.cos(n),a=Math.sin(n),s=e[0]-t[0],o=e[1]-t[1];return r[0]=s*i-o*a+t[0],r[1]=s*a+o*i+t[1],e},rotateVec3X:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Y:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Z:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},projectVec4:function(e,t){var n=1/e[3];return(t=t||Z.vec2())[0]=e[0]*n,t[1]=e[1]*n,t},unprojectVec3:(x=new Y(16),M=new Y(16),F=new Y(16),function(e,t,n,r){return this.transformVec3(this.mulMat4(this.inverseMat4(t,x),this.inverseMat4(n,M),F),e,r)}),lerpVec3:function(e,t,n,r,i,a){var s=a||Z.vec3(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s},lerpMat4:function(e,t,n,r,i,a){var s=a||Z.mat4(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s[3]=r[3]+o*(i[3]-r[3]),s[4]=r[4]+o*(i[4]-r[4]),s[5]=r[5]+o*(i[5]-r[5]),s[6]=r[6]+o*(i[6]-r[6]),s[7]=r[7]+o*(i[7]-r[7]),s[8]=r[8]+o*(i[8]-r[8]),s[9]=r[9]+o*(i[9]-r[9]),s[10]=r[10]+o*(i[10]-r[10]),s[11]=r[11]+o*(i[11]-r[11]),s[12]=r[12]+o*(i[12]-r[12]),s[13]=r[13]+o*(i[13]-r[13]),s[14]=r[14]+o*(i[14]-r[14]),s[15]=r[15]+o*(i[15]-r[15]),s},flatten:function(e){var t,n,r,i,a,s=[];for(t=0,n=e.length;t0&&void 0!==arguments[0]?arguments[0]:Z.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=e[0]*Z.DEGTORAD/2,i=e[1]*Z.DEGTORAD/2,a=e[2]*Z.DEGTORAD/2,s=Math.cos(r),o=Math.cos(i),l=Math.cos(a),u=Math.sin(r),c=Math.sin(i),f=Math.sin(a);return"XYZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"YXZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"ZXY"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"ZYX"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"YZX"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l-u*c*f):"XZY"===t&&(n[0]=u*o*l-s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l+u*c*f),n},mat4ToQuaternion:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),r=e[0],i=e[4],a=e[8],s=e[1],o=e[5],l=e[9],u=e[2],c=e[6],f=e[10],p=r+o+f;return p>0?(t=.5/Math.sqrt(p+1),n[3]=.25/t,n[0]=(c-l)*t,n[1]=(a-u)*t,n[2]=(s-i)*t):r>o&&r>f?(t=2*Math.sqrt(1+r-o-f),n[3]=(c-l)/t,n[0]=.25*t,n[1]=(i+s)/t,n[2]=(a+u)/t):o>f?(t=2*Math.sqrt(1+o-r-f),n[3]=(a-u)/t,n[0]=(i+s)/t,n[1]=.25*t,n[2]=(l+c)/t):(t=2*Math.sqrt(1+f-r-o),n[3]=(s-i)/t,n[0]=(a+u)/t,n[1]=(l+c)/t,n[2]=.25*t),n},vec3PairToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=Math.sqrt(Z.dotVec3(e,e)*Z.dotVec3(t,t)),i=r+Z.dotVec3(e,t);return i<1e-8*r?(i=0,Math.abs(e[0])>Math.abs(e[2])?(n[0]=-e[1],n[1]=e[0],n[2]=0):(n[0]=0,n[1]=-e[2],n[2]=e[1])):Z.cross3Vec3(e,t,n),n[3]=i,Z.normalizeQuaternion(n)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),n=e[3]/2,r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},quaternionToEuler:function(){var e=new Y(16);return function(t,n,r){return r=r||Z.vec3(),Z.quaternionToRotationMat4(t,e),Z.mat4ToEuler(e,n,r),r}}(),mulQuaternions:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=e[0],i=e[1],a=e[2],s=e[3],o=t[0],l=t[1],u=t[2],c=t[3];return n[0]=s*o+r*c+i*u-a*l,n[1]=s*l+i*c+a*o-r*u,n[2]=s*u+a*c+r*l-i*o,n[3]=s*c-r*o-i*l-a*u,n},vec3ApplyQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec3(),r=t[0],i=t[1],a=t[2],s=e[0],o=e[1],l=e[2],u=e[3],c=u*r+o*a-l*i,f=u*i+l*r-s*a,p=u*a+s*i-o*r,A=-s*r-o*i-l*a;return n[0]=c*u+A*-s+f*-l-p*-o,n[1]=f*u+A*-o+p*-s-c*-l,n[2]=p*u+A*-l+c*-o-f*-s,n},quaternionToMat4:function(e,t){t=Z.identityMat4(t);var n=e[0],r=e[1],i=e[2],a=e[3],s=2*n,o=2*r,l=2*i,u=s*a,c=o*a,f=l*a,p=s*n,A=o*n,d=l*n,v=o*r,h=l*r,I=l*i;return t[0]=1-(v+I),t[1]=A+f,t[2]=d-c,t[4]=A-f,t[5]=1-(p+I),t[6]=h+u,t[8]=d+c,t[9]=h-u,t[10]=1-(p+v),t},quaternionToRotationMat4:function(e,t){var n=e[0],r=e[1],i=e[2],a=e[3],s=n+n,o=r+r,l=i+i,u=n*s,c=n*o,f=n*l,p=r*o,A=r*l,d=i*l,v=a*s,h=a*o,I=a*l;return t[0]=1-(p+d),t[4]=c-I,t[8]=f+h,t[1]=c+I,t[5]=1-(u+d),t[9]=A-v,t[2]=f-h,t[6]=A+v,t[10]=1-(u+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=Z.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n,t[3]=e[3]/n,t},conjugateQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},inverseQuaternion:function(e,t){return Z.normalizeQuaternion(Z.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),n=(e=Z.normalizeQuaternion(e,J))[3],r=2*Math.acos(n),i=Math.sqrt(1-n*n);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=r,t},AABB3:function(e){return new Y(e||6)},AABB2:function(e){return new Y(e||4)},OBB3:function(e){return new Y(e||32)},OBB2:function(e){return new Y(e||16)},Sphere3:function(e,t,n,r){return new Y([e,t,n,r])},transformOBB3:function(e,t){var n,r,i,a,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;no?s:o,a[1]+=l>u?l:u,a[2]+=c>f?c:f,Math.abs(Z.lenVec3(a))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var n=t||Z.vec3();return n[0]=(e[0]+e[3])/2,n[1]=(e[1]+e[4])/2,n[2]=(e[2]+e[5])/2,n},getAABB2Center:function(e,t){var n=t||Z.vec2();return n[0]=(e[2]+e[0])/2,n[1]=(e[3]+e[1])/2,n},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Z.AABB3();return e[0]=Z.MAX_DOUBLE,e[1]=Z.MAX_DOUBLE,e[2]=Z.MAX_DOUBLE,e[3]=Z.MIN_DOUBLE,e[4]=Z.MIN_DOUBLE,e[5]=Z.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.OBB3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t},positions3ToAABB3:function(){var e=new Y(3);return function(t,n,r){n=n||Z.AABB3();for(var i,a,s,o=Z.MAX_DOUBLE,l=Z.MAX_DOUBLE,u=Z.MAX_DOUBLE,c=Z.MIN_DOUBLE,f=Z.MIN_DOUBLE,p=Z.MIN_DOUBLE,A=0,d=t.length;Ac&&(c=i),a>f&&(f=a),s>p&&(p=s);return n[0]=o,n[1]=l,n[2]=u,n[3]=c,n[4]=f,n[5]=p,n}}(),OBB3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB3(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MAX_DOUBLE,l=Z.MIN_DOUBLE,u=Z.MIN_DOUBLE,c=Z.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB3(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MAX_DOUBLE,l=Z.MIN_DOUBLE,u=Z.MIN_DOUBLE,c=Z.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToSphere3:function(){var e=new Y(3);return function(t,n){n=n||Z.vec4();var r,i=0,a=0,s=0,o=t.length;for(r=0;ru&&(u=l);return n[3]=u,n}}(),positions3ToSphere3:function(){var e=new Y(3),t=new Y(3);return function(n,r){r=r||Z.vec4();var i,a=0,s=0,o=0,l=n.length,u=0;for(i=0;iu&&(u=c);return r[3]=u,r}}(),OBB3ToSphere3:function(){var e=new Y(3),t=new Y(3);return function(n,r){r=r||Z.vec4();var i,a=0,s=0,o=0,l=n.length,u=l/4;for(i=0;if&&(f=c);return r[3]=f,r}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},getPositionsCenter:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3(),n=0,r=0,i=0,a=0,s=e.length;at[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]n&&(e[0]=n),e[1]>r&&(e[1]=r),e[2]>i&&(e[2]=i),e[3]0&&void 0!==arguments[0]?arguments[0]:Z.AABB2();return e[0]=Z.MAX_DOUBLE,e[1]=Z.MAX_DOUBLE,e[2]=Z.MIN_DOUBLE,e[3]=Z.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(r=e[0]*n[0],i=e[0]*n[3]):(r=e[0]*n[3],i=e[0]*n[0]),e[1]>0?(r+=e[1]*n[1],i+=e[1]*n[4]):(r+=e[1]*n[4],i+=e[1]*n[1]),e[2]>0?(r+=e[2]*n[2],i+=e[2]*n[5]):(r+=e[2]*n[5],i+=e[2]*n[2]),r<=-t&&i<=-t?-1:r>=-t&&i>=-t?1:0},OBB3ToAABB2:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB2(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MIN_DOUBLE,l=Z.MIN_DOUBLE,u=0,c=e.length;uo&&(o=t),n>l&&(l=n);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i},expandAABB2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]3&&void 0!==arguments[3]?arguments[3]:e,i=.5*(e[0]+1),a=.5*(e[1]+1),s=.5*(e[2]+1),o=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(o*n),r[2]=Math.floor(s*t),r[3]=n-Math.floor(a*n),r},tangentQuadraticBezier:function(e,t,n,r){return 2*(1-e)*(n-t)+2*e*(r-n)},tangentQuadraticBezier3:function(e,t,n,r,i){return-3*t*(1-e)*(1-e)+3*n*(1-e)*(1-e)-6*e*n*(1-e)+6*e*r*(1-e)-3*e*e*r+3*e*e*i},tangentSpline:function(e){return 6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e)},catmullRomInterpolate:function(e,t,n,r,i){var a=.5*(n-e),s=.5*(r-t),o=i*i;return(2*t-2*n+a+s)*(i*o)+(-3*t+3*n-2*a-s)*o+a*i+t},b2p0:function(e,t){var n=1-e;return n*n*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,n,r){return this.b2p0(e,t)+this.b2p1(e,n)+this.b2p2(e,r)},b3p0:function(e,t){var n=1-e;return n*n*n*t},b3p1:function(e,t){var n=1-e;return 3*n*n*e*t},b3p2:function(e,t){return 3*(1-e)*e*e*t},b3p3:function(e,t){return e*e*e*t},b3:function(e,t,n,r,i){return this.b3p0(e,t)+this.b3p1(e,n)+this.b3p2(e,r)+this.b3p3(e,i)},triangleNormal:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Z.vec3(),i=t[0]-e[0],a=t[1]-e[1],s=t[2]-e[2],o=n[0]-e[0],l=n[1]-e[1],u=n[2]-e[2],c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,A=Math.sqrt(c*c+f*f+p*p);return 0===A?(r[0]=0,r[1]=0,r[2]=0):(r[0]=c/A,r[1]=f/A,r[2]=p/A),r},rayTriangleIntersect:function(){var e=new Y(3),t=new Y(3),n=new Y(3),r=new Y(3),i=new Y(3);return function(a,s,o,l,u,c){c=c||Z.vec3();var f=Z.subVec3(l,o,e),p=Z.subVec3(u,o,t),A=Z.cross3Vec3(s,p,n),d=Z.dotVec3(f,A);if(d<1e-6)return null;var v=Z.subVec3(a,o,r),h=Z.dotVec3(v,A);if(h<0||h>d)return null;var I=Z.cross3Vec3(v,f,i),y=Z.dotVec3(s,I);if(y<0||h+y>d)return null;var m=Z.dotVec3(p,I)/d;return c[0]=a[0]+m*s[0],c[1]=a[1]+m*s[1],c[2]=a[2]+m*s[2],c}}(),rayPlaneIntersect:function(){var e=new Y(3),t=new Y(3),n=new Y(3),r=new Y(3);return function(i,a,s,o,l,u){u=u||Z.vec3(),a=Z.normalizeVec3(a,e);var c=Z.subVec3(o,s,t),f=Z.subVec3(l,s,n),p=Z.cross3Vec3(c,f,r);Z.normalizeVec3(p,p);var A=-Z.dotVec3(s,p),d=-(Z.dotVec3(i,p)+A)/Z.dotVec3(a,p);return u[0]=i[0]+d*a[0],u[1]=i[1]+d*a[1],u[2]=i[2]+d*a[2],u}}(),cartesianToBarycentric:function(){var e=new Y(3),t=new Y(3),n=new Y(3);return function(r,i,a,s,o){var l=Z.subVec3(s,i,e),u=Z.subVec3(a,i,t),c=Z.subVec3(r,i,n),f=Z.dotVec3(l,l),p=Z.dotVec3(l,u),A=Z.dotVec3(l,c),d=Z.dotVec3(u,u),v=Z.dotVec3(u,c),h=f*d-p*p;if(0===h)return null;var I=1/h,y=(d*A-p*v)*I,m=(f*v-p*A)*I;return o[0]=1-y-m,o[1]=m,o[2]=y,o}}(),barycentricInsideTriangle:function(e){var t=e[1],n=e[2];return n>=0&&t>=0&&n+t<1},barycentricToCartesian:function(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Z.vec3(),a=e[0],s=e[1],o=e[2];return i[0]=t[0]*a+n[0]*s+r[0]*o,i[1]=t[1]*a+n[1]*s+r[1]*o,i[2]=t[2]*a+n[2]*s+r[2]*o,i},mergeVertices:function(e,t,n,r){var i,a,s,o,l,u,c={},f=[],p=[],A=t?[]:null,d=n?[]:null,v=[],h=Math.pow(10,4),I=0;for(l=0,u=e.length;l>24&255,s=f>>16&255,a=f>>8&255,i=255&f,r=3*t[d],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+1],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+2],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,f++;return{positions:u,colors:c}},faceToVertexNormals:function(e,t){var n,r,i,a,s,o,l,u,c,f,p,A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},d=A.smoothNormalsAngleThreshold||20,v={},h=[],I={},y=4,m=Math.pow(10,y);for(l=0,c=e.length;ll[3]&&(l[3]=i[p]),i[p+1]l[4]&&(l[4]=i[p+1]),i[p+2]l[5]&&(l[5]=i[p+2])}if(n.length<20||a>10)return u.triangles=n,u.leaf=!0,u;e[0]=l[3]-l[0],e[1]=l[4]-l[1],e[2]=l[5]-l[2];var A=0;e[1]>e[A]&&(A=1),e[2]>e[A]&&(A=2),u.splitDim=A;var d=(l[A]+l[A+3])/2,v=new Array(n.length),h=0,I=new Array(n.length),y=0;for(s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t},octDecodeVec2s:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t}};Z.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var $=function(){function e(){b(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return P(e,[{key:"length",get:function(){return this._length}},{key:"shift",value:function(){if(this._index>=this._headLength){var e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}var t=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,t}},{key:"push",value:function(e){return this._length++,this._tail.push(e),this}},{key:"unshift",value:function(e){return this._head[--this._index]=e,this._length++,this}}]),e}(),ee={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var te=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],n=e[0].charCodeAt(0),r=n+e[1],i=n;i0&&void 0!==arguments[0]?arguments[0]:-1,r=(new Date).getTime(),i=0;le.length>0&&(n<0||r0&&ie>0){var n=1e3/ie;pe+=n,ce.push(n),ce.length>=30&&(pe-=ce.shift()),ee.frame.fps=Math.round(pe/ce.length)}!function(e){var t=Ae.runTasks(e+10),n=Ae.getNumTasks();ee.frame.tasksRun=t,ee.frame.tasksScheduled=n,ee.frame.tasksBudget=10}(t),function(e){for(var t in ue.time=e,Ae.scenes)if(Ae.scenes.hasOwnProperty(t)){var n=Ae.scenes[t];ue.sceneId=t,ue.startTime=n.startTime,ue.deltaTime=null!=ue.prevTime?ue.time-ue.prevTime:0,n.fire("tick",ue,!0)}ue.prevTime=e}(t),function(){var e,t,n,r,i,a=Ae.scenes,s=!1;for(i in a)a.hasOwnProperty(i)&&(e=a[i],(t=se[i])||(t=se[i]={}),n=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==n&&(t.ticksPerOcclusionTest=n,t.renderCountdown=n),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=n),r=e.ticksPerRender,t.ticksPerRender!==r&&(t.ticksPerRender=r,t.renderCountdown=r),0==--t.renderCountdown&&(e.render(s),t.renderCountdown=r))}(),fe=t,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(e):requestAnimationFrame(e)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(de):requestAnimationFrame(de);var ve=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=n.viewer;else{if("Scene"===t.type)this.scene=t;else{if(!(t instanceof e))throw"Invalid param: owner must be a Component";this.scene=t.scene}this._owner=t}this._dontClear=!!n.dontClear,this._renderer=this.scene._renderer,this.meta=n.meta||{},this.id=n.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,t&&t._own(this)}return P(e,[{key:"type",get:function(){return"Component"}},{key:"isComponent",get:function(){return!0}},{key:"glRedraw",value:function(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}},{key:"glResort",value:function(){this._renderer&&this._renderer.needStateSort()}},{key:"owner",get:function(){return this._owner}},{key:"isType",value:function(e){return this.type===e}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}},{key:"_message",value:function(e){return" ["+this.type+" "+ae.inQuotes(this.id)+"]: "+e}},{key:"warn",value:function(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}},{key:"error",value:function(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}},{key:"_attach",value:function(e){var t=e.name;if(t){var n=e.component,r=e.sceneDefault,i=e.sceneSingleton,a=e.type,s=e.on,o=!1!==e.recompiles;if(n&&(ae.isNumeric(n)||ae.isString(n))){var l=n;if(!(n=this.scene.components[l]))return void this.error("Component not found: "+ae.inQuotes(l))}if(!n)if(!0===i){var u=this.scene.types[a];for(var c in u)if(u.hasOwnProperty){n=u[c];break}if(!n)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===r&&!(n=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(n){if(n.scene.id!==this.scene.id)return void this.error("Not in same scene: "+n.type+" "+ae.inQuotes(n.id));if(a&&!n.isType(a))return void this.error("Expected a "+a+" type or subtype: "+n.type+" "+ae.inQuotes(n.id))}this._attachments||(this._attachments={});var f,p,A,d=this._attached[t];if(d){if(n&&d.id===n.id)return;var v=this._attachments[d.id];for(p=0,A=(f=v.subs).length;p3&&void 0!==arguments[3]?arguments[3]:1e3,i=Z.getPositionsCenter(e,he),a=Math.round(i[0]/r)*r,s=Math.round(i[1]/r)*r,o=Math.round(i[2]/r)*r;n[0]=a,n[1]=s,n[2]=o;var l=0!==n[0]||0!==n[1]||0!==n[2];if(l)for(var u=0,c=e.length;u0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,n=this.meshes[0]._colorize[3],r=255;if(t){if(e<0?e=0:e>1&&(e=1),n===(r=Math.floor(255*e)))return}else if(n===(r=255))return;for(var i=0,a=this.meshes.length;i1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._color=r.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=r.thickness||1,this._thicknessClickable=r.thicknessClickable||6;var i=this._wire,a=i.style;a.border="solid "+this._thickness+"px "+this._color,a.position="absolute",a["z-index"]=void 0===r.zIndex?"2000001":r.zIndex,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._wireClickable,o=s.style;o.border="solid "+this._thicknessClickable+"px "+this._color,o.position="absolute",o["z-index"]=void 0===r.zIndex?"2000002":r.zIndex+1,o.width="0px",o.height="0px",o.visibility="visible",o.top="0px",o.left="0px",o["-webkit-transform-origin"]="0 0",o["-moz-transform-origin"]="0 0",o["-ms-transform-origin"]="0 0",o["-o-transform-origin"]="0 0",o["transform-origin"]="0 0",o["-webkit-transform"]="rotate(0deg)",o["-moz-transform"]="rotate(0deg)",o["-ms-transform"]="rotate(0deg)",o["-o-transform"]="rotate(0deg)",o.transform="rotate(0deg)",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}return P(e,[{key:"_visible",get:function(){return"visible"===this._wire.style.visibility}},{key:"_update",value:function(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,n=this._wire.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)";var r=this._wireClickable.style;r.width=Math.round(e)+"px",r.left=Math.round(this._x1)+"px",r.top=Math.round(this._y1)+"px",r["-webkit-transform"]="rotate("+t+"deg)",r["-moz-transform"]="rotate("+t+"deg)",r["-ms-transform"]="rotate("+t+"deg)",r["-o-transform"]="rotate("+t+"deg)",r.transform="rotate("+t+"deg)"}},{key:"setStartAndEnd",value:function(e,t,n,r){this._x1=e,this._y1=t,this._x2=n,this._y2=r,this._update()}},{key:"setColor",value:function(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}},{key:"setOpacity",value:function(e){this._wire.style.opacity=e}},{key:"setVisible",value:function(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}},{key:"setClickable",value:function(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}},{key:"destroy",value:function(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}]),e}(),He=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var i=this._dot,a=i.style;a["border-radius"]="25px",a.border="solid 2px white",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"40000005":r.zIndex,a.width="8px",a.height="8px",a.visibility=!1!==r.visible?"visible":"hidden",a.top="0px",a.left="0px",a["box-shadow"]="0 2px 5px 0 #182A3D;",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._dotClickable,o=s.style;o["border-radius"]="35px",o.border="solid 10px white",o.position="absolute",o["z-index"]=void 0===r.zIndex?"40000007":r.zIndex+1,o.width="8px",o.height="8px",o.visibility="visible",o.top="0px",o.left="0px",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.borderColor)}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._dot.style;n.left=Math.round(e)-4+"px",n.top=Math.round(t)-4+"px";var r=this._dotClickable.style;r.left=Math.round(e)-9+"px",r.top=Math.round(t)-9+"px"}},{key:"setFillColor",value:function(e){this._dot.style.background=e||"lightgreen"}},{key:"setBorderColor",value:function(e){this._dot.style.border="solid 2px"+(e||"black")}},{key:"setOpacity",value:function(e){this._dot.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}},{key:"setClickable",value:function(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}},{key:"destroy",value:function(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}]),e}(),Ue=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-label-highlighted",this._prefix=r.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var i=this._label,a=i.style;a["border-radius"]="5px",a.color="white",a.padding="4px",a.border="solid 1px",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"5000005":r.zIndex,a.width="auto",a.height="auto",a.visibility="visible",a.top="0px",a.left="0px",a["pointer-events"]="all",a.opacity=1,r.onContextMenu,i.innerText="",t.appendChild(i),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.fillColor),this.setText(r.text),r.onMouseOver&&i.addEventListener("mouseover",(function(e){r.onMouseOver(e,n),e.preventDefault()})),r.onMouseLeave&&i.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n),e.preventDefault()})),r.onMouseWheel&&i.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&i.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()}))}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._label.style;n.left=Math.round(e)-20+"px",n.top=Math.round(t)-12+"px"}},{key:"setPosOnWire",value:function(e,t,n,r){var i=e+.5*(n-e),a=t+.5*(r-t),s=this._label.style;s.left=Math.round(i)-20+"px",s.top=Math.round(a)-12+"px"}},{key:"setPosBetweenWires",value:function(e,t,n,r,i,a){var s=(e+n+i)/3,o=(t+r+a)/3,l=this._label.style;l.left=Math.round(s)-20+"px",l.top=Math.round(o)-12+"px"}},{key:"setText",value:function(e){this._label.innerHTML=this._prefix+(e||"")}},{key:"setFillColor",value:function(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}},{key:"setBorderColor",value:function(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}},{key:"setOpacity",value:function(e){this._label.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}},{key:"setClickable",value:function(e){this._label.style["pointer-events"]=e?"all":"none"}},{key:"destroy",value:function(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}]),e}(),Ge=Z.vec3(),ke=Z.vec3(),Ve=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._color=i.color||e.defaultColor;var a=r.plugin.viewer.scene;r._originMarker=new Me(a,i.origin),r._cornerMarker=new Me(a,i.corner),r._targetMarker=new Me(a,i.target),r._originWorld=Z.vec3(),r._cornerWorld=Z.vec3(),r._targetWorld=Z.vec3(),r._wp=new Float64Array(12),r._vp=new Float64Array(12),r._pp=new Float64Array(12),r._cp=new Int16Array(6);var s=i.onMouseOver?function(e){i.onMouseOver(e,g(r))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,g(r))}:null,l=i.onContextMenu?function(e){i.onContextMenu(e,g(r))}:null,u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._cornerDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._originWire=new Fe(r._container,{color:r._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetWire=new Fe(r._container,{color:r._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._angleLabel=new Ue(r._container,{fillColor:r._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._visible=!1,r._originVisible=!1,r._cornerVisible=!1,r._targetVisible=!1,r._originWireVisible=!1,r._targetWireVisible=!1,r._angleVisible=!1,r._labelsVisible=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._cornerMarker.on("worldPos",(function(e){r._cornerWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.cornerVisible=i.cornerVisible,r.targetVisible=i.targetVisible,r.originWireVisible=i.originWireVisible,r.targetWireVisible=i.targetWireVisible,r.angleVisible=i.angleVisible,r.labelsVisible=i.labelsVisible,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(Z.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){var t=-.3,n=this._originMarker.viewPos[2],r=this._cornerMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(n>t||r>t||i>t)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);Z.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var a=this._pp,s=this._cp,o=e.canvas.canvas.getBoundingClientRect(),l=this._container.getBoundingClientRect(),u=o.top-l.top,c=o.left-l.left,f=e.canvas.boundary,p=f[2],A=f[3],d=0,v=0,h=a.length;vt+5||r[0]n+5||r[1]p[0]+5||A[0]p[1]+5||A[1]1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"AngleMeasurements",e))._container=i.container||document.body,r._control=new je(g(r)),r._measurements={},r.defaultColor=void 0!==i.defaultColor?i.defaultColor:"#00BBFF",r.defaultLabelsVisible=!1!==i.defaultLabelsVisible,r.zIndex=i.zIndex||1e4,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"control",get:function(){return this._control}},{key:"measurements",get:function(){return this._measurements}},{key:"createMeasurement",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.viewer.scene.components[t.id]&&(this.error("Viewer scene component with this ID already exists: "+t.id),delete t.id);var n=t.origin,r=t.corner,i=t.target,a=new Ve(this,{id:t.id,plugin:this,container:this._container,origin:{entity:n.entity,worldPos:n.worldPos},corner:{entity:r.entity,worldPos:r.worldPos},target:{entity:i.entity,worldPos:i.worldPos},visible:t.visible,originVisible:!0,originWireVisible:!0,cornerVisible:!0,targetWireVisible:!0,targetVisible:!0,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[a.id]=a,a.on("destroyed",(function(){delete e._measurements[a.id]})),this.fire("measurementCreated",a),a}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("AngleMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,n=Object.entries(this.measurements);t

";ae.isArray(t)&&(t=t.join("")),t=this._renderTemplate(t);var n=document.createRange().createContextualFragment(t);this._marker=n.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(function(){e.plugin.fire("markerClicked",e)})),this._marker.addEventListener("mouseenter",(function(){e.plugin.fire("markerMouseEnter",e)})),this._marker.addEventListener("mouseleave",(function(){e.plugin.fire("markerMouseLeave",e)})),this._marker.addEventListener("wheel",(function(t){e.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",t))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);var r=this._labelHTML||"

";ae.isArray(r)&&(r=r.join("")),r=this._renderTemplate(r);var i=document.createRange().createContextualFragment(r);this._label=i.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(function(t){e.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",t))}))}}},{key:"_updatePosition",value:function(){var e=this.scene.canvas.boundary,t=e[0],n=e[1],r=this.canvasPos;this._marker.style.left=Math.floor(t+r[0])-12+"px",this._marker.style.top=Math.floor(n+r[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+r[0]+20)+"px",this._label.style.top=Math.floor(n+r[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}},{key:"_renderTemplate",value:function(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){var n=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),n)}return e}},{key:"setMarkerShown",value:function(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}},{key:"getMarkerShown",value:function(){return this._markerShown}},{key:"setLabelShown",value:function(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}},{key:"getLabelShown",value:function(){return this._labelShown}},{key:"setField",value:function(e,t){this._values[e]=t||"",this._htmlDirty=!0}},{key:"getField",value:function(e){return this._values[e]}},{key:"setValues",value:function(e){for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];this.setField(t,n)}}},{key:"getValues",value:function(){return this._values}},{key:"destroy",value:function(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Ke=Z.vec3(),Ye=Z.vec3(),Xe=Z.vec3(),qe=function(e){I(n,z);var t=m(n);function n(e,r){var i;return b(this,n),(i=t.call(this,"Annotations",e))._labelHTML=r.labelHTML||"
",i._markerHTML=r.markerHTML||"
",i._container=r.container||document.body,i._values=r.values||{},i.annotations={},i.surfaceOffset=r.surfaceOffset,i}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){if("clearAnnotations"===e)this.clear()}},{key:"surfaceOffset",get:function(){return this._surfaceOffset},set:function(e){null==e&&(e=.3),this._surfaceOffset=e}},{key:"createAnnotation",value:function(e){var t,n,r=this;if(this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id),e.pickResult=e.pickResult||e.pickRecord,e.pickResult){var i=e.pickResult;if(i.worldPos&&i.worldNormal){var a=Z.normalizeVec3(i.worldNormal,Ke),s=Z.mulVec3Scalar(a,this._surfaceOffset,Ye);t=Z.addVec3(i.worldPos,s,Xe),n=i.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,n=e.entity;var o=null;e.markerElementId&&((o=document.getElementById(e.markerElementId))||this.error("Can't find DOM element for 'markerElementId' value '"+e.markerElementId+"' - defaulting to internally-generated empty DIV"));var l=null;e.labelElementId&&((l=document.getElementById(e.labelElementId))||this.error("Can't find DOM element for 'labelElementId' value '"+e.labelElementId+"' - defaulting to internally-generated empty DIV"));var u=new ze(this.viewer.scene,{id:e.id,plugin:this,entity:n,worldPos:t,container:this._container,markerElement:o,labelElement:l,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:ae.apply(e.values,ae.apply(this._values,{})),markerShown:e.markerShown,labelShown:e.labelShown,eye:e.eye,look:e.look,up:e.up,projection:e.projection,visible:!1!==e.visible});return this.annotations[u.id]=u,u.on("destroyed",(function(){delete r.annotations[u.id],r.fire("annotationDestroyed",u.id)})),this.fire("annotationCreated",u.id),u}},{key:"destroyAnnotation",value:function(e){var t=this.annotations[e];t?t.destroy():this.log("Annotation not found: "+e)}},{key:"clear",value:function(){for(var e=Object.keys(this.annotations),t=0,n=e.length;t1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._canvas=i.canvas,r._element=null,r._isCustom=!1,i.elementId&&(r._element=document.getElementById(i.elementId),r._element?r._adjustPosition():r.error("Can't find given Spinner HTML element: '"+i.elementId+"' - will automatically create default element")),r._element||r._createDefaultSpinner(),r.processes=0,r}return P(n,[{key:"type",get:function(){return"Spinner"}},{key:"_createDefaultSpinner",value:function(){this._injectDefaultCSS();var e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}},{key:"_injectDefaultCSS",value:function(){var e="xeokit-spinner-css";if(!document.getElementById(e)){var t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}}},{key:"_adjustPosition",value:function(){if(!this._isCustom){var e=this._canvas,t=this._element,n=t.style;n.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",n.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}}},{key:"processes",get:function(){return this._processes},set:function(e){if(e=e||0,this._processes!==e&&!(e<0)){var t=this._processes;this._processes=e;var n=this._element;n&&(n.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}}},{key:"_destroy",value:function(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);var e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}]),n}(),Ze={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},$e=document.createElement("canvas");if($e){var et=$e.getContext("webgl",{antialias:!0})||$e.getContext("experimental-webgl",{antialias:!0});Ze.WEBGL=!!et,Ze.WEBGL&&(Ze.ANTIALIAS=et.getContextAttributes().antialias,et.getShaderPrecisionFormat?et.getShaderPrecisionFormat(et.FRAGMENT_SHADER,et.HIGH_FLOAT).precision>0?Ze.FS_MAX_FLOAT_PRECISION="highp":et.getShaderPrecisionFormat(et.FRAGMENT_SHADER,et.MEDIUM_FLOAT).precision>0?Ze.FS_MAX_FLOAT_PRECISION="mediump":Ze.FS_MAX_FLOAT_PRECISION="lowp":Ze.FS_MAX_FLOAT_PRECISION="mediump",Ze.DEPTH_BUFFER_BITS=et.getParameter(et.DEPTH_BITS),Ze.MAX_TEXTURE_SIZE=et.getParameter(et.MAX_TEXTURE_SIZE),Ze.MAX_CUBE_MAP_SIZE=et.getParameter(et.MAX_CUBE_MAP_TEXTURE_SIZE),Ze.MAX_RENDERBUFFER_SIZE=et.getParameter(et.MAX_RENDERBUFFER_SIZE),Ze.MAX_TEXTURE_UNITS=et.getParameter(et.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Ze.MAX_TEXTURE_IMAGE_UNITS=et.getParameter(et.MAX_TEXTURE_IMAGE_UNITS),Ze.MAX_VERTEX_ATTRIBS=et.getParameter(et.MAX_VERTEX_ATTRIBS),Ze.MAX_VERTEX_UNIFORM_VECTORS=et.getParameter(et.MAX_VERTEX_UNIFORM_VECTORS),Ze.MAX_FRAGMENT_UNIFORM_VECTORS=et.getParameter(et.MAX_FRAGMENT_UNIFORM_VECTORS),Ze.MAX_VARYING_VECTORS=et.getParameter(et.MAX_VARYING_VECTORS),et.getSupportedExtensions().forEach((function(e){Ze.SUPPORTED_EXTENSIONS[e]=!0})))}var tt=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],nt=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))._backgroundColor=Z.vec3([i.backgroundColor?i.backgroundColor[0]:1,i.backgroundColor?i.backgroundColor[1]:1,i.backgroundColor?i.backgroundColor[2]:1]),r._backgroundColorFromAmbientLight=!!i.backgroundColorFromAmbientLight,r.canvas=i.canvas,r.gl=null,r.webgl2=!1,r.transparent=!!i.transparent,r.contextAttr=i.contextAttr||{},r.contextAttr.alpha=r.transparent,r.contextAttr.preserveDrawingBuffer=!!r.contextAttr.preserveDrawingBuffer,r.contextAttr.stencil=!1,r.contextAttr.premultipliedAlpha=!!r.contextAttr.premultipliedAlpha,r.contextAttr.antialias=!1!==r.contextAttr.antialias,r.resolutionScale=i.resolutionScale,r.canvas.width=Math.round(r.canvas.clientWidth*r._resolutionScale),r.canvas.height=Math.round(r.canvas.clientHeight*r._resolutionScale),r.boundary=[r.canvas.offsetLeft,r.canvas.offsetTop,r.canvas.clientWidth,r.canvas.clientHeight],r._initWebGL(i);var a=g(r);r.canvas.addEventListener("webglcontextlost",r._webglcontextlostListener=function(e){console.time("webglcontextrestored"),a.scene._webglContextLost(),a.fire("webglcontextlost"),e.preventDefault()},!1),r.canvas.addEventListener("webglcontextrestored",r._webglcontextrestoredListener=function(e){a._initWebGL(),a.gl&&(a.scene._webglContextRestored(a.gl),a.fire("webglcontextrestored",a.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);var s=!0,o=new ResizeObserver((function(e){var t,n=f(e);try{for(n.s();!(t=n.n()).done;){t.value.contentBoxSize&&(s=!0)}}catch(e){n.e(e)}finally{n.f()}}));return o.observe(r.canvas),r._tick=r.scene.on("tick",(function(){s&&(s=!1,a.canvas.width=Math.round(a.canvas.clientWidth*a._resolutionScale),a.canvas.height=Math.round(a.canvas.clientHeight*a._resolutionScale),a.boundary[0]=a.canvas.offsetLeft,a.boundary[1]=a.canvas.offsetTop,a.boundary[2]=a.canvas.clientWidth,a.boundary[3]=a.canvas.clientHeight,a.fire("boundary",a.boundary))})),r._spinner=new Je(r.scene,{canvas:r.canvas,elementId:i.spinnerElementId}),r}return P(n,[{key:"type",get:function(){return"Canvas"}},{key:"backgroundColorFromAmbientLight",get:function(){return this._backgroundColorFromAmbientLight},set:function(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}},{key:"resolutionScale",get:function(){return this._resolutionScale},set:function(e){if((e=e||1)!==this._resolutionScale){this._resolutionScale=e;var t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}}},{key:"spinner",get:function(){return this._spinner}},{key:"_createCanvas",value:function(){var e="xeokit-canvas-"+Z.createUUID(),t=document.getElementsByTagName("body")[0],n=document.createElement("div"),r=n.style;r.height="100%",r.width="100%",r.padding="0",r.margin="0",r.background="rgba(0,0,0,0);",r.float="left",r.left="0",r.top="0",r.position="absolute",r.opacity="1.0",r["z-index"]="-10000",n.innerHTML+='',t.appendChild(n),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,n=0;e;)t+=e.offsetLeft-e.scrollLeft,n+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:n}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e0&&"/"===t.charAt(n+1)&&(t=t.substring(0,n)),r.push(t);return r.join("\n")}function ct(e){console.error(e.join("\n"))}var ft=function(){function e(t,n){b(this,e),this.id=lt.addItem({}),this.source=n,this.init(t)}return P(e,[{key:"init",value:function(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new at(e,e.VERTEX_SHADER,ut(this.source.vertex)),this._fragmentShader=new at(e,e.FRAGMENT_SHADER,ut(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void ct(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void ct(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void ct(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void ct(this.errors);var t,n,r,i,a;if(this.compiled=!0,this.handle=e.createProgram(),this.handle){if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void ct(this.errors);var s=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(n=0;nthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}},{key:"setData",value:function(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}},{key:"bind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}},{key:"unbind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,null)}},{key:"destroy",value:function(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}]),e}(),At=function(){function e(t,n){b(this,e),this.scene=t,this.aabb=Z.AABB3(),this.origin=Z.vec3(n),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}return P(e,[{key:"addMarker",value:function(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}},{key:"markerWorldPosUpdated",value:function(e){if(this.markers[e.id]){var t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}}},{key:"removeMarker",value:function(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}},{key:"update",value:function(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}},{key:"_buildMarkerList",value:function(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}},{key:"_buildPositions",value:function(){for(var e=0,t=0;t-t)o._setVisible(!1);else{var l=o.canvasPos,u=l[0],c=l[1];u+10<0||c+10<0||u-10>r||c-10>i?o._setVisible(!1):!o.entity||o.entity.visible?o.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=o,this.pixels[a++]=u,this.pixels[a++]=c):o._setVisible(!0):o._setVisible(!1)}}}},{key:"_updateActiveSectionPlanes",value:function(){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n0,n=[];return n.push("#version 300 es"),n.push("// OcclusionTester vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("vec4 worldPosition = vec4(position, 1.0); "),n.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&n.push(" vWorldPosition = worldPosition;"),n.push(" vec4 clipPos = projMatrix * viewPosition;"),n.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?n.push("vFragDepth = 1.0 + clipPos.w;"):n.push("clipPos.z += -0.001;"),n.push(" gl_Position = clipPos;"),n.push("}"),n}},{key:"_buildFragmentShaderSource",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// OcclusionTester fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;");for(var i=0;i 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),r.push("}"),r}},{key:"_buildProgram",value:function(){this._program&&this._program.destroy();var e=this._scene,t=e.canvas.gl,n=e._sectionPlanesState;if(this._program=new ft(t,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=n.sectionPlanes.length;i0)for(var p=r.sectionPlanes,A=0;A= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var r=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new pt(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),this._uvBuf=new pt(n,n.ARRAY_BUFFER,r,r.length,2,n.STATIC_DRAW),this._indicesBuf=new pt(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}}},{key:"destroy",value:function(){this._program&&(this._program.destroy(),this._program=null)}}]),e}(),mt=new Float32Array(Dt(17,[0,1])),wt=new Float32Array(Dt(17,[1,0])),gt=new Float32Array(function(e,t){for(var n=[],r=0;r<=e;r++)n.push(bt(r,t));return n}(17,4)),Tt=new Float32Array(2),Et=function(){function e(t){b(this,e),this._scene=t,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}return P(e,[{key:"init",value:function(){var e=this._scene.canvas.gl;if(this._program=new ft(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS ".concat(16,"\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var t=new Float32Array([1,1,0,1,0,0,1,0]),n=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),r=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new pt(e,e.ARRAY_BUFFER,n,n.length,3,e.STATIC_DRAW),this._uvBuf=new pt(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new pt(e,e.ELEMENT_ARRAY_BUFFER,r,r.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}},{key:"render",value:function(e,t,n){var r=this;if(!this._programError){this._getInverseProjectMat||(this._getInverseProjectMat=function(){var e=!0;r._scene.camera.on("projMatrix",(function(){e=!0}));var t=Z.mat4();return function(){return e&&Z.inverseMat4(s.camera.projMatrix,t),t}}());var i=this._scene.canvas.gl,a=this._program,s=this._scene,o=i.drawingBufferWidth,l=i.drawingBufferHeight,u=s.camera.project._state,c=u.near,f=u.far;i.viewport(0,0,o,l),i.clearColor(0,0,0,1),i.enable(i.DEPTH_TEST),i.disable(i.BLEND),i.frontFace(i.CCW),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),a.bind(),Tt[0]=o,Tt[1]=l,i.uniform2fv(this._uViewport,Tt),i.uniform1f(this._uCameraNear,c),i.uniform1f(this._uCameraFar,f),i.uniform1f(this._uDepthCutoff,.01),0===n?i.uniform2fv(this._uSampleOffsets,wt):i.uniform2fv(this._uSampleOffsets,mt),i.uniform1fv(this._uSampleWeights,gt);var p=e.getDepthTexture(),A=t.getTexture();a.bindTexture(this._uDepthTexture,p,0),a.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),i.drawElements(i.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}}},{key:"destroy",value:function(){this._program.destroy()}}]),e}();function bt(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function Dt(e,t){for(var n=[],r=0;r<=e;r++)n.push(t[0]*r),n.push(t[1]*r);return n}var Pt=function(){function e(t,n,r){b(this,e),r=r||{},this.gl=n,this.allocated=!1,this.canvas=t,this.buffer=null,this.bound=!1,this.size=r.size,this._hasDepthTexture=!!r.depthTexture}return P(e,[{key:"setSize",value:function(e){this.size=e}},{key:"webglContextRestored",value:function(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}},{key:"bind",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(this._touch(e),!this.bound){var t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"_touch",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=this.gl;if(this.size?(e=this.size[0],t=this.size[1]):(e=r.drawingBufferWidth,t=r.drawingBufferHeight),this.buffer){if(this.buffer.width===e&&this.buffer.height===t)return;r.deleteTexture(this.buffer.texture),r.deleteFramebuffer(this.buffer.framebuf),r.deleteRenderbuffer(this.buffer.renderbuf)}var i,a=r.createTexture();r.bindTexture(r.TEXTURE_2D,a),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),n?r.texStorage2D(r.TEXTURE_2D,1,n,e,t):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),this._hasDepthTexture&&(i=r.createTexture(),r.bindTexture(r.TEXTURE_2D,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.DEPTH_COMPONENT32F,e,t,0,r.DEPTH_COMPONENT,r.FLOAT,null));var s=r.createRenderbuffer();r.bindRenderbuffer(r.RENDERBUFFER,s),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT32F,e,t);var o=r.createFramebuffer();if(r.bindFramebuffer(r.FRAMEBUFFER,o),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,a,0),this._hasDepthTexture?r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,i,0):r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,s),r.bindTexture(r.TEXTURE_2D,null),r.bindRenderbuffer(r.RENDERBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,o),!r.isFramebuffer(o))throw"Invalid framebuffer";r.bindFramebuffer(r.FRAMEBUFFER,null);var l=r.checkFramebufferStatus(r.FRAMEBUFFER);switch(l){case r.FRAMEBUFFER_COMPLETE:break;case r.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case r.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+l}this.buffer={framebuf:o,renderbuf:s,texture:a,depthTexture:i,width:e,height:t},this.bound=!1}},{key:"clear",value:function(){if(!this.bound)throw"Render buffer not bound";var e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}},{key:"read",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,s=e,o=(this.buffer.height||this.gl.drawingBufferHeight)-t,l=new i(a),u=this.gl;return u.readPixels(s,o,1,1,n||u.RGBA,r||u.UNSIGNED_BYTE,l,0),l}},{key:"readArray",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Uint8Array,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:4,i=new n(this.buffer.width*this.buffer.height*r),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}},{key:"readImageAsCanvas",value:function(){var e=this.gl,t=this._getImageDataCache(),n=t.pixelData,r=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,n);for(var s=this.buffer.width,o=this.buffer.height,l=o/2|0,u=4*s,c=new Uint8Array(4*s),f=0;f0&&void 0!==arguments[0]?arguments[0]:Uint8Array,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,n=this.buffer.width,r=this.buffer.height,i=this._imageDataCache;if(i&&(i.width===n&&i.height===r||(this._imageDataCache=null,i=null)),!i){var a=document.createElement("canvas"),s=a.getContext("2d");a.width=n,a.height=r,i={pixelData:new e(n*r*t),canvas:a,context:s,imageData:s.createImageData(n,r),width:n,height:r},this._imageDataCache=i}return i.context.resetTransform(),i}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"getTexture",value:function(){var e=this;return this._texture||(this._texture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.texture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.texture),!0)},unbind:function(t){e.buffer&&e.buffer.texture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"hasDepthTexture",value:function(){return this._hasDepthTexture}},{key:"getDepthTexture",value:function(){if(!this._hasDepthTexture)return null;var e=this;return this._depthTexture||(this._dethTexture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.depthTexture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.depthTexture),!0)},unbind:function(t){e.buffer&&e.buffer.depthTexture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"destroy",value:function(){if(this.allocated){var e=this.gl;e.deleteTexture(this.buffer.texture),e.deleteTexture(this.buffer.depthTexture),e.deleteFramebuffer(this.buffer.framebuf),e.deleteRenderbuffer(this.buffer.renderbuf),this.allocated=!1,this.buffer=null,this.bound=!1}this._imageDataCache=null,this._texture=null,this._depthTexture=null}}]),e}(),Rt=function(){function e(t){b(this,e),this.scene=t,this._renderBuffersBasic={},this._renderBuffersScaled={}}return P(e,[{key:"getRenderBuffer",value:function(e,t){var n=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled,r=n[e];return r||(r=new Pt(this.scene.canvas.canvas,this.scene.canvas.gl,t),n[e]=r),r}},{key:"destroy",value:function(){for(var e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(var t in this._renderBuffersScaled)this._renderBuffersScaled[t].destroy()}}]),e}();function Ct(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var n;switch(t){case"WEBGL_depth_texture":n=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=e.getExtension(t)}return e._cachedExtensions[t]=n,n}var _t=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}(),Bt=function(){function e(t,n,r,i){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;b(this,e),this.model=t,this.object=null,this.parent=null,this.id=n,this.aabb=null,this.layer=a,this.portionId=s,this._color=[r[0],r[1],r[2],i],this._colorize=[r[0],r[1],r[2],i],this._colorizing=!1,this._transparent=i<255,this.numTriangles=0,this.origin=null}return P(e,[{key:"_finalize",value:function(e){this.layer.initFlags(this.portionId,e,this._transparent)}},{key:"_finalize2",value:function(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}},{key:"_setVisible",value:function(e){this.layer.setVisible(this.portionId,e,this._transparent)}},{key:"_setColor",value:function(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}},{key:"_setColorize",value:function(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}},{key:"_setOpacity",value:function(e,t){var n=e<255,r=this._transparent!==n;this._color[3]=e,this._colorize[3]=e,this._transparent=n,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),r&&this.layer.setTransparent(this.portionId,t,n)}},{key:"_setOffset",value:function(e){this.layer.setOffset(this.portionId,e)}},{key:"_setHighlighted",value:function(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}},{key:"_setXRayed",value:function(e){this.layer.setXRayed(this.portionId,e,this._transparent)}},{key:"_setSelected",value:function(e){this.layer.setSelected(this.portionId,e,this._transparent)}},{key:"_setEdges",value:function(e){this.layer.setEdges(this.portionId,e,this._transparent)}},{key:"_setClippable",value:function(e){this.layer.setClippable(this.portionId,e,this._transparent)}},{key:"_setCollidable",value:function(e){this.layer.setCollidable(this.portionId,e)}},{key:"_setPickable",value:function(e){this.layer.setPickable(this.portionId,e,this._transparent)}},{key:"_setCulled",value:function(e){this.layer.setCulled(this.portionId,e,this._transparent)}},{key:"canPickTriangle",value:function(){return!1}},{key:"drawPickTriangles",value:function(e,t){}},{key:"pickTriangleSurface",value:function(e){}},{key:"precisionRayPickSurface",value:function(e,t,n,r){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,n,r)}},{key:"canPickWorldPos",value:function(){return!0}},{key:"drawPickDepths",value:function(e){this.model.drawPickDepths(e)}},{key:"drawPickNormals",value:function(e){this.model.drawPickNormals(e)}},{key:"delegatePickedEntity",value:function(){return this.parent}},{key:"getEachVertex",value:function(e){this.layer.getEachVertex(this.portionId,e)}},{key:"_destroy",value:function(){this.model.scene._renderer.putPickID(this.pickId)}}]),e}(),Ot=new(function(){function e(){b(this,e),this._uint8Arrays={},this._float32Arrays={}}return P(e,[{key:"_clear",value:function(){this._uint8Arrays={},this._float32Arrays={}}},{key:"getUInt8Array",value:function(e){var t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}},{key:"getFloat32Array",value:function(e){var t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}}]),e}()),St=0;function Nt(){return St++,Ot}var Lt={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},xt=new G({}),Mt=function(){function e(t){for(var n in b(this,e),this.id=xt.addItem({}),t)t.hasOwnProperty(n)&&(this[n]=t[n])}return P(e,[{key:"destroy",value:function(){xt.removeItem(this.id)}}]),e}();var Ft=function(){var e=Z.mat4(),t=Z.mat4();return function(n,r){r=r||Z.mat4();var i=n[0],a=n[1],s=n[2],o=n[3]-i,l=n[4]-a,u=n[5]-s,c=65535;return Z.identityMat4(e),Z.translationMat4v(n,e),Z.identityMat4(t),Z.scalingMat4v([o/c,l/c,u/c],t),Z.mulMat4(e,t,r),r}}(),Ht=function(){var e=Z.mat4(),t=Z.mat4();return function(n,r,i){var a,s=new Uint16Array(n.length),o=new Float32Array([i[0]!==r[0]?65535/(i[0]-r[0]):0,i[1]!==r[1]?65535/(i[1]-r[1]):0,i[2]!==r[2]?65535/(i[2]-r[2]):0]);for(a=0;a=0?1:-1),o=(1-Math.abs(i))*(a>=0?1:-1);i=s,a=o}return new Int8Array([Math[n](127.5*i+(i<0?-1:0)),Math[r](127.5*a+(a<0?-1:0))])}function kt(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}function Vt(e,t,n){return e[t]*n[0]+e[t+1]*n[1]+e[t+2]*n[2]}var jt={getPositionsBounds:function(e){var t,n,r=new Float32Array(3),i=new Float32Array(3);for(t=0;t<3;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:e;return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n[3]=e[3]*t[0]+t[12],n[4]=e[4]*t[5]+t[13],n[5]=e[5]*t[10]+t[14],n},getUVBounds:function(e){var t,n,r=new Float32Array(2),i=new Float32Array(2);for(t=0;t<2;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;ri&&(n=t,i=r),(r=Vt(e,s,kt(t=Gt(e,s,"floor","ceil"))))>i&&(n=t,i=r),(r=Vt(e,s,kt(t=Gt(e,s,"ceil","ceil"))))>i&&(n=t,i=r),a[s]=n[0],a[s+1]=n[1];return a},decompressNormals:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t},decompressNormal:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t}},Qt=new Float32Array([1,1,1,1]),Wt=new Float32Array([0,0,0,1]),zt=Z.vec4(),Kt=Z.vec3(),Yt=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.instancing,a=void 0!==i&&i,s=r.edges,o=void 0!==s&&s;b(this,e),this._scene=t,this._withSAO=n,this._instancing=a,this._edges=o,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}return P(e,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){return[""]}},{key:"_buildFragmentShader",value:function(){return[""]}},{key:"_addMatricesUniformBlockLines",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}},{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"setSectionPlanesStateUniforms",value:function(e){var t=this._scene,n=t.canvas.gl,r=e.model,i=e.layerIndex,a=t._sectionPlanesState.sectionPlanes.length;if(a>0)for(var s=t._sectionPlanesState.sectionPlanes,o=i*a,l=r.renderFlags,u=0;u0&&(this._uReflectionMap="reflectionMap"),n.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.sectionPlanes.length;o3&&void 0!==arguments[3]?arguments[3]:{},i=r.colorUniform,a=void 0!==i&&i,s=r.incrementDrawState,o=void 0!==s&&s,l=Ze.MAX_TEXTURE_IMAGE_UNITS,u=this._scene,c=u.canvas.gl,f=t._state,p=t.model,A=f.textureSet,d=f.geometry,v=f.origin,h=f.positionsDecodeMatrix,I=u._lightsState,y=u.pointsMaterial,m=p.scene.camera,w=m.viewNormalMatrix,g=m.project,T=e.pickViewMatrix||m.viewMatrix,E=p.worldMatrix,b=p.worldNormalMatrix;if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),this._vaoCache.has(t)?c.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(f));var D=0,P=16;if(this._matricesUniformBlockBufferData.set(E,0),this._matricesUniformBlockBufferData.set(v?Ie(T,v):T,D+=P),this._matricesUniformBlockBufferData.set(e.pickProjMatrix||g.matrix,D+=P),this._matricesUniformBlockBufferData.set(h,D+=P),this._matricesUniformBlockBufferData.set(b,D+=P),this._matricesUniformBlockBufferData.set(w,D+=P),c.bindBuffer(c.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),c.bufferData(c.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,c.DYNAMIC_DRAW),c.bindBufferBase(c.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer),c.uniform1i(this._uRenderPass,n),this.setSectionPlanesStateUniforms(t),u.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var R=2/(Math.log(e.pickZFar+1)/Math.LN2);c.uniform1f(this._uLogDepthBufFC,R)}this._uZFar&&c.uniform1f(this._uZFar,u.camera.project.far)}if(this._uPickInvisible&&c.uniform1i(this._uPickInvisible,e.pickInvisible),this._uPickZNear&&c.uniform1f(this._uPickZNear,e.pickZNear),this._uPickZFar&&c.uniform1f(this._uPickZFar,e.pickZFar),this._uPositionsDecodeMatrix&&c.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,f.positionsDecodeMatrix),this._uUVDecodeMatrix&&c.uniformMatrix3fv(this._uUVDecodeMatrix,!1,(this._instancing,f.uvDecodeMatrix)),this._uIntensityRange&&y.filterIntensity&&c.uniform2f(this._uIntensityRange,y.minIntensity,y.maxIntensity),this._uPointSize&&c.uniform1f(this._uPointSize,y.pointSize),this._uNearPlaneHeight){var C="ortho"===u.camera.projection?1:c.drawingBufferHeight/(2*Math.tan(.5*u.camera.perspective.fov*Math.PI/180));c.uniform1f(this._uNearPlaneHeight,C)}if(A){var _=A.colorTexture,B=A.metallicRoughnessTexture,O=A.emissiveTexture,S=A.normalsTexture,N=A.occlusionTexture;this._uColorMap&&_&&(this._program.bindTexture(this._uColorMap,_.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uMetallicRoughMap&&B&&(this._program.bindTexture(this._uMetallicRoughMap,B.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uEmissiveMap&&O&&(this._program.bindTexture(this._uEmissiveMap,O.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uNormalMap&&S&&(this._program.bindTexture(this._uNormalMap,S.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uAOMap&&N&&(this._program.bindTexture(this._uAOMap,N.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l)}if(I.reflectionMaps.length>0&&I.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,I.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),I.lightMaps.length>0&&I.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,I.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),this._withSAO){var L=u.sao,x=L.possible;if(x){var M=c.drawingBufferWidth,F=c.drawingBufferHeight;zt[0]=M,zt[1]=F,zt[2]=L.blendCutoff,zt[3]=L.blendFactor,c.uniform4fv(this._uSAOParams,zt),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++}}if(a){var H=this._edges?"edgeColor":"fillColor",U=this._edges?"edgeAlpha":"fillAlpha";if(n===Lt["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var G=u.xrayMaterial._state,k=G[H],V=G[U];c.uniform4f(this._uColor,k[0],k[1],k[2],V)}else if(n===Lt["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var j=u.highlightMaterial._state,Q=j[H],W=j[U];c.uniform4f(this._uColor,Q[0],Q[1],Q[2],W)}else if(n===Lt["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var z=u.selectedMaterial._state,K=z[H],Y=z[U];c.uniform4f(this._uColor,K[0],K[1],K[2],Y)}else c.uniform4fv(this._uColor,this._edges?Wt:Qt)}this._draw({geometry:d,state:f,frameCtx:e,incrementDrawState:o}),c.bindVertexArray(null)}}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null,ee.memory.programs--}}]),e}(),Xt=function(e){I(n,Yt);var t=m(n);function n(e,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=i.instancing,s=void 0!==a&&a,o=i.edges,l=void 0!==o&&o;return b(this,n),t.call(this,e,r,{instancing:s,edges:l})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;if(this._edges)t.drawElements(t.LINES,n.edgeIndicesBuf.numItems,n.edgeIndicesBuf.itemType,0);else{var a=r.pickElementsCount||n.indicesBuf.numItems,s=r.pickElementsOffset?r.pickElementsOffset*n.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,a,n.indicesBuf.itemType,s),i&&r.drawElements++}}}]),n}(),qt=function(e){I(n,Xt);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!1,edges:!0})}return P(n)}(),Jt=function(e){I(n,Yt);var t=m(n);function n(e,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=i.edges,s=void 0!==a&&a;return b(this,n),t.call(this,e,r,{instancing:!0,edges:s})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=(e.geometry,e.incrementDrawState);this._edges?t.drawElementsInstanced(t.LINES,n.edgeIndicesBuf.numItems,n.edgeIndicesBuf.itemType,0,n.numInstances):(t.drawElementsInstanced(t.TRIANGLES,n.indicesBuf.numItems,n.indicesBuf.itemType,0,n.numInstances),i&&r.drawElements++)}}]),n}(),Zt=function(e){I(n,Jt);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0,edges:!0})}return P(n)}(),$t=function(e){I(n,Yt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawArrays(t.POINTS,0,n.positionsBuf.numItems),i&&r.drawArrays++}}]),n}(),en=function(e){I(n,Yt);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=(e.geometry,e.incrementDrawState);t.drawArraysInstanced(t.POINTS,0,n.positionsBuf.numItems,n.numInstances),i&&r.drawArrays++}}]),n}(),tn=function(e){I(n,Yt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawElements(t.LINES,n.indicesBuf.numItems,n.indicesBuf.itemType,0),i&&r.drawElements++}}]),n}(),nn=function(e){I(n,Yt);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=(e.geometry,e.frameCtx),i=e.incrementDrawState;t.drawElementsInstanced(t.LINES,n.indicesBuf.numItems,n.indicesBuf.itemType,0,n.numInstances),i&&r.drawElements++}}]),n}(),rn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t=this._scene,n=t._sectionPlanesState,r=t._lightsState,i=n.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),t.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),t.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(var s=0,o=r.lights.length;s= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),i&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),t.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(var l=0,u=r.lights.length;l0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),n}(),an=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching flat-shading draw vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._lightsState,n=e._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),r){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var a=0,s=n.sectionPlanes.length;a> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var c=0,f=n.sectionPlanes.length;c 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var p=0,A=t.lights.length;p0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}]),n}(),on=function(e){I(n,qt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("uniform int renderPass;"),n.push("uniform vec4 color;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),ln=function(e){I(n,qt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),un=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry picking vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vPickColor; "),r.push("}"),r}}]),n}(),cn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),fn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vWorldNormal;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec3 worldNormal = octDecode(normal.xy); "),n.push(" vWorldNormal = worldNormal;"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}}]),n}(),pn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching occlusion fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),r.push("}"),r}}]),n}(),An=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec2 vHighPrecisionZW;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching depth fragment shader"),r.push("precision highp float;"),r.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),r.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),r.push("}"),r}}]),n}(),dn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n,!0),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),vn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry shadow vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),n.push(" int colorFlag = int(flags) & 0xF;"),n.push(" bool visible = (colorFlag > 0);"),n.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push(" if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry shadow fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = encodeFloat( gl_FragCoord.z); "),n.push("}"),n}}]),n}(),hn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=e._lightsState,r=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),n.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),r&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),r&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),n.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._sectionPlanesState,r=e._lightsState,i=n.sectionPlanes.length>0,a=n.clippingCaps,s=[];s.push("#version 300 es"),s.push("// Triangles batching quality draw fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform sampler2D uColorMap;"),s.push("uniform sampler2D uMetallicRoughMap;"),s.push("uniform sampler2D uEmissiveMap;"),s.push("uniform sampler2D uNormalMap;"),s.push("uniform sampler2D uAOMap;"),s.push("in vec4 vViewPosition;"),s.push("in vec3 vViewNormal;"),s.push("in vec4 vColor;"),s.push("in vec2 vUV;"),s.push("in vec2 vMetallicRoughness;"),r.lightMaps.length>0&&s.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(s,!0),r.reflectionMaps.length>0&&s.push("uniform samplerCube reflectionMap;"),r.lightMaps.length>0&&s.push("uniform samplerCube lightMap;"),s.push("uniform vec4 lightAmbient;");for(var o=0,l=r.lights.length;o0&&(s.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),s.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),s.push(" return envMapColor;"),s.push("}")),s.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),s.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),s.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),s.push("}"),s.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" return 1.0 / ( gl * gv );"),s.push("}"),s.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" return 0.5 / max( gv + gl, EPSILON );"),s.push("}"),s.push("float D_GGX(const in float alpha, const in float dotNH) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),s.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float alpha = ( roughness * roughness );"),s.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),s.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),s.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),s.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),s.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),s.push(" vec3 F = F_Schlick( specularColor, dotLH );"),s.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),s.push(" float D = D_GGX( alpha, dotNH );"),s.push(" return F * (G * D);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),s.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),s.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),s.push(" vec4 r = roughness * c0 + c1;"),s.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),s.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),s.push(" return specularColor * AB.x + AB.y;"),s.push("}"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&(s.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.lightMaps.length>0&&(s.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),s.push(" irradiance *= PI;"),s.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),r.reflectionMaps.length>0&&(s.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),s.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),s.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),s.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),s.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),s.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),s.push("}")),s.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),s.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),s.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),s.push("}"),s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var p=0,A=n.sectionPlanes.length;p (0.002 * vClipPosition.w)) {"),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" return;"),s.push("}")):(s.push(" if (dist > 0.0) { "),s.push(" discard;"),s.push(" }")),s.push("}")}s.push("IncidentLight light;"),s.push("Material material;"),s.push("Geometry geometry;"),s.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),s.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),s.push("float opacity = float(vColor.a) / 255.0;"),s.push("vec3 baseColor = rgb;"),s.push("float specularF0 = 1.0;"),s.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),s.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),s.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),s.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),s.push("baseColor *= colorTexel.rgb;"),s.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),s.push("metallic *= metalRoughTexel.b;"),s.push("roughness *= metalRoughTexel.g;"),s.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),s.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),s.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),s.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),s.push("geometry.position = vViewPosition.xyz;"),s.push("geometry.viewNormal = -normalize(viewNormal);"),s.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),r.lightMaps.length>0&&s.push("geometry.worldNormal = normalize(vWorldNormal);"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&s.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var d=0,v=r.lights.length;d0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick flat normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("out vec4 vWorldPosition;"),t&&n.push("out float vFlags;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),t&&n.push(" vFlags = flags;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick flat normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}}]),n}(),yn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching color texture vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._lightsState,r=e._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(var s=0,o=r.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(var f=0,p=r.sectionPlanes.length;f 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var A=0,d=n.lights.length;A0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]})),Tn=Z.mat4(),En=Z.mat4();function bn(e,t,n){for(var r=e.length,i=new Uint16Array(r),a=t[0],s=t[1],o=t[2],l=t[3]-a,u=t[4]-s,c=t[5]-o,f=65525,p=f/l,A=f/u,d=f/c,v=function(e){return e>=0?e:0},h=0;h=0?1:-1),s=(1-Math.abs(r))*(i>=0?1:-1),r=a,i=s}return new Int8Array([Math[t](127.5*r+(r<0?-1:0)),Math[n](127.5*i+(i<0?-1:0))])}function Rn(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}var Cn=Z.vec3(),_n=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=a.eye;e._origin[0]=l[0],e._origin[1]=l[1],e._origin[2]=l[2];var c=t.aabb,f=[Z.safeInv(c[3]-c[0])*Z.MAX_INT,Z.safeInv(c[4]-c[1])*Z.MAX_INT,Z.safeInv(c[5]-c[2])*Z.MAX_INT];if(e._coordinateScale[0]=Z.safeInv(f[0]),e._coordinateScale[1]=Z.safeInv(f[1]),e._coordinateScale[2]=Z.safeInv(f[2]),this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),e.pickViewMatrix&&(u=e.pickOrigin||u);var p=[u[0]-l[0],u[1]-l[1],u[2]-l[2]];s.uniform3fv(this._uCameraEyeRtc,p),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.layerNumber),s.uniform3fv(this._uCoordinateScaler,f),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible),s.uniform1i(this._uSolid,t.solid);var A=e.pickViewMatrix||a.viewMatrix,d=l?Ie(A,l):A;if(s.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){var v=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,v)}var h=i._sectionPlanesState.sectionPlanes.length;if(h>0)for(var I=i._sectionPlanesState.sectionPlanes,y=t.layerIndex*h,m=r.renderFlags,w=0;w0,n=[];return n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),n.push("uniform bool solid;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),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("// VBO SnapBatchingDepthBufInitRenderer 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 int layerNumber;"),r.push("uniform vec3 coordinateScaler;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Bn=Z.vec3(),On=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()+this._scene.pointsMaterial.hash}},{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;e._origin[0]=l[0],e._origin[1]=l[1],e._origin[2]=l[2];var u=t.aabb,c=[Z.safeInv(u[3]-u[0])*Z.MAX_INT,Z.safeInv(u[4]-u[1])*Z.MAX_INT,Z.safeInv(u[5]-u[2])*Z.MAX_INT];if(e._coordinateScale[0]=Z.safeInv(c[0]),e._coordinateScale[1]=Z.safeInv(c[1]),e._coordinateScale[2]=Z.safeInv(c[2]),this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var f=a.eye;e.pickViewMatrix&&(f=e.pickOrigin||f);var p=[f[0]-l[0],f[1]-l[1],f[2]-l[2]];s.uniform3fv(this._uCameraEyeRtc,p),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.layerNumber),s.uniform3fv(this._uCoordinateScaler,c),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible);var A=e.pickViewMatrix||a.viewMatrix,d=l?Ie(A,l):A;if(s.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){var v=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,v)}var h=i._sectionPlanesState.sectionPlanes.length;if(h>0)for(var I=i._sectionPlanesState.sectionPlanes,y=t.layerIndex*h,m=r.renderFlags,w=0;w0;e.pointsMaterial._state;var n=[];return n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),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("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),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("// SnapBatchingDepthRenderer 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 int layerNumber;"),r.push("uniform vec3 coordinateScaler;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Sn=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new _n(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new On(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),Nn={};var Ln=Z.mat4(),xn=Z.mat4(),Mn=Z.vec4([0,0,0,1]),Fn=Z.vec4([0,0,0,1]),Hn=Z.vec4([0,0,0,1]),Un=Z.OBB3(),Gn=Z.vec3(),kn=Z.vec3(),Vn=Z.vec3(),jn=Z.vec3(),Qn=Z.vec3(),Wn=Z.vec3(),zn=Z.vec3(),Kn=function(){function e(t){var n,r,i;b(this,e),console.log("Creating TrianglesBatchingLayer"),this.model=t.model,this.sortId="TrianglesBatchingLayer"+(t.solid?"-solid":"-surface")+(t.autoNormals?"-autonormals":"-normals")+(t.textureSet&&t.textureSet.colorTexture?"-colorTexture":"")+(t.textureSet&&t.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=t.layerIndex,this._batchingRenderers=(n=t.model.scene,r=n.id,(i=wn[r])||(i=new mn(n),wn[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete wn[r],i._destroy()}))),i),this._snapBatchingRenderers=function(e){var t=e.id,n=Nn[t];return n||(n=new Sn(e),Nn[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Nn[t],n._destroy()}))),n}(t.model.scene),this._buffer=new gn(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Mt({origin:Z.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:t.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=Z.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,t.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=Z.mat4(t.positionsDecodeMatrix)),t.uvDecodeMatrix?(this._state.uvDecodeMatrix=Z.mat3(t.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,t.origin&&this._state.origin.set(t.origin),this.aabb=Z.collapseAABB3(),this.solid=!!t.solid}return P(e,[{key:"canCreatePortion",value:function(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(var F=0,H=a.length;F0){var U=Ln;h?Z.inverseMat4(Z.transposeMat4(h,xn),U):Z.identityMat4(U,U),function(e,t,n,r,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}var s,o,l,u,c,f=new Float32Array([0,0,0,0]),p=new Float32Array([0,0,0,0]);for(c=0;cu&&(o=s,u=l),(l=a(p,Rn(s=Pn(p,"floor","ceil"))))>u&&(o=s,u=l),(l=a(p,Rn(s=Pn(p,"ceil","ceil"))))>u&&(o=s,u=l),r[i+c+0]=o[0],r[i+c+1]=o[1],r[i+c+2]=0}(U,i,i.length,g.normals,g.normals.length)}if(l)for(var G=0,k=l.length;G0)for(var $=0,ee=s.length;$0)for(var te=0,ne=o.length;te0){var r=this._state.positionsDecodeMatrix?new Uint16Array(n.positions):bn(n.positions,this._modelAABB,this._state.positionsDecodeMatrix=Z.mat4());if(e.positionsBuf=new pt(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(var i=0,a=this._portions.length;i0){var u=new Int8Array(n.normals);e.normalsBuf=new pt(t,t.ARRAY_BUFFER,u,n.normals.length,3,t.STATIC_DRAW,!0)}if(n.colors.length>0){var c=new Uint8Array(n.colors);e.colorsBuf=new pt(t,t.ARRAY_BUFFER,c,n.colors.length,4,t.DYNAMIC_DRAW,!1)}if(n.uv.length>0)if(e.uvDecodeMatrix){e.uvBuf=new pt(t,t.ARRAY_BUFFER,n.uv,n.uv.length,2,t.STATIC_DRAW,!1)}else{var f=jt.getUVBounds(n.uv),p=jt.compressUVs(n.uv,f.min,f.max),A=p.quantized;e.uvDecodeMatrix=Z.mat3(p.decodeMatrix),e.uvBuf=new pt(t,t.ARRAY_BUFFER,A,A.length,2,t.STATIC_DRAW,!1)}if(n.metallicRoughness.length>0){var d=new Uint8Array(n.metallicRoughness);e.metallicRoughnessBuf=new pt(t,t.ARRAY_BUFFER,d,n.metallicRoughness.length,2,t.STATIC_DRAW,!1)}if(n.positions.length>0){var v=n.positions.length/3,h=new Float32Array(v);e.flagsBuf=new pt(t,t.ARRAY_BUFFER,h,h.length,1,t.DYNAMIC_DRAW,!1)}if(n.pickColors.length>0){var I=new Uint8Array(n.pickColors);e.pickColorsBuf=new pt(t,t.ARRAY_BUFFER,I,n.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var y=new Float32Array(n.offsets);e.offsetsBuf=new pt(t,t.ARRAY_BUFFER,y,n.offsets.length,3,t.DYNAMIC_DRAW)}if(n.indices.length>0){var m=new Uint32Array(n.indices);e.indicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,m,n.indices.length,1,t.STATIC_DRAW)}if(n.edgeIndices.length>0){var w=new Uint32Array(n.edgeIndices);e.edgeIndicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,w,n.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}}},{key:"isEmpty",value:function(){return!this._state.indicesBuf}},{key:"initFlags",value:function(e,t,n){t&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,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{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._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=e,r=this._portions[n],i=4*r.vertsBaseIndex,a=4*r.numVerts,s=this._scratchMemory.getUInt8Array(a),o=t[0],l=t[1],u=t[2],c=t[3],f=0;f3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=e,o=this._portions[s],l=o.vertsBaseIndex,u=o.numVerts,c=l,f=u,p=!!(t&Te),A=!!(t&Re),d=!!(t&Ce),v=!!(t&_e),h=!!(t&Be),I=!!(t&be),y=!!(t&Ee);i=!p||y||A||d&&!this.model.scene.highlightMaterial.glowThrough||v&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,a=!p||y?Lt.NOT_RENDERED:v?Lt.SILHOUETTE_SELECTED:d?Lt.SILHOUETTE_HIGHLIGHTED:A?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED;var m=0;m=!p||y?Lt.NOT_RENDERED:v?Lt.EDGES_SELECTED:d?Lt.EDGES_HIGHLIGHTED:A?Lt.EDGES_XRAYED:h?n?Lt.EDGES_COLOR_TRANSPARENT:Lt.EDGES_COLOR_OPAQUE:Lt.NOT_RENDERED;var w=p&&!y&&I?Lt.PICK:Lt.NOT_RENDERED,g=t&De?1:0;if(r){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var T=c,E=c+f;TI)&&(I=b,r.set(y),i&&Z.triangleNormal(A,d,v,i),h=!0)}}return h&&i&&(Z.transformVec3(this.model.worldNormalMatrix,i,i),Z.normalizeVec3(i)),h}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}]),e}(),Yn=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t,n,r=this._scene,i=r._sectionPlanesState,a=r._lightsState,s=i.sectionPlanes.length>0,o=[];for(o.push("#version 300 es"),o.push("// Instancing geometry drawing vertex shader"),o.push("uniform int renderPass;"),o.push("in vec3 position;"),o.push("in vec2 normal;"),o.push("in vec4 color;"),o.push("in float flags;"),r.entityOffsetsEnabled&&o.push("in vec3 offset;"),o.push("in vec4 modelMatrixCol0;"),o.push("in vec4 modelMatrixCol1;"),o.push("in vec4 modelMatrixCol2;"),o.push("in vec4 modelNormalMatrixCol0;"),o.push("in vec4 modelNormalMatrixCol1;"),o.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(o,!0),r.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;")),o.push("uniform vec4 lightAmbient;"),e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"),s&&(o.push("out vec4 vWorldPosition;"),o.push("out float vFlags;")),o.push("out vec4 vColor;"),o.push("void main(void) {"),o.push("int colorFlag = int(flags) & 0xF;"),o.push("if (colorFlag != renderPass) {"),o.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),o.push("} else {"),o.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),o.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),r.entityOffsetsEnabled&&o.push(" worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix * worldPosition; "),o.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),o.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),o.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),e=0,t=a.lights.length;e0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),n}(),Xn=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry flat-shading drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=n._lightsState,a=r.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),n.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),a){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var o=0,l=r.sectionPlanes.length;o> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var c=0,f=r.sectionPlanes.length;c 0.0) { "),s.push(" discard;"),s.push(" }"),s.push("}")}for(s.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),s.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),s.push("float lambertian = 1.0;"),s.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),s.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),s.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=i.lights.length;e0,n=[];return n.push("#version 300 es"),n.push("// Instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing fill fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Jn=function(e){I(n,Zt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles instancing edges vertex shader"),n.push("uniform int renderPass;"),n.push("uniform vec4 color;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Zn=function(e){I(n,Zt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles instancing edges vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),$n=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry picking vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vPickColor; "),r.push("}"),r}}]),n}(),er=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),tr=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec2 normal;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("in vec4 modelNormalMatrixCol0;"),n.push("in vec4 modelNormalMatrixCol1;"),n.push("in vec4 modelNormalMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vWorldNormal;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),n.push(" vWorldNormal = worldNormal;"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}}]),n}(),nr=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),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("in float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing occlusion fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),rr=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry depth drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec2 vHighPrecisionZW;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),n.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}]),n}(),ir=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n,!0),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),ar=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry shadow drawing vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("bool visible = (colorFlag > 0);"),n.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push("if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),sr=1e3,or=1001,lr=1002,ur=1003,cr=1004,fr=1004,pr=1005,Ar=1005,dr=1006,vr=1007,hr=1007,Ir=1008,yr=1008,mr=1009,wr=1010,gr=1011,Tr=1012,Er=1013,br=1014,Dr=1015,Pr=1016,Rr=1017,Cr=1018,_r=1020,Br=1021,Or=1022,Sr=1023,Nr=1024,Lr=1025,xr=1026,Mr=1027,Fr=1028,Hr=1029,Ur=1030,Gr=1031,kr=1033,Vr=33776,jr=33777,Qr=33778,Wr=33779,zr=35840,Kr=35841,Yr=35842,Xr=35843,qr=36196,Jr=37492,Zr=37496,$r=37808,ei=37809,ti=37810,ni=37811,ri=37812,ii=37813,ai=37814,si=37815,oi=37816,li=37817,ui=37818,ci=37819,fi=37820,pi=37821,Ai=36492,di=3e3,vi=3001,hi=1e4,Ii=10001,yi=10002,mi=10003,wi={3e3:"linearToLinear",3001:"sRGBToLinear"},gi=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=e._lightsState,r=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),n.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),r&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),r&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),n.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._sectionPlanesState,r=e._lightsState,i=n.sectionPlanes.length>0,a=n.clippingCaps,s=[];s.push("#version 300 es"),s.push("// Instancing geometry quality drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform sampler2D uColorMap;"),s.push("uniform sampler2D uMetallicRoughMap;"),s.push("uniform sampler2D uEmissiveMap;"),s.push("uniform sampler2D uNormalMap;"),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),r.reflectionMaps.length>0&&s.push("uniform samplerCube reflectionMap;"),r.lightMaps.length>0&&s.push("uniform samplerCube lightMap;"),s.push("uniform vec4 lightAmbient;");for(var o=0,l=r.lights.length;o0&&s.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(s,!0),s.push("#define PI 3.14159265359"),s.push("#define RECIPROCAL_PI 0.31830988618"),s.push("#define RECIPROCAL_PI2 0.15915494"),s.push("#define EPSILON 1e-6"),s.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),s.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),s.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),s.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),s.push(" return normalize(surf_norm );"),s.push(" }"),s.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),s.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),s.push(" vec2 st0 = dFdx( uv.st );"),s.push(" vec2 st1 = dFdy( uv.st );"),s.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),s.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),s.push(" vec3 N = normalize( surf_norm );"),s.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),s.push(" mat3 tsn = mat3( S, T, N );"),s.push(" return normalize( tsn * mapN );"),s.push("}"),s.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),s.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),s.push("}"),s.push("struct IncidentLight {"),s.push(" vec3 color;"),s.push(" vec3 direction;"),s.push("};"),s.push("struct ReflectedLight {"),s.push(" vec3 diffuse;"),s.push(" vec3 specular;"),s.push("};"),s.push("struct Geometry {"),s.push(" vec3 position;"),s.push(" vec3 viewNormal;"),s.push(" vec3 worldNormal;"),s.push(" vec3 viewEyeDir;"),s.push("};"),s.push("struct Material {"),s.push(" vec3 diffuseColor;"),s.push(" float specularRoughness;"),s.push(" vec3 specularColor;"),s.push(" float shine;"),s.push("};"),s.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),s.push(" float r = ggxRoughness + 0.0001;"),s.push(" return (2.0 / (r * r) - 2.0);"),s.push("}"),s.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),s.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),s.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),s.push("}"),r.reflectionMaps.length>0&&(s.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),s.push(" vec3 envMapColor = "+wi[r.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),s.push(" return envMapColor;"),s.push("}")),s.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),s.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),s.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),s.push("}"),s.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" return 1.0 / ( gl * gv );"),s.push("}"),s.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" return 0.5 / max( gv + gl, EPSILON );"),s.push("}"),s.push("float D_GGX(const in float alpha, const in float dotNH) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),s.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float alpha = ( roughness * roughness );"),s.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),s.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),s.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),s.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),s.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),s.push(" vec3 F = F_Schlick( specularColor, dotLH );"),s.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),s.push(" float D = D_GGX( alpha, dotNH );"),s.push(" return F * (G * D);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),s.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),s.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),s.push(" vec4 r = roughness * c0 + c1;"),s.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),s.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),s.push(" return specularColor * AB.x + AB.y;"),s.push("}"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&(s.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.lightMaps.length>0&&(s.push(" vec3 irradiance = "+wi[r.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),s.push(" irradiance *= PI;"),s.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),r.reflectionMaps.length>0&&(s.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),s.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),s.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),s.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),s.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),s.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),s.push("}")),s.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),s.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),s.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),s.push("}"),s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var p=0,A=n.sectionPlanes.length;p (0.002 * vClipPosition.w)) {"),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" return;"),s.push("}")):(s.push(" if (dist > 0.0) { "),s.push(" discard;"),s.push(" }")),s.push("}")}s.push("IncidentLight light;"),s.push("Material material;"),s.push("Geometry geometry;"),s.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),s.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),s.push("float opacity = float(vColor.a) / 255.0;"),s.push("vec3 baseColor = rgb;"),s.push("float specularF0 = 1.0;"),s.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),s.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),s.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),s.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),s.push("baseColor *= colorTexel.rgb;"),s.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),s.push("metallic *= metalRoughTexel.b;"),s.push("roughness *= metalRoughTexel.g;"),s.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),s.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),s.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),s.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),s.push("geometry.position = vViewPosition.xyz;"),s.push("geometry.viewNormal = -normalize(viewNormal);"),s.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),r.lightMaps.length>0&&s.push("geometry.worldNormal = normalize(vWorldNormal);"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&s.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var d=0,v=r.lights.length;d0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&n.push("out float vFlags;"),n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&n.push("vFlags = flags;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}}]),n}(),Ei=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n.gammaOutput,i=n._sectionPlanesState,a=n._lightsState,s=i.sectionPlanes.length>0,o=[];if(o.push("#version 300 es"),o.push("// Instancing geometry drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),n.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),o.push("uniform sampler2D uColorMap;"),this._withSAO&&(o.push("uniform sampler2D uOcclusionTexture;"),o.push("uniform vec4 uSAOParams;"),o.push("const float packUpscale = 256. / 255.;"),o.push("const float unpackDownScale = 255. / 256.;"),o.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),o.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),o.push("float unpackRGBToFloat( const in vec4 v ) {"),o.push(" return dot( v, unPackFactors );"),o.push("}")),o.push("uniform float gammaFactor;"),o.push("vec4 linearToLinear( in vec4 value ) {"),o.push(" return value;"),o.push("}"),o.push("vec4 sRGBToLinear( in vec4 value ) {"),o.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),o.push("}"),o.push("vec4 gammaToLinear( in vec4 value) {"),o.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),o.push("}"),r&&(o.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),o.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),o.push("}")),s){o.push("in vec4 vWorldPosition;"),o.push("in float vFlags;");for(var l=0,u=i.sectionPlanes.length;l> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var f=0,p=i.sectionPlanes.length;f 0.0) { "),o.push(" discard;"),o.push(" }"),o.push("}")}for(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),o.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),o.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),o.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=a.lights.length;e0)for(var y=i._sectionPlanesState.sectionPlanes,m=t.layerIndex*I,w=r.renderFlags,g=0;g0,n=[];return n.push("#version 300 es"),n.push("// Points instancing snap vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),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("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),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("// Points instancing pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform int layerNumber;"),r.push("uniform vec3 coordinateScaler;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Ci=Z.vec3(),_i=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.canvas.gl,s=t._state,o=t._state.origin,l=s.geometry;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];var u=t.aabb,c=[Z.safeInv(u[3]-u[0])*Z.MAX_INT,Z.safeInv(u[4]-u[1])*Z.MAX_INT,Z.safeInv(u[5]-u[2])*Z.MAX_INT];if(e._coordinateScale[0]=Z.safeInv(c[0]),e._coordinateScale[1]=Z.safeInv(c[1]),e._coordinateScale[2]=Z.safeInv(c[2]),this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var f=i.camera,p=f.eye;e.pickViewMatrix&&(p=e.pickOrigin||p);var A=[p[0]-o[0],p[1]-o[1],p[2]-o[2]];a.uniform3fv(this._uCameraEyeRtc,A),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.layerNumber),a.uniform3fv(this._uCoordinateScaler,c),a.uniform1i(this._uRenderPass,n),a.uniform1i(this._uPickInvisible,e.pickInvisible);var d=e.pickViewMatrix||f.viewMatrix,v=o?Ie(d,o):d;if(a.uniformMatrix4fv(this._uViewMatrix,!1,v),a.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,f.projMatrix),i.logarithmicDepthBufferEnabled){var h=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,h)}var I=i._sectionPlanesState.sectionPlanes.length;if(I>0)for(var y=i._sectionPlanesState.sectionPlanes,m=t.layerIndex*I,w=r.renderFlags,g=0;g0,n=[];return n.push("#version 300 es"),n.push("// Points instancing snap vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),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("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),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("// Points instancing pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform int layerNumber;"),r.push("uniform vec3 coordinateScaler;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Bi=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Ri(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new _i(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),Oi={};var Si=new Uint8Array(4),Ni=new Float32Array(1),Li=Z.vec4([0,0,0,1]),xi=Z.vec4([0,0,0,1]),Mi=Z.vec4([0,0,0,1]),Fi=new Float32Array(3),Hi=Z.vec3(),Ui=Z.vec3(),Gi=Z.vec3(),ki=Z.vec3(),Vi=Z.vec3(),ji=Z.vec3(),Qi=Z.vec3(),Wi=function(){function e(t){var n,r,i;b(this,e),console.log("Creating TrianglesInstancingLayer"),this.model=t.model,this.sortId="TrianglesInstancingLayer"+(t.solid?"-solid":"-surface")+(t.normals?"-normals":"-autoNormals"),this.layerIndex=t.layerIndex,this._instancingRenderers=(n=t.model.scene,r=n.id,(i=Di[r])||(i=new bi(n),Di[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Di[r],i._destroy()}))),i),this._snapInstancingRenderers=function(e){var t=e.id,n=Oi[t];return n||(n=new Bi(e),Oi[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Oi[t],n._destroy()}))),n}(t.model.scene),this._aabb=Z.collapseAABB3(),this._state=new Mt({numInstances:0,obb:Z.OBB3(),origin:Z.vec3(),geometry:t.geometry,textureSet:t.textureSet,pbrSupported:!1,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],t.origin&&this._state.origin.set(t.origin),this._finalized=!1,this.aabb=Z.collapseAABB3(),this.solid=!!t.solid,this.numIndices=t.geometry.numIndices}return P(e,[{key:"createPortion",value:function(e){var t=e.color,n=e.metallic,r=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,s=e.sceneModelMatrix,o=e.aabb,l=e.pickColor;if(this._finalized)throw"Already finalized";var u=t[0],c=t[1],f=t[2];if(this._colors.push(u),this._colors.push(c),this._colors.push(f),this._colors.push(i),this._metallicRoughness.push(null!=n?n:0),this._metallicRoughness.push(null!=r?r:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){var p=Z.transposeMat4(a,Z.mat4()),A=Z.inverseMat4(p);this._modelNormalMatrixCol0.push(A[0]),this._modelNormalMatrixCol0.push(A[4]),this._modelNormalMatrixCol0.push(A[8]),this._modelNormalMatrixCol0.push(A[12]),this._modelNormalMatrixCol1.push(A[1]),this._modelNormalMatrixCol1.push(A[5]),this._modelNormalMatrixCol1.push(A[9]),this._modelNormalMatrixCol1.push(A[13]),this._modelNormalMatrixCol2.push(A[2]),this._modelNormalMatrixCol2.push(A[6]),this._modelNormalMatrixCol2.push(A[10]),this._modelNormalMatrixCol2.push(A[14])}this._pickColors.push(l[0]),this._pickColors.push(l[1]),this._pickColors.push(l[2]),this._pickColors.push(l[3]);for(var d=this._state.geometry.positionsCompressed.length,v=this._state.geometry.positionsCompressed,h=this._state.geometry.positionsDecodeMatrix,I=0;I0){e.colorsBuf=new pt(r,r.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,r.DYNAMIC_DRAW,!1),this._colors=[]}if(this._metallicRoughness.length>0){var s=new Uint8Array(this._metallicRoughness);e.metallicRoughnessBuf=new pt(r,r.ARRAY_BUFFER,s,this._metallicRoughness.length,2,r.STATIC_DRAW,!1)}if(a>0){e.flagsBuf=new pt(r,r.ARRAY_BUFFER,new Float32Array(a),a,1,r.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){e.offsetsBuf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,r.DYNAMIC_DRAW,!1),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){e.positionsBuf=new pt(r,r.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,r.STATIC_DRAW,!1),e.positionsDecodeMatrix=Z.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){var o=new Uint8Array(t.colorsCompressed);e.colorsBuf=new pt(r,r.ARRAY_BUFFER,o,o.length,4,r.STATIC_DRAW,!1)}if(t.uvCompressed&&t.uvCompressed.length>0){var l=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new pt(r,r.ARRAY_BUFFER,l,l.length,2,r.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new pt(r,r.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,r.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new pt(r,r.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,r.STATIC_DRAW)),this._modelMatrixCol0.length>0){var u=!1;e.modelMatrixCol0Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,r.STATIC_DRAW,u),e.modelMatrixCol1Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,r.STATIC_DRAW,u),e.modelMatrixCol2Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,r.STATIC_DRAW,u),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,r.STATIC_DRAW,u),e.modelNormalMatrixCol1Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,r.STATIC_DRAW,u),e.modelNormalMatrixCol2Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,r.STATIC_DRAW,u),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){e.pickColorsBuf=new pt(r,r.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,r.STATIC_DRAW,!1),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&n&&n.colorTexture&&n.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!n&&!!n.colorTexture,this._state.geometry=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&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)}},{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._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Si[0]=t[0],Si[1]=t[1],Si[2]=t[2],Si[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Si,4*e)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Te),i=!!(t&Re),a=!!(t&Ce),s=!!(t&_e),o=!!(t&Be),l=!!(t&be),u=!!(t&Ee),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.SILHOUETTE_SELECTED:a?Lt.SILHOUETTE_HIGHLIGHTED:i?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED)<<4,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.EDGES_SELECTED:a?Lt.EDGES_HIGHLIGHTED:i?Lt.EDGES_XRAYED:o?n?Lt.EDGES_COLOR_TRANSPARENT:Lt.EDGES_COLOR_OPAQUE:Lt.NOT_RENDERED)<<8,c|=(r&&!u&&l?Lt.PICK:Lt.NOT_RENDERED)<<12,c|=(t&De?1:0)<<16,Ni[0]=c,this._state.flagsBuf&&this._state.flagsBuf.setData(Ni,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Fi[0]=t[0],Fi[1]=t[1],Fi[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Fi,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"getEachVertex",value:function(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var n=this._state,r=n.geometry,i=this._portions[e];if(i)for(var a=r.quantizedPositions,s=n.origin,o=i.offset,l=s[0]+o[0],u=s[1]+o[1],c=s[2]+o[2],f=Li,p=i.matrix,A=this.model.sceneModelMatrix,d=n.positionsDecodeMatrix,v=0,h=a.length;vy)&&(y=P,r.set(m),i&&Z.triangleNormal(d,v,h,i),I=!0)}}return I&&i&&(Z.transformVec3(o.normalMatrix,i,i),Z.transformVec3(this.model.worldNormalMatrix,i,i),Z.normalizeVec3(i)),I}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}]),e}(),zi=function(e){I(n,tn);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines batching color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),Ki=function(e){I(n,tn);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines batching silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = color;"),r.push("}"),r}}]),n}(),Yi=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new zi(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Ki(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),Xi={};var qi=P((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]})),Ji=Z.vec4([0,0,0,1]),Zi=Z.vec4([0,0,0,1]),$i=Z.vec4([0,0,0,1]),ea=Z.OBB3(),ta=function(){function e(t){var n,r,i;b(this,e),this.layerIndex=t.layerIndex,this._batchingRenderers=(n=t.model.scene,r=n.id,(i=Xi[r])||(i=new Yi(n),Xi[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Xi[r],i._destroy()}))),i),this.model=t.model,this._buffer=new qi(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Mt({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:Z.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=Z.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=Z.vec3(t.origin)),this.aabb=Z.collapseAABB3()}return P(e,[{key:"canCreatePortion",value:function(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){var r=new Uint16Array(n.positions);e.positionsBuf=new pt(t,t.ARRAY_BUFFER,r,n.positions.length,3,t.STATIC_DRAW)}else{var i=bn(new Float32Array(n.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new pt(t,t.ARRAY_BUFFER,i,n.positions.length,3,t.STATIC_DRAW)}if(n.colors.length>0){var a=new Uint8Array(n.colors);e.colorsBuf=new pt(t,t.ARRAY_BUFFER,a,n.colors.length,4,t.DYNAMIC_DRAW,!1)}if(n.colors.length>0){var s=n.colors.length/4,o=new Float32Array(s);e.flagsBuf=new pt(t,t.ARRAY_BUFFER,o,o.length,1,t.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var l=new Float32Array(n.offsets);e.offsetsBuf=new pt(t,t.ARRAY_BUFFER,l,n.offsets.length,3,t.DYNAMIC_DRAW)}if(n.indices.length>0){var u=new Uint32Array(n.indices);e.indicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,u,n.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&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,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{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._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=2*e,r=4*this._portions[n],i=4*this._portions[n+1],a=this._scratchMemory.getUInt8Array(i),s=t[0],o=t[1],l=t[2],u=t[3],c=0;c3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=2*e,o=this._portions[s],l=this._portions[s+1],u=o,c=l,f=!!(t&Te),p=!!(t&Re),A=!!(t&Ce),d=!!(t&_e),v=!!(t&be),h=!!(t&Ee);i=!f||h||p||A&&!this.model.scene.highlightMaterial.glowThrough||d&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,a=!f||h?Lt.NOT_RENDERED:d?Lt.SILHOUETTE_SELECTED:A?Lt.SILHOUETTE_HIGHLIGHTED:p?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED;var I=f&&!h&&v?Lt.PICK:Lt.NOT_RENDERED,y=t&De?1:0;if(r){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var m=u,w=u+c;m0,n=[];return n.push("#version 300 es"),n.push("// Lines instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 lightAmbient;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),ra=function(e){I(n,nn);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 color;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines instancing silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = color;"),r.push("}"),r}}]),n}(),ia=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new na(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ra(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),aa={};var sa=new Uint8Array(4),oa=new Float32Array(1),la=Z.vec4([0,0,0,1]),ua=Z.vec4([0,0,0,1]),ca=Z.vec4([0,0,0,1]),fa=new Float32Array(3),pa=function(){function e(t){var n,r,i;b(this,e),this.model=t.model,this.material=t.material,this.sortId="LinesInstancingLayer",this.layerIndex=t.layerIndex,this._linesInstancingRenderers=(n=t.model.scene,r=n.id,(i=aa[r])||(i=new ia(n),aa[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete aa[r],i._destroy()}))),i),this._aabb=Z.collapseAABB3(),this._state=new Mt({obb:Z.OBB3(),numInstances:0,origin:null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],t.origin&&(this._state.origin=Z.vec3(t.origin)),this._finalized=!1,this.aabb=Z.collapseAABB3()}return P(e,[{key:"createPortion",value:function(e){var t=e.color,n=e.opacity,r=e.meshMatrix,i=e.worldMatrix,a=e.aabb;if(this._finalized)throw"Already finalized";var s=t[0],o=t[1],l=t[2];t[3],this._colors.push(s),this._colors.push(o),this._colors.push(l),this._colors.push(n),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(r[0]),this._modelMatrixCol0.push(r[4]),this._modelMatrixCol0.push(r[8]),this._modelMatrixCol0.push(r[12]),this._modelMatrixCol1.push(r[1]),this._modelMatrixCol1.push(r[5]),this._modelMatrixCol1.push(r[9]),this._modelMatrixCol1.push(r[13]),this._modelMatrixCol2.push(r[2]),this._modelMatrixCol2.push(r[6]),this._modelMatrixCol2.push(r[10]),this._modelMatrixCol2.push(r[14]),Z.collapseAABB3(a);for(var u=this._state.obb,c=u.length,f=0;f0){this._state.colorsBuf=new pt(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,!1),this._colors=[]}if(n>0){this._state.flagsBuf=new pt(e,e.ARRAY_BUFFER,new Float32Array(n),n,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){this._state.offsetsBuf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(this._modelMatrixCol0.length>0){var r=!1;this._state.modelMatrixCol0Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,r),this._state.modelMatrixCol1Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,r),this._state.modelMatrixCol2Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,r),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,n){t&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)}},{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._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";sa[0]=t[0],sa[1]=t[1],sa[2]=t[2],sa[3]=t[3],this._state.colorsBuf.setData(sa,4*e,4)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Te),i=!!(t&Re),a=!!(t&Ce),s=!!(t&_e),o=!!(t&Be),l=!!(t&be),u=!!(t&Ee),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.SILHOUETTE_SELECTED:a?Lt.SILHOUETTE_HIGHLIGHTED:i?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED)<<4,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.EDGES_SELECTED:a?Lt.EDGES_HIGHLIGHTED:i?Lt.EDGES_XRAYED:o?n?Lt.EDGES_COLOR_TRANSPARENT:Lt.EDGES_COLOR_OPAQUE:Lt.NOT_RENDERED)<<8,c|=(r&&!u&&l?Lt.PICK:Lt.NOT_RENDERED)<<12,c|=(t&De?255:0)<<16,oa[0]=c,this._state.flagsBuf.setData(oa,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(fa[0]=t[0],fa[1]=t[1],fa[2]=t[2],this._state.offsetsBuf.setData(fa,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Lt.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Lt.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){}},{key:"drawPickDepths",value:function(e,t){}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}]),e}(),Aa=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial,r=[];return r.push("#version 300 es"),r.push("// Points batching color vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("in float flags;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),n.filterIntensity&&r.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),n.filterIntensity&&(r.push("float intensity = float(color.a) / 255.0;"),r.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {")),r.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),n.filterIntensity&&r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),da=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching silhouette vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),this._addMatricesUniformBlockLines(r),r.push("uniform vec4 color;"),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),r.push("if (silhouetteFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}]),n}(),va=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching pick mesh vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 pickColor;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vPickColor;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),r.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("gl_PointSize += 10.0;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching pick mesh vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vPickColor; "),r.push("}"),r}}]),n}(),ha=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batched pick depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vViewPosition;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vViewPosition = viewPosition;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("gl_PointSize += 10.0;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batched pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Ia=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching occlusion vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push(" gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching occlusion fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),r.push("}"),r}}]),n}(),ya=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Aa(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new da(this._scene)),this._silhouetteRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new va(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new ha(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Ia(this._scene)),this._occlusionRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}]),e}(),ma={};var wa=P((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]})),ga=Z.vec4(),Ta=Z.vec4(),Ea=Z.vec4([0,0,0,1]),ba=Z.vec4([0,0,0,1]),Da=Z.vec4([0,0,0,1]),Pa=Z.OBB3(),Ra=function(){function e(t){b(this,e),this.model=t.model,this.sortId="PointsBatchingLayer",this.layerIndex=t.layerIndex,this._pointsBatchingRenderers=function(e){var t=e.id,n=ma[t];return n||(n=new ya(e),ma[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete ma[t],n._destroy()}))),n}(t.model.scene),this._buffer=new wa(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Mt({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:Z.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=Z.collapseAABB3(),this._portions=[],this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=Z.vec3(t.origin)),this.aabb=Z.collapseAABB3()}return P(e,[{key:"canCreatePortion",value:function(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}},{key:"createPortion",value:function(e){if(this._finalized)throw"Already finalized";var t,n=e.positions,r=e.positionsCompressed,i=e.color,a=e.colorsCompressed,s=e.colors,o=e.meshMatrix,l=e.worldMatrix,u=e.worldAABB,c=e.pickColor,f=this._buffer,p=f.positions.length/3;if(this._preCompressedPositionsExpected){if(!r)throw"positionsCompressed expected";for(var A=0,d=r.length;A0)if(this._preCompressedPositionsExpected){var r=new Uint16Array(n.positions);e.positionsBuf=new pt(t,t.ARRAY_BUFFER,r,n.positions.length,3,t.STATIC_DRAW)}else{var i=bn(new Float32Array(n.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new pt(t,t.ARRAY_BUFFER,i,n.positions.length,3,t.STATIC_DRAW)}if(n.colors.length>0){var a=new Uint8Array(n.colors);e.colorsBuf=new pt(t,t.ARRAY_BUFFER,a,n.colors.length,4,t.STATIC_DRAW,!1)}if(n.positions.length>0){var s=n.positions.length/3,o=new Float32Array(s);e.flagsBuf=new pt(t,t.ARRAY_BUFFER,o,o.length,1,t.DYNAMIC_DRAW,!1)}if(n.pickColors.length>0){var l=new Uint8Array(n.pickColors);e.pickColorsBuf=new pt(t,t.ARRAY_BUFFER,l,n.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var u=new Float32Array(n.offsets);e.offsetsBuf=new pt(t,t.ARRAY_BUFFER,u,n.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&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._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ee&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&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"}},{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._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=2*e,r=4*this._portions[n],i=4*this._portions[n+1],a=this._scratchMemory.getUInt8Array(i),s=t[0],o=t[1],l=t[2],u=0;u0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing color vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("in float flags;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),n.filterIntensity&&r.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),n.filterIntensity&&(r.push("float intensity = float(color.a) / 255.0;"),r.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {")),r.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),n.filterIntensity&&r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),_a=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing silhouette vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 color;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),r.push("uniform vec4 silhouetteColor;"),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),r.push("if (silhouetteFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ba=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing pick mesh vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 pickColor;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vPickColor;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),r.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing pick mesh fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vPickColor; "),r.push("}"),r}}]),n}(),Oa=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing pick depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vViewPosition;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push(" vViewPosition = viewPosition;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Sa=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing occlusion vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in vec4 color;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing occlusion vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),Na=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),La=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry shadow drawing vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("bool visible = (colorFlag > 0);"),n.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push("if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n.push("gl_PointSize = pointSize;"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),xa=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Ca(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new _a(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new Na(this._scene)),this._depthRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Ba(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Oa(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Sa(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new La(this._scene)),this._shadowRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}]),e}(),Ma={};var Fa=new Uint8Array(4),Ha=new Float32Array(1),Ua=Z.vec4([0,0,0,1]),Ga=Z.vec4([0,0,0,1]),ka=Z.vec4([0,0,0,1]),Va=new Float32Array(3),ja=function(){function e(t){var n,r,i;b(this,e),this.model=t.model,this.material=t.material,this.sortId="PointsInstancingLayer",this.layerIndex=t.layerIndex,this._pointsInstancingRenderers=(n=t.model.scene,r=n.id,(i=Ma[r])||(i=new xa(n),Ma[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Ma[r],i._destroy()}))),i),this._aabb=Z.collapseAABB3(),this._state=new Mt({obb:Z.OBB3(),numInstances:0,origin:t.origin?Z.vec3(t.origin):null,geometry:t.geometry,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=Z.collapseAABB3()}return P(e,[{key:"createPortion",value:function(e){var t=e.meshMatrix,n=e.worldMatrix,r=e.aabb,i=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(i[0]),this._pickColors.push(i[1]),this._pickColors.push(i[2]),this._pickColors.push(i[3]),Z.collapseAABB3(r);for(var a=this._state.obb,s=a.length,o=0;o0){this._state.flagsBuf=new pt(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){this._state.offsetsBuf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(this._modelMatrixCol0.length>0){var n=!1;this._state.modelMatrixCol0Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,n),this._state.modelMatrixCol1Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,n),this._state.modelMatrixCol2Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,n),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){this._state.pickColorsBuf=new pt(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,!1),this._pickColors=[]}this._state.geometry=null,this._finalized=!0}},{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)}},{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._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Fa[0]=t[0],Fa[1]=t[1],Fa[2]=t[2],this._state.colorsBuf.setData(Fa,3*e)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Te),i=!!(t&Re),a=!!(t&Ce),s=!!(t&_e),o=!!(t&Be),l=!!(t&be),u=!!(t&Ee),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.SILHOUETTE_SELECTED:a?Lt.SILHOUETTE_HIGHLIGHTED:i?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED)<<4,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.EDGES_SELECTED:a?Lt.EDGES_HIGHLIGHTED:i?Lt.EDGES_XRAYED:o?n?Lt.EDGES_COLOR_TRANSPARENT:Lt.EDGES_COLOR_OPAQUE:Lt.NOT_RENDERED)<<8,c|=(r&&!u&&l?Lt.PICK:Lt.NOT_RENDERED)<<12,c|=(t&De?255:0)<<16,Ha[0]=c,this._state.flagsBuf.setData(Ha,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Va[0]=t[0],Va[1]=t[1],Va[2]=t[2],this._state.offsetsBuf.setData(Va,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Lt.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Lt.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,Lt.COLOR_OPAQUE)}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Lt.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Lt.PICK)}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}]),e}(),Qa=function(){function e(){b(this,e),this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}return P(e,[{key:"reset",value:function(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}]),e}(),Wa=function(){function e(t){b(this,e),this.id=t.id,this.colorTexture=t.colorTexture,this.metallicRoughnessTexture=t.metallicRoughnessTexture,this.normalsTexture=t.normalsTexture,this.emissiveTexture=t.emissiveTexture,this.occlusionTexture=t.occlusionTexture}return P(e,[{key:"destroy",value:function(){}}]),e}(),za=function(){function e(t){b(this,e),this.id=t.id,this.texture=t.texture}return P(e,[{key:"destroy",value:function(){this.texture&&(this.texture.destroy(),this.texture=null)}}]),e}();function Ka(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===r){var a=Ct(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===a)return null;if(33776===i)return a.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(n=Ct(e,"WEBGL_compressed_texture_s3tc")))return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){var s=Ct(e,"WEBGL_compressed_texture_pvrtc");if(null===s)return null;if(35840===i)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){var o=Ct(e,"WEBGL_compressed_texture_etc1");return null!==o?o.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){var l=Ct(e,"WEBGL_compressed_texture_etc");if(null===l)return null;if(37492===i)return 3001===r?l.COMPRESSED_SRGB8_ETC2:l.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===r?l.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:l.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){var u=Ct(e,"WEBGL_compressed_texture_astc");if(null===u)return null;if(37808===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:u.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:u.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:u.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:u.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:u.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:u.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:u.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:u.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:u.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:u.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:u.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:u.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:u.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:u.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){var c=Ct(e,"EXT_texture_compression_bptc");if(null===c)return null;if(36492===i)return 3001===r?c.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:c.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}var Ya=new Uint8Array([0,0,0,1]),Xa=function(){function e(t){var n=t.gl,r=t.target,i=t.format,a=t.type,s=t.wrapS,o=t.wrapT,l=t.wrapR,u=t.encoding,c=t.preloadColor,f=t.premultiplyAlpha,p=t.flipY;b(this,e),this.gl=n,this.target=r||n.TEXTURE_2D,this.format=i||1023,this.type=a||1009,this.internalFormat=null,this.premultiplyAlpha=!!f,this.flipY=!!p,this.unpackAlignment=4,this.wrapS=s||1e3,this.wrapT=o||1e3,this.wrapR=l||1e3,this.encoding=u||3001,this.texture=n.createTexture(),c&&this.setPreloadColor(c),this.allocated=!0}return P(e,[{key:"setPreloadColor",value:function(e){e?(Ya[0]=Math.floor(255*e[0]),Ya[1]=Math.floor(255*e[1]),Ya[2]=Math.floor(255*e[2]),Ya[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(Ya[0]=0,Ya[1]=0,Ya[2]=0,Ya[3]=255);var t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP)for(var n=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],r=0,i=n.length;r1&&void 0!==arguments[1]?arguments[1]:{},n=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);var r=!1;n.bindTexture(this.target,this.texture);var i=n.getParameter(n.UNPACK_FLIP_Y_WEBGL);n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,this.flipY);var a=n.getParameter(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL);n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);var s=n.getParameter(n.UNPACK_ALIGNMENT);n.pixelStorei(n.UNPACK_ALIGNMENT,this.unpackAlignment);var o=n.getParameter(n.UNPACK_COLORSPACE_CONVERSION_WEBGL);n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,n.NONE);var l=Ka(n,this.minFilter);n.texParameteri(this.target,n.TEXTURE_MIN_FILTER,l),l!==n.NEAREST_MIPMAP_NEAREST&&l!==n.LINEAR_MIPMAP_NEAREST&&l!==n.NEAREST_MIPMAP_LINEAR&&l!==n.LINEAR_MIPMAP_LINEAR||(r=!0);var u=Ka(n,this.magFilter);u&&n.texParameteri(this.target,n.TEXTURE_MAG_FILTER,u);var c=Ka(n,this.wrapS);c&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,c);var f=Ka(n,this.wrapT);f&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,f);var p=Ka(n,this.format,this.encoding),A=Ka(n,this.type),d=qa(n,this.internalFormat,p,A,this.encoding,!1);if(this.target===n.TEXTURE_CUBE_MAP){if(ae.isArray(e))for(var v=e,h=[n.TEXTURE_CUBE_MAP_POSITIVE_X,n.TEXTURE_CUBE_MAP_NEGATIVE_X,n.TEXTURE_CUBE_MAP_POSITIVE_Y,n.TEXTURE_CUBE_MAP_NEGATIVE_Y,n.TEXTURE_CUBE_MAP_POSITIVE_Z,n.TEXTURE_CUBE_MAP_NEGATIVE_Z],I=0,y=h.length;I1;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);var o=Ka(i,this.wrapS);o&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,o);var l=Ka(i,this.wrapT);if(l&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,l),this.type===i.TEXTURE_3D||this.type===i.TEXTURE_2D_ARRAY){var u=Ka(i,this.wrapR);u&&i.texParameteri(this.target,i.TEXTURE_WRAP_R,u),i.texParameteri(this.type,i.TEXTURE_WRAP_R,u)}s?(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Ja(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ja(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Ka(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ka(i,this.magFilter)));var c=Ka(i,this.format,this.encoding),f=Ka(i,this.type),p=qa(i,this.internalFormat,c,f,this.encoding,!1);i.texStorage2D(i.TEXTURE_2D,a,p,t[0].width,t[0].height);for(var A=0,d=t.length;A5&&void 0!==arguments[5]&&arguments[5];if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}var s=n;return n===e.RED&&(r===e.FLOAT&&(s=e.R32F),r===e.HALF_FLOAT&&(s=e.R16F),r===e.UNSIGNED_BYTE&&(s=e.R8)),n===e.RG&&(r===e.FLOAT&&(s=e.RG32F),r===e.HALF_FLOAT&&(s=e.RG16F),r===e.UNSIGNED_BYTE&&(s=e.RG8)),n===e.RGBA&&(r===e.FLOAT&&(s=e.RGBA32F),r===e.HALF_FLOAT&&(s=e.RGBA16F),r===e.UNSIGNED_BYTE&&(s=3001===i&&!1===a?e.SRGB8_ALPHA8:e.RGBA8),r===e.UNSIGNED_SHORT_4_4_4_4&&(s=e.RGBA4),r===e.UNSIGNED_SHORT_5_5_5_1&&(s=e.RGB5_A1)),s!==e.R16F&&s!==e.R32F&&s!==e.RG16F&&s!==e.RG32F&&s!==e.RGBA16F&&s!==e.RGBA32F||Ct(e,"EXT_color_buffer_float"),s}function Ja(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}var Za={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}},$a=function(){function e(t,n,r){b(this,e),this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=t,this.onProgress=n,this.onError=r}return P(e,[{key:"itemStart",value:function(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}},{key:"itemEnd",value:function(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}},{key:"itemError",value:function(e){void 0!==this.onError&&this.onError(e)}},{key:"resolveURL",value:function(e){return this.urlModifier?this.urlModifier(e):e}},{key:"setURLModifier",value:function(e){return this.urlModifier=e,this}},{key:"addHandler",value:function(e,t){return this.handlers.push(e,t),this}},{key:"removeHandler",value:function(e){var t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}},{key:"getHandler",value:function(e){for(var t=0,n=this.handlers.length;t0&&void 0!==arguments[0]?arguments[0]:4;b(this,e),this.pool=t,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}return P(e,[{key:"_initWorker",value:function(e){if(!this.workers[e]){var t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}},{key:"_getIdleWorker",value:function(){for(var e=0;e0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),as++}return this._transcoderPending}},{key:"transcode",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,a){var s=r;n._init().then((function(){return n._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:s},e)})).then((function(e){var n=e.data,r=n.mipmaps,s=(n.width,n.height,n.format),o=n.type,l=n.error,u=n.dfdTransferFn,c=n.dfdFlags;if("error"===o)return a(l);t.setCompressedData({mipmaps:r,props:{format:s,minFilter:1===r.length?1006:1008,magFilter:1===r.length?1006:1008,encoding:2===u?3001:3e3,premultiplyAlpha:!!(1&c)}}),i()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),as--}}]),e}();ss.BasisFormat={ETC1S:0,UASTC_4x4:1},ss.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},ss.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},ss.BasisWorker=function(){var e,t,n,r=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(s){var c,f=s.data;switch(f.type){case"init":e=f.config,c=f.transcoderBinary,t=new Promise((function(e){n={wasmBinary:c,onRuntimeInitialized:e},BASIS(n)})).then((function(){n.initializeBasis(),void 0===n.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((function(){try{for(var t=function(t){var s=new n.KTX2File(new Uint8Array(t));function c(){s.close(),s.delete()}if(!s.isValid())throw c(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var f=s.isUASTC()?a.UASTC_4x4:a.ETC1S,p=s.getWidth(),A=s.getHeight(),d=s.getLevels(),v=s.getHasAlpha(),h=s.getDFDTransferFunc(),I=s.getDFDFlags(),y=function(t,n,s,c){for(var f,p,A=t===a.ETC1S?o:l,d=0;d=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var o=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(o&&l){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),b(n),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;b(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:P(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},e}function u(e,t,n,r,i,a,s){try{var o=e[a](s),l=o.value}catch(e){return void n(e)}o.done?t(l):Promise.resolve(l).then(r,i)}function c(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function s(e){u(a,r,i,s,o,"next",e)}function o(e){u(a,r,i,s,o,"throw",e)}s(void 0)}))}}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=A(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}(e,t)||A(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._id=k.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==n.hideOnMouseDown&&(document.addEventListener("mousedown",(function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),n.items&&(this.items=n.items),this._hideOnAction=!1!==n.hideOnAction,this.context=n.context,this.enabled=!1!==n.enabled,this.hide()}return P(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r0,c=t._getNextId(),f=a.getTitle||function(){return a.title||""},p=a.doAction||a.callback||function(){},A=a.getEnabled||function(){return!0},d=a.getShown||function(){return!0},v=new Q(c,f,p,A,d);if(v.parentMenu=i,l.items.push(v),u){var h=e(s);v.subMenu=h,h.parentItem=v}t._itemList.push(v),t._itemMap[v.id]=v},c=0,f=o.length;c'),r.push("
    "),n)for(var i=0,a=n.length;i'+A+" [MORE]"):r.push('
  • '+A+"
  • ")}}r.push("
"),r.push("");var d=r.join("");document.body.insertAdjacentHTML("beforeend",d);var v=document.querySelector("."+e.id);e.menuElement=v,v.style["border-radius"]="4px",v.style.display="none",v.style["z-index"]=3e5,v.style.background="white",v.style.border="1px solid black",v.style["box-shadow"]="0 4px 5px 0 gray",v.oncontextmenu=function(e){e.preventDefault()};var h=this,I=null;if(n)for(var y=0,m=n.length;ywindow.innerWidth?h._showMenu(t.id,a.left-200,a.top-1):h._showMenu(t.id,a.right-5,a.top-1),I=t}}else I&&(h._hideMenu(I.id),I=null)})),i||(r.itemElement.addEventListener("click",(function(e){e.preventDefault(),h._context&&!1!==r.enabled&&(r.doAction&&r.doAction(h._context),t._hideOnAction?h.hide():(h._updateItemsTitles(),h._updateItemsEnabledStatus()))})),r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==r.enabled&&r.doHover&&r.doHover(h._context)})))},T=0,E=w.length;Twindow.innerHeight&&(n=window.innerHeight-r),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=n+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),z=function(){function e(t,n,r){b(this,e),this.id=r&&r.id?r.id:t,this.viewer=n,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,n.addPlugin(this)}return P(e,[{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){console.log("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"warn",value:function(e){console.warn("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"error",value:function(e){console.error("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.removePlugin(this)}}]),e}(),K=!0,Y=K?Float64Array:Float32Array,X=new Y(16),q=new Y(16),J=new Y(4),Z={setDoublePrecisionEnabled:function(e){Y=(K=e)?Float64Array:Float32Array},getDoublePrecisionEnabled:function(){return K},MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId:function(e,t){var n=t.indexOf("#");return n===e.length&&t.startsWith(e)?t.substring(n+1):t},globalizeObjectId:function(e,t){return e+"#"+t},safeInv:function(e){var t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:function(e){return new Y(e||2)},vec3:function(e){return new Y(e||3)},vec4:function(e){return new Y(e||4)},mat3:function(e){return new Y(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Y(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},mat4:function(e){return new Y(e||16)},mat4ToMat3:function(e,t){},doublesToFloats:function(e,t,n){for(var r=new Y(2),i=0,a=e.length;i>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&n]).concat(e[n>>8&255],"-").concat(e[n>>16&15|64]).concat(e[n>>24&255],"-").concat(e[63&r|128]).concat(e[r>>8&255],"-").concat(e[r>>16&255]).concat(e[r>>24&255]).concat(e[255&i]).concat(e[i>>8&255]).concat(e[i>>16&255]).concat(e[i>>24&255])}}(),clamp:function(e,t,n){return Math.max(t,Math.min(n,e))},fmod:function(e,t){if(e1?1:n,Math.acos(n)},vec3FromMat4Scale:function(){var e=new Y(3);return function(t,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],n[0]=Z.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],n[1]=Z.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],n[2]=Z.lenVec3(e),n}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var n=0,r=(t=Array.prototype.slice.call(t)).length;n0&&void 0!==arguments[0]?arguments[0]:new Y(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},identityMat3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Y(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},isIdentityMat4:function(e){return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]},negateMat4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t},addMat4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n[4]=e[4]+t[4],n[5]=e[5]+t[5],n[6]=e[6]+t[6],n[7]=e[7]+t[7],n[8]=e[8]+t[8],n[9]=e[9]+t[9],n[10]=e[10]+t[10],n[11]=e[11]+t[11],n[12]=e[12]+t[12],n[13]=e[13]+t[13],n[14]=e[14]+t[14],n[15]=e[15]+t[15],n},addMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n[4]=e[4]+t,n[5]=e[5]+t,n[6]=e[6]+t,n[7]=e[7]+t,n[8]=e[8]+t,n[9]=e[9]+t,n[10]=e[10]+t,n[11]=e[11]+t,n[12]=e[12]+t,n[13]=e[13]+t,n[14]=e[14]+t,n[15]=e[15]+t,n},addScalarMat4:function(e,t,n){return Z.addMat4Scalar(t,e,n)},subMat4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n[4]=e[4]-t[4],n[5]=e[5]-t[5],n[6]=e[6]-t[6],n[7]=e[7]-t[7],n[8]=e[8]-t[8],n[9]=e[9]-t[9],n[10]=e[10]-t[10],n[11]=e[11]-t[11],n[12]=e[12]-t[12],n[13]=e[13]-t[13],n[14]=e[14]-t[14],n[15]=e[15]-t[15],n},subMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n[4]=e[4]-t,n[5]=e[5]-t,n[6]=e[6]-t,n[7]=e[7]-t,n[8]=e[8]-t,n[9]=e[9]-t,n[10]=e[10]-t,n[11]=e[11]-t,n[12]=e[12]-t,n[13]=e[13]-t,n[14]=e[14]-t,n[15]=e[15]-t,n},subScalarMat4:function(e,t,n){return n||(n=t),n[0]=e-t[0],n[1]=e-t[1],n[2]=e-t[2],n[3]=e-t[3],n[4]=e-t[4],n[5]=e-t[5],n[6]=e-t[6],n[7]=e-t[7],n[8]=e-t[8],n[9]=e-t[9],n[10]=e-t[10],n[11]=e-t[11],n[12]=e-t[12],n[13]=e-t[13],n[14]=e-t[14],n[15]=e-t[15],n},mulMat4:function(e,t,n){n||(n=e);var r=e[0],i=e[1],a=e[2],s=e[3],o=e[4],l=e[5],u=e[6],c=e[7],f=e[8],p=e[9],A=e[10],d=e[11],v=e[12],h=e[13],I=e[14],y=e[15],m=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],L=t[15];return n[0]=m*r+w*o+g*f+T*v,n[1]=m*i+w*l+g*p+T*h,n[2]=m*a+w*u+g*A+T*I,n[3]=m*s+w*c+g*d+T*y,n[4]=E*r+b*o+D*f+P*v,n[5]=E*i+b*l+D*p+P*h,n[6]=E*a+b*u+D*A+P*I,n[7]=E*s+b*c+D*d+P*y,n[8]=R*r+C*o+_*f+B*v,n[9]=R*i+C*l+_*p+B*h,n[10]=R*a+C*u+_*A+B*I,n[11]=R*s+C*c+_*d+B*y,n[12]=O*r+S*o+N*f+L*v,n[13]=O*i+S*l+N*p+L*h,n[14]=O*a+S*u+N*A+L*I,n[15]=O*s+S*c+N*d+L*y,n},mulMat3:function(e,t,n){n||(n=new Y(9));var r=e[0],i=e[3],a=e[6],s=e[1],o=e[4],l=e[7],u=e[2],c=e[5],f=e[8],p=t[0],A=t[3],d=t[6],v=t[1],h=t[4],I=t[7],y=t[2],m=t[5],w=t[8];return n[0]=r*p+i*v+a*y,n[3]=r*A+i*h+a*m,n[6]=r*d+i*I+a*w,n[1]=s*p+o*v+l*y,n[4]=s*A+o*h+l*m,n[7]=s*d+o*I+l*w,n[2]=u*p+c*v+f*y,n[5]=u*A+c*h+f*m,n[8]=u*d+c*I+f*w,n},mulMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n[4]=e[4]*t,n[5]=e[5]*t,n[6]=e[6]*t,n[7]=e[7]*t,n[8]=e[8]*t,n[9]=e[9]*t,n[10]=e[10]*t,n[11]=e[11]*t,n[12]=e[12]*t,n[13]=e[13]*t,n[14]=e[14]*t,n[15]=e[15]*t,n},mulMat4v4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=t[0],i=t[1],a=t[2],s=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12]*s,n[1]=e[1]*r+e[5]*i+e[9]*a+e[13]*s,n[2]=e[2]*r+e[6]*i+e[10]*a+e[14]*s,n[3]=e[3]*r+e[7]*i+e[11]*a+e[15]*s,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],a=e[13],s=e[12],o=e[9];if(!t||e===t){var l=e[1],u=e[2],c=e[3],f=e[6],p=e[7],A=e[11];return e[1]=n,e[2]=i,e[3]=s,e[4]=l,e[6]=o,e[7]=a,e[8]=u,e[9]=f,e[11]=r,e[12]=c,e[13]=p,e[14]=A,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=s,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=r,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3:function(e,t){if(t===e){var n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4:function(e){var t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],s=e[5],o=e[6],l=e[7],u=e[8],c=e[9],f=e[10],p=e[11],A=e[12],d=e[13],v=e[14],h=e[15];return A*c*o*i-u*d*o*i-A*s*f*i+a*d*f*i+u*s*v*i-a*c*v*i-A*c*r*l+u*d*r*l+A*n*f*l-t*d*f*l-u*n*v*l+t*c*v*l+A*s*r*p-a*d*r*p-A*n*o*p+t*d*o*p+a*n*v*p-t*s*v*p-u*s*r*h+a*c*r*h+u*n*o*h-t*c*o*h-a*n*f*h+t*s*f*h},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],a=e[3],s=e[4],o=e[5],l=e[6],u=e[7],c=e[8],f=e[9],p=e[10],A=e[11],d=e[12],v=e[13],h=e[14],I=e[15],y=n*o-r*s,m=n*l-i*s,w=n*u-a*s,g=r*l-i*o,T=r*u-a*o,E=i*u-a*l,b=c*v-f*d,D=c*h-p*d,P=c*I-A*d,R=f*h-p*v,C=f*I-A*v,_=p*I-A*h,B=1/(y*_-m*C+w*R+g*P-T*D+E*b);return t[0]=(o*_-l*C+u*R)*B,t[1]=(-r*_+i*C-a*R)*B,t[2]=(v*E-h*T+I*g)*B,t[3]=(-f*E+p*T-A*g)*B,t[4]=(-s*_+l*P-u*D)*B,t[5]=(n*_-i*P+a*D)*B,t[6]=(-d*E+h*w-I*m)*B,t[7]=(c*E-p*w+A*m)*B,t[8]=(s*C-o*P+u*b)*B,t[9]=(-n*C+r*P-a*b)*B,t[10]=(d*T-v*w+I*y)*B,t[11]=(-c*T+f*w-A*y)*B,t[12]=(-s*R+o*D-l*b)*B,t[13]=(n*R-r*D+i*b)*B,t[14]=(-d*g+v*m-h*y)*B,t[15]=(c*g-f*m+p*y)*B,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var n=t||Z.identityMat4();return n[12]=e[0],n[13]=e[1],n[14]=e[2],n},translationMat3v:function(e,t){var n=t||Z.identityMat3();return n[6]=e[0],n[7]=e[1],n},translationMat4c:(H=new Y(3),function(e,t,n,r){return H[0]=e,H[1]=t,H[2]=n,Z.translationMat4v(H,r)}),translationMat4s:function(e,t){return Z.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return Z.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,n,r){var i=r[3];r[0]+=i*e,r[1]+=i*t,r[2]+=i*n;var a=r[7];r[4]+=a*e,r[5]+=a*t,r[6]+=a*n;var s=r[11];r[8]+=s*e,r[9]+=s*t,r[10]+=s*n;var o=r[15];return r[12]+=o*e,r[13]+=o*t,r[14]+=o*n,r},setMat4Translation:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=e[15],n},rotationMat4v:function(e,t,n){var r,i,a,s,o,l,u=Z.normalizeVec4([t[0],t[1],t[2],0],[]),c=Math.sin(e),f=Math.cos(e),p=1-f,A=u[0],d=u[1],v=u[2];return r=A*d,i=d*v,a=v*A,s=A*c,o=d*c,l=v*c,(n=n||Z.mat4())[0]=p*A*A+f,n[1]=p*r+l,n[2]=p*a-o,n[3]=0,n[4]=p*r-l,n[5]=p*d*d+f,n[6]=p*i+s,n[7]=0,n[8]=p*a+o,n[9]=p*i-s,n[10]=p*v*v+f,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},rotationMat4c:function(e,t,n,r,i){return Z.rotationMat4v(e,[t,n,r],i)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.identityMat4();return t[0]=e[0],t[5]=e[1],t[10]=e[2],t},scalingMat3v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new Y(3);return function(t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,Z.scalingMat4v(e,i)}}(),scaleMat4c:function(e,t,n,r){return r[0]*=e,r[4]*=t,r[8]*=n,r[1]*=e,r[5]*=t,r[9]*=n,r[2]*=e,r[6]*=t,r[10]*=n,r[3]*=e,r[7]*=t,r[11]*=n,r},scaleMat4v:function(e,t){var n=e[0],r=e[1],i=e[2];return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,t},scalingMat4s:function(e){return Z.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.mat4(),r=e[0],i=e[1],a=e[2],s=e[3],o=r+r,l=i+i,u=a+a,c=r*o,f=r*l,p=r*u,A=i*l,d=i*u,v=a*u,h=s*o,I=s*l,y=s*u;return n[0]=1-(A+v),n[1]=f+y,n[2]=p-I,n[3]=0,n[4]=f-y,n[5]=1-(c+v),n[6]=d+h,n[7]=0,n[8]=p+I,n[9]=d-h,n[10]=1-(c+A),n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n},mat4ToEuler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=Z.clamp,i=e[0],a=e[4],s=e[8],o=e[1],l=e[5],u=e[9],c=e[2],f=e[6],p=e[10];return"XYZ"===t?(n[1]=Math.asin(r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(-u,p),n[2]=Math.atan2(-a,i)):(n[0]=Math.atan2(f,l),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(u,-1,1)),Math.abs(u)<.99999?(n[1]=Math.atan2(s,p),n[2]=Math.atan2(o,l)):(n[1]=Math.atan2(-c,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(f,-1,1)),Math.abs(f)<.99999?(n[1]=Math.atan2(-c,p),n[2]=Math.atan2(-a,l)):(n[1]=0,n[2]=Math.atan2(o,i))):"ZYX"===t?(n[1]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[0]=Math.atan2(f,p),n[2]=Math.atan2(o,i)):(n[0]=0,n[2]=Math.atan2(-a,l))):"YZX"===t?(n[2]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-u,l),n[1]=Math.atan2(-c,i)):(n[0]=0,n[1]=Math.atan2(s,p))):"XZY"===t&&(n[2]=Math.asin(-r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(f,l),n[1]=Math.atan2(s,i)):(n[0]=Math.atan2(-u,p),n[1]=0)),n},composeMat4:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Z.mat4();return Z.quaternionToRotationMat4(t,r),Z.scaleMat4v(n,r),Z.translateMat4v(e,r),r},decomposeMat4:function(){var e=new Y(3),t=new Y(16);return function(n,r,i,a){e[0]=n[0],e[1]=n[1],e[2]=n[2];var s=Z.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var o=Z.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var l=Z.lenVec3(e);Z.determinantMat4(n)<0&&(s=-s),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var u=1/s,c=1/o,f=1/l;return t[0]*=u,t[1]*=u,t[2]*=u,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=f,t[9]*=f,t[10]*=f,Z.mat4ToQuaternion(t,i),a[0]=s,a[1]=o,a[2]=l,this}}(),getColMat4:function(e,t){var n=4*t;return[e[n],e[n+1],e[n+2],e[n+3]]},setRowMat4:function(e,t,n){e[t]=n[0],e[t+4]=n[1],e[t+8]=n[2],e[t+12]=n[3]},lookAtMat4v:function(e,t,n,r){r||(r=Z.mat4());var i,a,s,o,l,u,c,f,p,A,d=e[0],v=e[1],h=e[2],I=n[0],y=n[1],m=n[2],w=t[0],g=t[1],T=t[2];return d===w&&v===g&&h===T?Z.identityMat4():(i=d-w,a=v-g,s=h-T,o=y*(s*=A=1/Math.sqrt(i*i+a*a+s*s))-m*(a*=A),l=m*(i*=A)-I*s,u=I*a-y*i,(A=Math.sqrt(o*o+l*l+u*u))?(o*=A=1/A,l*=A,u*=A):(o=0,l=0,u=0),c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,(A=Math.sqrt(c*c+f*f+p*p))?(c*=A=1/A,f*=A,p*=A):(c=0,f=0,p=0),r[0]=o,r[1]=c,r[2]=i,r[3]=0,r[4]=l,r[5]=f,r[6]=a,r[7]=0,r[8]=u,r[9]=p,r[10]=s,r[11]=0,r[12]=-(o*d+l*v+u*h),r[13]=-(c*d+f*v+p*h),r[14]=-(i*d+a*v+s*h),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,a,s,o,l){return Z.lookAtMat4v([e,t,n],[r,i,a],[s,o,l],[])},orthoMat4c:function(e,t,n,r,i,a,s){s||(s=Z.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2/l,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=-2/u,s[11]=0,s[12]=-(e+t)/o,s[13]=-(r+n)/l,s[14]=-(a+i)/u,s[15]=1,s},frustumMat4v:function(e,t,n){n||(n=Z.mat4());var r=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];Z.addVec4(i,r,X),Z.subVec4(i,r,q);var a=2*r[2],s=q[0],o=q[1],l=q[2];return n[0]=a/s,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=a/o,n[6]=0,n[7]=0,n[8]=X[0]/s,n[9]=X[1]/o,n[10]=-X[2]/l,n[11]=-1,n[12]=0,n[13]=0,n[14]=-a*i[2]/l,n[15]=0,n},frustumMat4:function(e,t,n,r,i,a,s){s||(s=Z.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2*i/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2*i/l,s[6]=0,s[7]=0,s[8]=(t+e)/o,s[9]=(r+n)/l,s[10]=-(a+i)/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i*2/u,s[15]=0,s},perspectiveMat4:function(e,t,n,r,i){var a=[],s=[];return a[2]=n,s[2]=r,s[1]=a[2]*Math.tan(e/2),a[1]=-s[1],s[0]=s[1]*t,a[0]=-s[0],Z.frustumMat4v(a,s,i)},compareMat4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]},transformPoint3:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec3(),r=t[0],i=t[1],a=t[2];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12],n[1]=e[1]*r+e[5]*i+e[9]*a+e[13],n[2]=e[2]*r+e[6]*i+e[10]*a+e[14],n},transformPoint4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4();return n[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],n[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],n[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],n[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],n},transformPoints3:function(e,t,n){for(var r,i,a,s,o,l=n||[],u=t.length,c=e[0],f=e[1],p=e[2],A=e[3],d=e[4],v=e[5],h=e[6],I=e[7],y=e[8],m=e[9],w=e[10],g=e[11],T=e[12],E=e[13],b=e[14],D=e[15],P=0;P2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2];e[3];var f=e[4],p=e[5],A=e[6];e[7];var d=e[8],v=e[9],h=e[10];e[11];var I=e[12],y=e[13],m=e[14];for(e[15],n=0;n2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n3&&void 0!==arguments[3]?arguments[3]:e,i=Math.cos(n),a=Math.sin(n),s=e[0]-t[0],o=e[1]-t[1];return r[0]=s*i-o*a+t[0],r[1]=s*a+o*i+t[1],e},rotateVec3X:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Y:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Z:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},projectVec4:function(e,t){var n=1/e[3];return(t=t||Z.vec2())[0]=e[0]*n,t[1]=e[1]*n,t},unprojectVec3:(x=new Y(16),M=new Y(16),F=new Y(16),function(e,t,n,r){return this.transformVec3(this.mulMat4(this.inverseMat4(t,x),this.inverseMat4(n,M),F),e,r)}),lerpVec3:function(e,t,n,r,i,a){var s=a||Z.vec3(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s},lerpMat4:function(e,t,n,r,i,a){var s=a||Z.mat4(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s[3]=r[3]+o*(i[3]-r[3]),s[4]=r[4]+o*(i[4]-r[4]),s[5]=r[5]+o*(i[5]-r[5]),s[6]=r[6]+o*(i[6]-r[6]),s[7]=r[7]+o*(i[7]-r[7]),s[8]=r[8]+o*(i[8]-r[8]),s[9]=r[9]+o*(i[9]-r[9]),s[10]=r[10]+o*(i[10]-r[10]),s[11]=r[11]+o*(i[11]-r[11]),s[12]=r[12]+o*(i[12]-r[12]),s[13]=r[13]+o*(i[13]-r[13]),s[14]=r[14]+o*(i[14]-r[14]),s[15]=r[15]+o*(i[15]-r[15]),s},flatten:function(e){var t,n,r,i,a,s=[];for(t=0,n=e.length;t0&&void 0!==arguments[0]?arguments[0]:Z.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=e[0]*Z.DEGTORAD/2,i=e[1]*Z.DEGTORAD/2,a=e[2]*Z.DEGTORAD/2,s=Math.cos(r),o=Math.cos(i),l=Math.cos(a),u=Math.sin(r),c=Math.sin(i),f=Math.sin(a);return"XYZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"YXZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"ZXY"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"ZYX"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"YZX"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l-u*c*f):"XZY"===t&&(n[0]=u*o*l-s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l+u*c*f),n},mat4ToQuaternion:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),r=e[0],i=e[4],a=e[8],s=e[1],o=e[5],l=e[9],u=e[2],c=e[6],f=e[10],p=r+o+f;return p>0?(t=.5/Math.sqrt(p+1),n[3]=.25/t,n[0]=(c-l)*t,n[1]=(a-u)*t,n[2]=(s-i)*t):r>o&&r>f?(t=2*Math.sqrt(1+r-o-f),n[3]=(c-l)/t,n[0]=.25*t,n[1]=(i+s)/t,n[2]=(a+u)/t):o>f?(t=2*Math.sqrt(1+o-r-f),n[3]=(a-u)/t,n[0]=(i+s)/t,n[1]=.25*t,n[2]=(l+c)/t):(t=2*Math.sqrt(1+f-r-o),n[3]=(s-i)/t,n[0]=(a+u)/t,n[1]=(l+c)/t,n[2]=.25*t),n},vec3PairToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=Math.sqrt(Z.dotVec3(e,e)*Z.dotVec3(t,t)),i=r+Z.dotVec3(e,t);return i<1e-8*r?(i=0,Math.abs(e[0])>Math.abs(e[2])?(n[0]=-e[1],n[1]=e[0],n[2]=0):(n[0]=0,n[1]=-e[2],n[2]=e[1])):Z.cross3Vec3(e,t,n),n[3]=i,Z.normalizeQuaternion(n)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),n=e[3]/2,r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},quaternionToEuler:function(){var e=new Y(16);return function(t,n,r){return r=r||Z.vec3(),Z.quaternionToRotationMat4(t,e),Z.mat4ToEuler(e,n,r),r}}(),mulQuaternions:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=e[0],i=e[1],a=e[2],s=e[3],o=t[0],l=t[1],u=t[2],c=t[3];return n[0]=s*o+r*c+i*u-a*l,n[1]=s*l+i*c+a*o-r*u,n[2]=s*u+a*c+r*l-i*o,n[3]=s*c-r*o-i*l-a*u,n},vec3ApplyQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec3(),r=t[0],i=t[1],a=t[2],s=e[0],o=e[1],l=e[2],u=e[3],c=u*r+o*a-l*i,f=u*i+l*r-s*a,p=u*a+s*i-o*r,A=-s*r-o*i-l*a;return n[0]=c*u+A*-s+f*-l-p*-o,n[1]=f*u+A*-o+p*-s-c*-l,n[2]=p*u+A*-l+c*-o-f*-s,n},quaternionToMat4:function(e,t){t=Z.identityMat4(t);var n=e[0],r=e[1],i=e[2],a=e[3],s=2*n,o=2*r,l=2*i,u=s*a,c=o*a,f=l*a,p=s*n,A=o*n,d=l*n,v=o*r,h=l*r,I=l*i;return t[0]=1-(v+I),t[1]=A+f,t[2]=d-c,t[4]=A-f,t[5]=1-(p+I),t[6]=h+u,t[8]=d+c,t[9]=h-u,t[10]=1-(p+v),t},quaternionToRotationMat4:function(e,t){var n=e[0],r=e[1],i=e[2],a=e[3],s=n+n,o=r+r,l=i+i,u=n*s,c=n*o,f=n*l,p=r*o,A=r*l,d=i*l,v=a*s,h=a*o,I=a*l;return t[0]=1-(p+d),t[4]=c-I,t[8]=f+h,t[1]=c+I,t[5]=1-(u+d),t[9]=A-v,t[2]=f-h,t[6]=A+v,t[10]=1-(u+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=Z.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n,t[3]=e[3]/n,t},conjugateQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},inverseQuaternion:function(e,t){return Z.normalizeQuaternion(Z.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),n=(e=Z.normalizeQuaternion(e,J))[3],r=2*Math.acos(n),i=Math.sqrt(1-n*n);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=r,t},AABB3:function(e){return new Y(e||6)},AABB2:function(e){return new Y(e||4)},OBB3:function(e){return new Y(e||32)},OBB2:function(e){return new Y(e||16)},Sphere3:function(e,t,n,r){return new Y([e,t,n,r])},transformOBB3:function(e,t){var n,r,i,a,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;no?s:o,a[1]+=l>u?l:u,a[2]+=c>f?c:f,Math.abs(Z.lenVec3(a))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var n=t||Z.vec3();return n[0]=(e[0]+e[3])/2,n[1]=(e[1]+e[4])/2,n[2]=(e[2]+e[5])/2,n},getAABB2Center:function(e,t){var n=t||Z.vec2();return n[0]=(e[2]+e[0])/2,n[1]=(e[3]+e[1])/2,n},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Z.AABB3();return e[0]=Z.MAX_DOUBLE,e[1]=Z.MAX_DOUBLE,e[2]=Z.MAX_DOUBLE,e[3]=Z.MIN_DOUBLE,e[4]=Z.MIN_DOUBLE,e[5]=Z.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.OBB3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t},positions3ToAABB3:function(){var e=new Y(3);return function(t,n,r){n=n||Z.AABB3();for(var i,a,s,o=Z.MAX_DOUBLE,l=Z.MAX_DOUBLE,u=Z.MAX_DOUBLE,c=Z.MIN_DOUBLE,f=Z.MIN_DOUBLE,p=Z.MIN_DOUBLE,A=0,d=t.length;Ac&&(c=i),a>f&&(f=a),s>p&&(p=s);return n[0]=o,n[1]=l,n[2]=u,n[3]=c,n[4]=f,n[5]=p,n}}(),OBB3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB3(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MAX_DOUBLE,l=Z.MIN_DOUBLE,u=Z.MIN_DOUBLE,c=Z.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB3(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MAX_DOUBLE,l=Z.MIN_DOUBLE,u=Z.MIN_DOUBLE,c=Z.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToSphere3:function(){var e=new Y(3);return function(t,n){n=n||Z.vec4();var r,i=0,a=0,s=0,o=t.length;for(r=0;ru&&(u=l);return n[3]=u,n}}(),positions3ToSphere3:function(){var e=new Y(3),t=new Y(3);return function(n,r){r=r||Z.vec4();var i,a=0,s=0,o=0,l=n.length,u=0;for(i=0;iu&&(u=c);return r[3]=u,r}}(),OBB3ToSphere3:function(){var e=new Y(3),t=new Y(3);return function(n,r){r=r||Z.vec4();var i,a=0,s=0,o=0,l=n.length,u=l/4;for(i=0;if&&(f=c);return r[3]=f,r}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},getPositionsCenter:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3(),n=0,r=0,i=0,a=0,s=e.length;at[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]n&&(e[0]=n),e[1]>r&&(e[1]=r),e[2]>i&&(e[2]=i),e[3]0&&void 0!==arguments[0]?arguments[0]:Z.AABB2();return e[0]=Z.MAX_DOUBLE,e[1]=Z.MAX_DOUBLE,e[2]=Z.MIN_DOUBLE,e[3]=Z.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(r=e[0]*n[0],i=e[0]*n[3]):(r=e[0]*n[3],i=e[0]*n[0]),e[1]>0?(r+=e[1]*n[1],i+=e[1]*n[4]):(r+=e[1]*n[4],i+=e[1]*n[1]),e[2]>0?(r+=e[2]*n[2],i+=e[2]*n[5]):(r+=e[2]*n[5],i+=e[2]*n[2]),r<=-t&&i<=-t?-1:r>=-t&&i>=-t?1:0},OBB3ToAABB2:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB2(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MIN_DOUBLE,l=Z.MIN_DOUBLE,u=0,c=e.length;uo&&(o=t),n>l&&(l=n);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i},expandAABB2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]3&&void 0!==arguments[3]?arguments[3]:e,i=.5*(e[0]+1),a=.5*(e[1]+1),s=.5*(e[2]+1),o=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(o*n),r[2]=Math.floor(s*t),r[3]=n-Math.floor(a*n),r},tangentQuadraticBezier:function(e,t,n,r){return 2*(1-e)*(n-t)+2*e*(r-n)},tangentQuadraticBezier3:function(e,t,n,r,i){return-3*t*(1-e)*(1-e)+3*n*(1-e)*(1-e)-6*e*n*(1-e)+6*e*r*(1-e)-3*e*e*r+3*e*e*i},tangentSpline:function(e){return 6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e)},catmullRomInterpolate:function(e,t,n,r,i){var a=.5*(n-e),s=.5*(r-t),o=i*i;return(2*t-2*n+a+s)*(i*o)+(-3*t+3*n-2*a-s)*o+a*i+t},b2p0:function(e,t){var n=1-e;return n*n*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,n,r){return this.b2p0(e,t)+this.b2p1(e,n)+this.b2p2(e,r)},b3p0:function(e,t){var n=1-e;return n*n*n*t},b3p1:function(e,t){var n=1-e;return 3*n*n*e*t},b3p2:function(e,t){return 3*(1-e)*e*e*t},b3p3:function(e,t){return e*e*e*t},b3:function(e,t,n,r,i){return this.b3p0(e,t)+this.b3p1(e,n)+this.b3p2(e,r)+this.b3p3(e,i)},triangleNormal:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Z.vec3(),i=t[0]-e[0],a=t[1]-e[1],s=t[2]-e[2],o=n[0]-e[0],l=n[1]-e[1],u=n[2]-e[2],c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,A=Math.sqrt(c*c+f*f+p*p);return 0===A?(r[0]=0,r[1]=0,r[2]=0):(r[0]=c/A,r[1]=f/A,r[2]=p/A),r},rayTriangleIntersect:function(){var e=new Y(3),t=new Y(3),n=new Y(3),r=new Y(3),i=new Y(3);return function(a,s,o,l,u,c){c=c||Z.vec3();var f=Z.subVec3(l,o,e),p=Z.subVec3(u,o,t),A=Z.cross3Vec3(s,p,n),d=Z.dotVec3(f,A);if(d<1e-6)return null;var v=Z.subVec3(a,o,r),h=Z.dotVec3(v,A);if(h<0||h>d)return null;var I=Z.cross3Vec3(v,f,i),y=Z.dotVec3(s,I);if(y<0||h+y>d)return null;var m=Z.dotVec3(p,I)/d;return c[0]=a[0]+m*s[0],c[1]=a[1]+m*s[1],c[2]=a[2]+m*s[2],c}}(),rayPlaneIntersect:function(){var e=new Y(3),t=new Y(3),n=new Y(3),r=new Y(3);return function(i,a,s,o,l,u){u=u||Z.vec3(),a=Z.normalizeVec3(a,e);var c=Z.subVec3(o,s,t),f=Z.subVec3(l,s,n),p=Z.cross3Vec3(c,f,r);Z.normalizeVec3(p,p);var A=-Z.dotVec3(s,p),d=-(Z.dotVec3(i,p)+A)/Z.dotVec3(a,p);return u[0]=i[0]+d*a[0],u[1]=i[1]+d*a[1],u[2]=i[2]+d*a[2],u}}(),cartesianToBarycentric:function(){var e=new Y(3),t=new Y(3),n=new Y(3);return function(r,i,a,s,o){var l=Z.subVec3(s,i,e),u=Z.subVec3(a,i,t),c=Z.subVec3(r,i,n),f=Z.dotVec3(l,l),p=Z.dotVec3(l,u),A=Z.dotVec3(l,c),d=Z.dotVec3(u,u),v=Z.dotVec3(u,c),h=f*d-p*p;if(0===h)return null;var I=1/h,y=(d*A-p*v)*I,m=(f*v-p*A)*I;return o[0]=1-y-m,o[1]=m,o[2]=y,o}}(),barycentricInsideTriangle:function(e){var t=e[1],n=e[2];return n>=0&&t>=0&&n+t<1},barycentricToCartesian:function(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Z.vec3(),a=e[0],s=e[1],o=e[2];return i[0]=t[0]*a+n[0]*s+r[0]*o,i[1]=t[1]*a+n[1]*s+r[1]*o,i[2]=t[2]*a+n[2]*s+r[2]*o,i},mergeVertices:function(e,t,n,r){var i,a,s,o,l,u,c={},f=[],p=[],A=t?[]:null,d=n?[]:null,v=[],h=Math.pow(10,4),I=0;for(l=0,u=e.length;l>24&255,s=f>>16&255,a=f>>8&255,i=255&f,r=3*t[d],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+1],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+2],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,f++;return{positions:u,colors:c}},faceToVertexNormals:function(e,t){var n,r,i,a,s,o,l,u,c,f,p,A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},d=A.smoothNormalsAngleThreshold||20,v={},h=[],I={},y=4,m=Math.pow(10,y);for(l=0,c=e.length;ll[3]&&(l[3]=i[p]),i[p+1]l[4]&&(l[4]=i[p+1]),i[p+2]l[5]&&(l[5]=i[p+2])}if(n.length<20||a>10)return u.triangles=n,u.leaf=!0,u;e[0]=l[3]-l[0],e[1]=l[4]-l[1],e[2]=l[5]-l[2];var A=0;e[1]>e[A]&&(A=1),e[2]>e[A]&&(A=2),u.splitDim=A;var d=(l[A]+l[A+3])/2,v=new Array(n.length),h=0,I=new Array(n.length),y=0;for(s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t},octDecodeVec2s:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t}};Z.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var $=function(){function e(){b(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return P(e,[{key:"length",get:function(){return this._length}},{key:"shift",value:function(){if(this._index>=this._headLength){var e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}var t=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,t}},{key:"push",value:function(e){return this._length++,this._tail.push(e),this}},{key:"unshift",value:function(e){return this._head[--this._index]=e,this._length++,this}}]),e}(),ee={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var te=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],n=e[0].charCodeAt(0),r=n+e[1],i=n;i0&&void 0!==arguments[0]?arguments[0]:-1,r=(new Date).getTime(),i=0;le.length>0&&(n<0||r0&&ie>0){var n=1e3/ie;pe+=n,ce.push(n),ce.length>=30&&(pe-=ce.shift()),ee.frame.fps=Math.round(pe/ce.length)}!function(e){var t=Ae.runTasks(e+10),n=Ae.getNumTasks();ee.frame.tasksRun=t,ee.frame.tasksScheduled=n,ee.frame.tasksBudget=10}(t),function(e){for(var t in ue.time=e,Ae.scenes)if(Ae.scenes.hasOwnProperty(t)){var n=Ae.scenes[t];ue.sceneId=t,ue.startTime=n.startTime,ue.deltaTime=null!=ue.prevTime?ue.time-ue.prevTime:0,n.fire("tick",ue,!0)}ue.prevTime=e}(t),function(){var e,t,n,r,i,a=Ae.scenes,s=!1;for(i in a)a.hasOwnProperty(i)&&(e=a[i],(t=se[i])||(t=se[i]={}),n=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==n&&(t.ticksPerOcclusionTest=n,t.renderCountdown=n),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=n),r=e.ticksPerRender,t.ticksPerRender!==r&&(t.ticksPerRender=r,t.renderCountdown=r),0==--t.renderCountdown&&(e.render(s),t.renderCountdown=r))}(),fe=t,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(e):requestAnimationFrame(e)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(de):requestAnimationFrame(de);var ve=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=n.viewer;else{if("Scene"===t.type)this.scene=t;else{if(!(t instanceof e))throw"Invalid param: owner must be a Component";this.scene=t.scene}this._owner=t}this._dontClear=!!n.dontClear,this._renderer=this.scene._renderer,this.meta=n.meta||{},this.id=n.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,t&&t._own(this)}return P(e,[{key:"type",get:function(){return"Component"}},{key:"isComponent",get:function(){return!0}},{key:"glRedraw",value:function(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}},{key:"glResort",value:function(){this._renderer&&this._renderer.needStateSort()}},{key:"owner",get:function(){return this._owner}},{key:"isType",value:function(e){return this.type===e}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}},{key:"_message",value:function(e){return" ["+this.type+" "+ae.inQuotes(this.id)+"]: "+e}},{key:"warn",value:function(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}},{key:"error",value:function(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}},{key:"_attach",value:function(e){var t=e.name;if(t){var n=e.component,r=e.sceneDefault,i=e.sceneSingleton,a=e.type,s=e.on,o=!1!==e.recompiles;if(n&&(ae.isNumeric(n)||ae.isString(n))){var l=n;if(!(n=this.scene.components[l]))return void this.error("Component not found: "+ae.inQuotes(l))}if(!n)if(!0===i){var u=this.scene.types[a];for(var c in u)if(u.hasOwnProperty){n=u[c];break}if(!n)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===r&&!(n=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(n){if(n.scene.id!==this.scene.id)return void this.error("Not in same scene: "+n.type+" "+ae.inQuotes(n.id));if(a&&!n.isType(a))return void this.error("Expected a "+a+" type or subtype: "+n.type+" "+ae.inQuotes(n.id))}this._attachments||(this._attachments={});var f,p,A,d=this._attached[t];if(d){if(n&&d.id===n.id)return;var v=this._attachments[d.id];for(p=0,A=(f=v.subs).length;p3&&void 0!==arguments[3]?arguments[3]:1e3,i=Z.getPositionsCenter(e,he),a=Math.round(i[0]/r)*r,s=Math.round(i[1]/r)*r,o=Math.round(i[2]/r)*r;n[0]=a,n[1]=s,n[2]=o;var l=0!==n[0]||0!==n[1]||0!==n[2];if(l)for(var u=0,c=e.length;u0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,n=this.meshes[0]._colorize[3],r=255;if(t){if(e<0?e=0:e>1&&(e=1),n===(r=Math.floor(255*e)))return}else if(n===(r=255))return;for(var i=0,a=this.meshes.length;i1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._color=r.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=r.thickness||1,this._thicknessClickable=r.thicknessClickable||6;var i=this._wire,a=i.style;a.border="solid "+this._thickness+"px "+this._color,a.position="absolute",a["z-index"]=void 0===r.zIndex?"2000001":r.zIndex,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._wireClickable,o=s.style;o.border="solid "+this._thicknessClickable+"px "+this._color,o.position="absolute",o["z-index"]=void 0===r.zIndex?"2000002":r.zIndex+1,o.width="0px",o.height="0px",o.visibility="visible",o.top="0px",o.left="0px",o["-webkit-transform-origin"]="0 0",o["-moz-transform-origin"]="0 0",o["-ms-transform-origin"]="0 0",o["-o-transform-origin"]="0 0",o["transform-origin"]="0 0",o["-webkit-transform"]="rotate(0deg)",o["-moz-transform"]="rotate(0deg)",o["-ms-transform"]="rotate(0deg)",o["-o-transform"]="rotate(0deg)",o.transform="rotate(0deg)",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}return P(e,[{key:"_visible",get:function(){return"visible"===this._wire.style.visibility}},{key:"_update",value:function(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,n=this._wire.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)";var r=this._wireClickable.style;r.width=Math.round(e)+"px",r.left=Math.round(this._x1)+"px",r.top=Math.round(this._y1)+"px",r["-webkit-transform"]="rotate("+t+"deg)",r["-moz-transform"]="rotate("+t+"deg)",r["-ms-transform"]="rotate("+t+"deg)",r["-o-transform"]="rotate("+t+"deg)",r.transform="rotate("+t+"deg)"}},{key:"setStartAndEnd",value:function(e,t,n,r){this._x1=e,this._y1=t,this._x2=n,this._y2=r,this._update()}},{key:"setColor",value:function(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}},{key:"setOpacity",value:function(e){this._wire.style.opacity=e}},{key:"setVisible",value:function(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}},{key:"setClickable",value:function(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}},{key:"destroy",value:function(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}]),e}(),He=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var i=this._dot,a=i.style;a["border-radius"]="25px",a.border="solid 2px white",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"40000005":r.zIndex,a.width="8px",a.height="8px",a.visibility=!1!==r.visible?"visible":"hidden",a.top="0px",a.left="0px",a["box-shadow"]="0 2px 5px 0 #182A3D;",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._dotClickable,o=s.style;o["border-radius"]="35px",o.border="solid 10px white",o.position="absolute",o["z-index"]=void 0===r.zIndex?"40000007":r.zIndex+1,o.width="8px",o.height="8px",o.visibility="visible",o.top="0px",o.left="0px",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.borderColor)}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._dot.style;n.left=Math.round(e)-4+"px",n.top=Math.round(t)-4+"px";var r=this._dotClickable.style;r.left=Math.round(e)-9+"px",r.top=Math.round(t)-9+"px"}},{key:"setFillColor",value:function(e){this._dot.style.background=e||"lightgreen"}},{key:"setBorderColor",value:function(e){this._dot.style.border="solid 2px"+(e||"black")}},{key:"setOpacity",value:function(e){this._dot.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}},{key:"setClickable",value:function(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}},{key:"destroy",value:function(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}]),e}(),Ue=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-label-highlighted",this._prefix=r.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var i=this._label,a=i.style;a["border-radius"]="5px",a.color="white",a.padding="4px",a.border="solid 1px",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"5000005":r.zIndex,a.width="auto",a.height="auto",a.visibility="visible",a.top="0px",a.left="0px",a["pointer-events"]="all",a.opacity=1,r.onContextMenu,i.innerText="",t.appendChild(i),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.fillColor),this.setText(r.text),r.onMouseOver&&i.addEventListener("mouseover",(function(e){r.onMouseOver(e,n),e.preventDefault()})),r.onMouseLeave&&i.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n),e.preventDefault()})),r.onMouseWheel&&i.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&i.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()}))}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._label.style;n.left=Math.round(e)-20+"px",n.top=Math.round(t)-12+"px"}},{key:"setPosOnWire",value:function(e,t,n,r){var i=e+.5*(n-e),a=t+.5*(r-t),s=this._label.style;s.left=Math.round(i)-20+"px",s.top=Math.round(a)-12+"px"}},{key:"setPosBetweenWires",value:function(e,t,n,r,i,a){var s=(e+n+i)/3,o=(t+r+a)/3,l=this._label.style;l.left=Math.round(s)-20+"px",l.top=Math.round(o)-12+"px"}},{key:"setText",value:function(e){this._label.innerHTML=this._prefix+(e||"")}},{key:"setFillColor",value:function(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}},{key:"setBorderColor",value:function(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}},{key:"setOpacity",value:function(e){this._label.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}},{key:"setClickable",value:function(e){this._label.style["pointer-events"]=e?"all":"none"}},{key:"destroy",value:function(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}]),e}(),Ge=Z.vec3(),ke=Z.vec3(),Ve=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._color=i.color||e.defaultColor;var a=r.plugin.viewer.scene;r._originMarker=new Me(a,i.origin),r._cornerMarker=new Me(a,i.corner),r._targetMarker=new Me(a,i.target),r._originWorld=Z.vec3(),r._cornerWorld=Z.vec3(),r._targetWorld=Z.vec3(),r._wp=new Float64Array(12),r._vp=new Float64Array(12),r._pp=new Float64Array(12),r._cp=new Int16Array(6);var s=i.onMouseOver?function(e){i.onMouseOver(e,g(r))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,g(r))}:null,l=i.onContextMenu?function(e){i.onContextMenu(e,g(r))}:null,u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._cornerDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._originWire=new Fe(r._container,{color:r._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetWire=new Fe(r._container,{color:r._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._angleLabel=new Ue(r._container,{fillColor:r._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._visible=!1,r._originVisible=!1,r._cornerVisible=!1,r._targetVisible=!1,r._originWireVisible=!1,r._targetWireVisible=!1,r._angleVisible=!1,r._labelsVisible=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._cornerMarker.on("worldPos",(function(e){r._cornerWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.cornerVisible=i.cornerVisible,r.targetVisible=i.targetVisible,r.originWireVisible=i.originWireVisible,r.targetWireVisible=i.targetWireVisible,r.angleVisible=i.angleVisible,r.labelsVisible=i.labelsVisible,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(Z.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){var t=-.3,n=this._originMarker.viewPos[2],r=this._cornerMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(n>t||r>t||i>t)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);Z.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var a=this._pp,s=this._cp,o=e.canvas.canvas.getBoundingClientRect(),l=this._container.getBoundingClientRect(),u=o.top-l.top,c=o.left-l.left,f=e.canvas.boundary,p=f[2],A=f[3],d=0,v=0,h=a.length;vt+5||r[0]n+5||r[1]p[0]+5||A[0]p[1]+5||A[1]1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"AngleMeasurements",e))._container=i.container||document.body,r._control=new je(g(r)),r._measurements={},r.defaultColor=void 0!==i.defaultColor?i.defaultColor:"#00BBFF",r.defaultLabelsVisible=!1!==i.defaultLabelsVisible,r.zIndex=i.zIndex||1e4,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"control",get:function(){return this._control}},{key:"measurements",get:function(){return this._measurements}},{key:"createMeasurement",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.viewer.scene.components[t.id]&&(this.error("Viewer scene component with this ID already exists: "+t.id),delete t.id);var n=t.origin,r=t.corner,i=t.target,a=new Ve(this,{id:t.id,plugin:this,container:this._container,origin:{entity:n.entity,worldPos:n.worldPos},corner:{entity:r.entity,worldPos:r.worldPos},target:{entity:i.entity,worldPos:i.worldPos},visible:t.visible,originVisible:!0,originWireVisible:!0,cornerVisible:!0,targetWireVisible:!0,targetVisible:!0,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[a.id]=a,a.on("destroyed",(function(){delete e._measurements[a.id]})),this.fire("measurementCreated",a),a}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("AngleMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,n=Object.entries(this.measurements);t

";ae.isArray(t)&&(t=t.join("")),t=this._renderTemplate(t);var n=document.createRange().createContextualFragment(t);this._marker=n.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(function(){e.plugin.fire("markerClicked",e)})),this._marker.addEventListener("mouseenter",(function(){e.plugin.fire("markerMouseEnter",e)})),this._marker.addEventListener("mouseleave",(function(){e.plugin.fire("markerMouseLeave",e)})),this._marker.addEventListener("wheel",(function(t){e.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",t))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);var r=this._labelHTML||"

";ae.isArray(r)&&(r=r.join("")),r=this._renderTemplate(r);var i=document.createRange().createContextualFragment(r);this._label=i.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(function(t){e.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",t))}))}}},{key:"_updatePosition",value:function(){var e=this.scene.canvas.boundary,t=e[0],n=e[1],r=this.canvasPos;this._marker.style.left=Math.floor(t+r[0])-12+"px",this._marker.style.top=Math.floor(n+r[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+r[0]+20)+"px",this._label.style.top=Math.floor(n+r[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}},{key:"_renderTemplate",value:function(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){var n=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),n)}return e}},{key:"setMarkerShown",value:function(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}},{key:"getMarkerShown",value:function(){return this._markerShown}},{key:"setLabelShown",value:function(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}},{key:"getLabelShown",value:function(){return this._labelShown}},{key:"setField",value:function(e,t){this._values[e]=t||"",this._htmlDirty=!0}},{key:"getField",value:function(e){return this._values[e]}},{key:"setValues",value:function(e){for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];this.setField(t,n)}}},{key:"getValues",value:function(){return this._values}},{key:"destroy",value:function(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Ke=Z.vec3(),Ye=Z.vec3(),Xe=Z.vec3(),qe=function(e){I(n,z);var t=m(n);function n(e,r){var i;return b(this,n),(i=t.call(this,"Annotations",e))._labelHTML=r.labelHTML||"
",i._markerHTML=r.markerHTML||"
",i._container=r.container||document.body,i._values=r.values||{},i.annotations={},i.surfaceOffset=r.surfaceOffset,i}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){if("clearAnnotations"===e)this.clear()}},{key:"surfaceOffset",get:function(){return this._surfaceOffset},set:function(e){null==e&&(e=.3),this._surfaceOffset=e}},{key:"createAnnotation",value:function(e){var t,n,r=this;if(this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id),e.pickResult=e.pickResult||e.pickRecord,e.pickResult){var i=e.pickResult;if(i.worldPos&&i.worldNormal){var a=Z.normalizeVec3(i.worldNormal,Ke),s=Z.mulVec3Scalar(a,this._surfaceOffset,Ye);t=Z.addVec3(i.worldPos,s,Xe),n=i.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,n=e.entity;var o=null;e.markerElementId&&((o=document.getElementById(e.markerElementId))||this.error("Can't find DOM element for 'markerElementId' value '"+e.markerElementId+"' - defaulting to internally-generated empty DIV"));var l=null;e.labelElementId&&((l=document.getElementById(e.labelElementId))||this.error("Can't find DOM element for 'labelElementId' value '"+e.labelElementId+"' - defaulting to internally-generated empty DIV"));var u=new ze(this.viewer.scene,{id:e.id,plugin:this,entity:n,worldPos:t,container:this._container,markerElement:o,labelElement:l,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:ae.apply(e.values,ae.apply(this._values,{})),markerShown:e.markerShown,labelShown:e.labelShown,eye:e.eye,look:e.look,up:e.up,projection:e.projection,visible:!1!==e.visible});return this.annotations[u.id]=u,u.on("destroyed",(function(){delete r.annotations[u.id],r.fire("annotationDestroyed",u.id)})),this.fire("annotationCreated",u.id),u}},{key:"destroyAnnotation",value:function(e){var t=this.annotations[e];t?t.destroy():this.log("Annotation not found: "+e)}},{key:"clear",value:function(){for(var e=Object.keys(this.annotations),t=0,n=e.length;t1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._canvas=i.canvas,r._element=null,r._isCustom=!1,i.elementId&&(r._element=document.getElementById(i.elementId),r._element?r._adjustPosition():r.error("Can't find given Spinner HTML element: '"+i.elementId+"' - will automatically create default element")),r._element||r._createDefaultSpinner(),r.processes=0,r}return P(n,[{key:"type",get:function(){return"Spinner"}},{key:"_createDefaultSpinner",value:function(){this._injectDefaultCSS();var e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}},{key:"_injectDefaultCSS",value:function(){var e="xeokit-spinner-css";if(!document.getElementById(e)){var t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}}},{key:"_adjustPosition",value:function(){if(!this._isCustom){var e=this._canvas,t=this._element,n=t.style;n.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",n.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}}},{key:"processes",get:function(){return this._processes},set:function(e){if(e=e||0,this._processes!==e&&!(e<0)){var t=this._processes;this._processes=e;var n=this._element;n&&(n.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}}},{key:"_destroy",value:function(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);var e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}]),n}(),Ze={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},$e=document.createElement("canvas");if($e){var et=$e.getContext("webgl",{antialias:!0})||$e.getContext("experimental-webgl",{antialias:!0});Ze.WEBGL=!!et,Ze.WEBGL&&(Ze.ANTIALIAS=et.getContextAttributes().antialias,et.getShaderPrecisionFormat?et.getShaderPrecisionFormat(et.FRAGMENT_SHADER,et.HIGH_FLOAT).precision>0?Ze.FS_MAX_FLOAT_PRECISION="highp":et.getShaderPrecisionFormat(et.FRAGMENT_SHADER,et.MEDIUM_FLOAT).precision>0?Ze.FS_MAX_FLOAT_PRECISION="mediump":Ze.FS_MAX_FLOAT_PRECISION="lowp":Ze.FS_MAX_FLOAT_PRECISION="mediump",Ze.DEPTH_BUFFER_BITS=et.getParameter(et.DEPTH_BITS),Ze.MAX_TEXTURE_SIZE=et.getParameter(et.MAX_TEXTURE_SIZE),Ze.MAX_CUBE_MAP_SIZE=et.getParameter(et.MAX_CUBE_MAP_TEXTURE_SIZE),Ze.MAX_RENDERBUFFER_SIZE=et.getParameter(et.MAX_RENDERBUFFER_SIZE),Ze.MAX_TEXTURE_UNITS=et.getParameter(et.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Ze.MAX_TEXTURE_IMAGE_UNITS=et.getParameter(et.MAX_TEXTURE_IMAGE_UNITS),Ze.MAX_VERTEX_ATTRIBS=et.getParameter(et.MAX_VERTEX_ATTRIBS),Ze.MAX_VERTEX_UNIFORM_VECTORS=et.getParameter(et.MAX_VERTEX_UNIFORM_VECTORS),Ze.MAX_FRAGMENT_UNIFORM_VECTORS=et.getParameter(et.MAX_FRAGMENT_UNIFORM_VECTORS),Ze.MAX_VARYING_VECTORS=et.getParameter(et.MAX_VARYING_VECTORS),et.getSupportedExtensions().forEach((function(e){Ze.SUPPORTED_EXTENSIONS[e]=!0})))}var tt=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],nt=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))._backgroundColor=Z.vec3([i.backgroundColor?i.backgroundColor[0]:1,i.backgroundColor?i.backgroundColor[1]:1,i.backgroundColor?i.backgroundColor[2]:1]),r._backgroundColorFromAmbientLight=!!i.backgroundColorFromAmbientLight,r.canvas=i.canvas,r.gl=null,r.webgl2=!1,r.transparent=!!i.transparent,r.contextAttr=i.contextAttr||{},r.contextAttr.alpha=r.transparent,r.contextAttr.preserveDrawingBuffer=!!r.contextAttr.preserveDrawingBuffer,r.contextAttr.stencil=!1,r.contextAttr.premultipliedAlpha=!!r.contextAttr.premultipliedAlpha,r.contextAttr.antialias=!1!==r.contextAttr.antialias,r.resolutionScale=i.resolutionScale,r.canvas.width=Math.round(r.canvas.clientWidth*r._resolutionScale),r.canvas.height=Math.round(r.canvas.clientHeight*r._resolutionScale),r.boundary=[r.canvas.offsetLeft,r.canvas.offsetTop,r.canvas.clientWidth,r.canvas.clientHeight],r._initWebGL(i);var a=g(r);r.canvas.addEventListener("webglcontextlost",r._webglcontextlostListener=function(e){console.time("webglcontextrestored"),a.scene._webglContextLost(),a.fire("webglcontextlost"),e.preventDefault()},!1),r.canvas.addEventListener("webglcontextrestored",r._webglcontextrestoredListener=function(e){a._initWebGL(),a.gl&&(a.scene._webglContextRestored(a.gl),a.fire("webglcontextrestored",a.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);var s=!0,o=new ResizeObserver((function(e){var t,n=f(e);try{for(n.s();!(t=n.n()).done;){t.value.contentBoxSize&&(s=!0)}}catch(e){n.e(e)}finally{n.f()}}));return o.observe(r.canvas),r._tick=r.scene.on("tick",(function(){s&&(s=!1,a.canvas.width=Math.round(a.canvas.clientWidth*a._resolutionScale),a.canvas.height=Math.round(a.canvas.clientHeight*a._resolutionScale),a.boundary[0]=a.canvas.offsetLeft,a.boundary[1]=a.canvas.offsetTop,a.boundary[2]=a.canvas.clientWidth,a.boundary[3]=a.canvas.clientHeight,a.fire("boundary",a.boundary))})),r._spinner=new Je(r.scene,{canvas:r.canvas,elementId:i.spinnerElementId}),r}return P(n,[{key:"type",get:function(){return"Canvas"}},{key:"backgroundColorFromAmbientLight",get:function(){return this._backgroundColorFromAmbientLight},set:function(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}},{key:"resolutionScale",get:function(){return this._resolutionScale},set:function(e){if((e=e||1)!==this._resolutionScale){this._resolutionScale=e;var t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}}},{key:"spinner",get:function(){return this._spinner}},{key:"_createCanvas",value:function(){var e="xeokit-canvas-"+Z.createUUID(),t=document.getElementsByTagName("body")[0],n=document.createElement("div"),r=n.style;r.height="100%",r.width="100%",r.padding="0",r.margin="0",r.background="rgba(0,0,0,0);",r.float="left",r.left="0",r.top="0",r.position="absolute",r.opacity="1.0",r["z-index"]="-10000",n.innerHTML+='',t.appendChild(n),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,n=0;e;)t+=e.offsetLeft-e.scrollLeft,n+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:n}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e0&&"/"===t.charAt(n+1)&&(t=t.substring(0,n)),r.push(t);return r.join("\n")}function ct(e){console.error(e.join("\n"))}var ft=function(){function e(t,n){b(this,e),this.id=lt.addItem({}),this.source=n,this.init(t)}return P(e,[{key:"init",value:function(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new at(e,e.VERTEX_SHADER,ut(this.source.vertex)),this._fragmentShader=new at(e,e.FRAGMENT_SHADER,ut(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void ct(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void ct(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void ct(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void ct(this.errors);var t,n,r,i,a;if(this.compiled=!0,this.handle=e.createProgram(),this.handle){if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void ct(this.errors);var s=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(n=0;nthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}},{key:"setData",value:function(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}},{key:"bind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}},{key:"unbind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,null)}},{key:"destroy",value:function(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}]),e}(),At=function(){function e(t,n){b(this,e),this.scene=t,this.aabb=Z.AABB3(),this.origin=Z.vec3(n),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}return P(e,[{key:"addMarker",value:function(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}},{key:"markerWorldPosUpdated",value:function(e){if(this.markers[e.id]){var t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}}},{key:"removeMarker",value:function(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}},{key:"update",value:function(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}},{key:"_buildMarkerList",value:function(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}},{key:"_buildPositions",value:function(){for(var e=0,t=0;t-t)o._setVisible(!1);else{var l=o.canvasPos,u=l[0],c=l[1];u+10<0||c+10<0||u-10>r||c-10>i?o._setVisible(!1):!o.entity||o.entity.visible?o.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=o,this.pixels[a++]=u,this.pixels[a++]=c):o._setVisible(!0):o._setVisible(!1)}}}},{key:"_updateActiveSectionPlanes",value:function(){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n0,n=[];return n.push("#version 300 es"),n.push("// OcclusionTester vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("vec4 worldPosition = vec4(position, 1.0); "),n.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&n.push(" vWorldPosition = worldPosition;"),n.push(" vec4 clipPos = projMatrix * viewPosition;"),n.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?n.push("vFragDepth = 1.0 + clipPos.w;"):n.push("clipPos.z += -0.001;"),n.push(" gl_Position = clipPos;"),n.push("}"),n}},{key:"_buildFragmentShaderSource",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// OcclusionTester fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;");for(var i=0;i 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),r.push("}"),r}},{key:"_buildProgram",value:function(){this._program&&this._program.destroy();var e=this._scene,t=e.canvas.gl,n=e._sectionPlanesState;if(this._program=new ft(t,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=n.sectionPlanes.length;i0)for(var p=r.sectionPlanes,A=0;A= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var r=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new pt(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),this._uvBuf=new pt(n,n.ARRAY_BUFFER,r,r.length,2,n.STATIC_DRAW),this._indicesBuf=new pt(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}}},{key:"destroy",value:function(){this._program&&(this._program.destroy(),this._program=null)}}]),e}(),mt=new Float32Array(Dt(17,[0,1])),wt=new Float32Array(Dt(17,[1,0])),gt=new Float32Array(function(e,t){for(var n=[],r=0;r<=e;r++)n.push(bt(r,t));return n}(17,4)),Tt=new Float32Array(2),Et=function(){function e(t){b(this,e),this._scene=t,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}return P(e,[{key:"init",value:function(){var e=this._scene.canvas.gl;if(this._program=new ft(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS ".concat(16,"\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var t=new Float32Array([1,1,0,1,0,0,1,0]),n=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),r=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new pt(e,e.ARRAY_BUFFER,n,n.length,3,e.STATIC_DRAW),this._uvBuf=new pt(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new pt(e,e.ELEMENT_ARRAY_BUFFER,r,r.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}},{key:"render",value:function(e,t,n){var r=this;if(!this._programError){this._getInverseProjectMat||(this._getInverseProjectMat=function(){var e=!0;r._scene.camera.on("projMatrix",(function(){e=!0}));var t=Z.mat4();return function(){return e&&Z.inverseMat4(s.camera.projMatrix,t),t}}());var i=this._scene.canvas.gl,a=this._program,s=this._scene,o=i.drawingBufferWidth,l=i.drawingBufferHeight,u=s.camera.project._state,c=u.near,f=u.far;i.viewport(0,0,o,l),i.clearColor(0,0,0,1),i.enable(i.DEPTH_TEST),i.disable(i.BLEND),i.frontFace(i.CCW),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),a.bind(),Tt[0]=o,Tt[1]=l,i.uniform2fv(this._uViewport,Tt),i.uniform1f(this._uCameraNear,c),i.uniform1f(this._uCameraFar,f),i.uniform1f(this._uDepthCutoff,.01),0===n?i.uniform2fv(this._uSampleOffsets,wt):i.uniform2fv(this._uSampleOffsets,mt),i.uniform1fv(this._uSampleWeights,gt);var p=e.getDepthTexture(),A=t.getTexture();a.bindTexture(this._uDepthTexture,p,0),a.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),i.drawElements(i.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}}},{key:"destroy",value:function(){this._program.destroy()}}]),e}();function bt(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function Dt(e,t){for(var n=[],r=0;r<=e;r++)n.push(t[0]*r),n.push(t[1]*r);return n}var Pt=function(){function e(t,n,r){b(this,e),r=r||{},this.gl=n,this.allocated=!1,this.canvas=t,this.buffer=null,this.bound=!1,this.size=r.size,this._hasDepthTexture=!!r.depthTexture}return P(e,[{key:"setSize",value:function(e){this.size=e}},{key:"webglContextRestored",value:function(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}},{key:"bind",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(this._touch(e),!this.bound){var t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"_touch",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=this.gl;if(this.size?(e=this.size[0],t=this.size[1]):(e=r.drawingBufferWidth,t=r.drawingBufferHeight),this.buffer){if(this.buffer.width===e&&this.buffer.height===t)return;r.deleteTexture(this.buffer.texture),r.deleteFramebuffer(this.buffer.framebuf),r.deleteRenderbuffer(this.buffer.renderbuf)}var i,a=r.createTexture();r.bindTexture(r.TEXTURE_2D,a),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),n?r.texStorage2D(r.TEXTURE_2D,1,n,e,t):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),this._hasDepthTexture&&(i=r.createTexture(),r.bindTexture(r.TEXTURE_2D,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.DEPTH_COMPONENT32F,e,t,0,r.DEPTH_COMPONENT,r.FLOAT,null));var s=r.createRenderbuffer();r.bindRenderbuffer(r.RENDERBUFFER,s),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT32F,e,t);var o=r.createFramebuffer();if(r.bindFramebuffer(r.FRAMEBUFFER,o),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,a,0),this._hasDepthTexture?r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,i,0):r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,s),r.bindTexture(r.TEXTURE_2D,null),r.bindRenderbuffer(r.RENDERBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,o),!r.isFramebuffer(o))throw"Invalid framebuffer";r.bindFramebuffer(r.FRAMEBUFFER,null);var l=r.checkFramebufferStatus(r.FRAMEBUFFER);switch(l){case r.FRAMEBUFFER_COMPLETE:break;case r.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case r.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+l}this.buffer={framebuf:o,renderbuf:s,texture:a,depthTexture:i,width:e,height:t},this.bound=!1}},{key:"clear",value:function(){if(!this.bound)throw"Render buffer not bound";var e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}},{key:"read",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,s=e,o=(this.buffer.height||this.gl.drawingBufferHeight)-t,l=new i(a),u=this.gl;return u.readPixels(s,o,1,1,n||u.RGBA,r||u.UNSIGNED_BYTE,l,0),l}},{key:"readArray",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Uint8Array,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:4,i=new n(this.buffer.width*this.buffer.height*r),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}},{key:"readImageAsCanvas",value:function(){var e=this.gl,t=this._getImageDataCache(),n=t.pixelData,r=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,n);for(var s=this.buffer.width,o=this.buffer.height,l=o/2|0,u=4*s,c=new Uint8Array(4*s),f=0;f0&&void 0!==arguments[0]?arguments[0]:Uint8Array,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,n=this.buffer.width,r=this.buffer.height,i=this._imageDataCache;if(i&&(i.width===n&&i.height===r||(this._imageDataCache=null,i=null)),!i){var a=document.createElement("canvas"),s=a.getContext("2d");a.width=n,a.height=r,i={pixelData:new e(n*r*t),canvas:a,context:s,imageData:s.createImageData(n,r),width:n,height:r},this._imageDataCache=i}return i.context.resetTransform(),i}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"getTexture",value:function(){var e=this;return this._texture||(this._texture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.texture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.texture),!0)},unbind:function(t){e.buffer&&e.buffer.texture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"hasDepthTexture",value:function(){return this._hasDepthTexture}},{key:"getDepthTexture",value:function(){if(!this._hasDepthTexture)return null;var e=this;return this._depthTexture||(this._dethTexture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.depthTexture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.depthTexture),!0)},unbind:function(t){e.buffer&&e.buffer.depthTexture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"destroy",value:function(){if(this.allocated){var e=this.gl;e.deleteTexture(this.buffer.texture),e.deleteTexture(this.buffer.depthTexture),e.deleteFramebuffer(this.buffer.framebuf),e.deleteRenderbuffer(this.buffer.renderbuf),this.allocated=!1,this.buffer=null,this.bound=!1}this._imageDataCache=null,this._texture=null,this._depthTexture=null}}]),e}(),Rt=function(){function e(t){b(this,e),this.scene=t,this._renderBuffersBasic={},this._renderBuffersScaled={}}return P(e,[{key:"getRenderBuffer",value:function(e,t){var n=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled,r=n[e];return r||(r=new Pt(this.scene.canvas.canvas,this.scene.canvas.gl,t),n[e]=r),r}},{key:"destroy",value:function(){for(var e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(var t in this._renderBuffersScaled)this._renderBuffersScaled[t].destroy()}}]),e}();function Ct(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var n;switch(t){case"WEBGL_depth_texture":n=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=e.getExtension(t)}return e._cachedExtensions[t]=n,n}var _t=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}(),Bt=function(){function e(t,n,r,i){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;b(this,e),this.model=t,this.object=null,this.parent=null,this.id=n,this.aabb=null,this.layer=a,this.portionId=s,this._color=[r[0],r[1],r[2],i],this._colorize=[r[0],r[1],r[2],i],this._colorizing=!1,this._transparent=i<255,this.numTriangles=0,this.origin=null}return P(e,[{key:"_finalize",value:function(e){this.layer.initFlags(this.portionId,e,this._transparent)}},{key:"_finalize2",value:function(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}},{key:"_setVisible",value:function(e){this.layer.setVisible(this.portionId,e,this._transparent)}},{key:"_setColor",value:function(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}},{key:"_setColorize",value:function(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}},{key:"_setOpacity",value:function(e,t){var n=e<255,r=this._transparent!==n;this._color[3]=e,this._colorize[3]=e,this._transparent=n,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),r&&this.layer.setTransparent(this.portionId,t,n)}},{key:"_setOffset",value:function(e){this.layer.setOffset(this.portionId,e)}},{key:"_setHighlighted",value:function(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}},{key:"_setXRayed",value:function(e){this.layer.setXRayed(this.portionId,e,this._transparent)}},{key:"_setSelected",value:function(e){this.layer.setSelected(this.portionId,e,this._transparent)}},{key:"_setEdges",value:function(e){this.layer.setEdges(this.portionId,e,this._transparent)}},{key:"_setClippable",value:function(e){this.layer.setClippable(this.portionId,e,this._transparent)}},{key:"_setCollidable",value:function(e){this.layer.setCollidable(this.portionId,e)}},{key:"_setPickable",value:function(e){this.layer.setPickable(this.portionId,e,this._transparent)}},{key:"_setCulled",value:function(e){this.layer.setCulled(this.portionId,e,this._transparent)}},{key:"canPickTriangle",value:function(){return!1}},{key:"drawPickTriangles",value:function(e,t){}},{key:"pickTriangleSurface",value:function(e){}},{key:"precisionRayPickSurface",value:function(e,t,n,r){return!!this.layer.precisionRayPickSurface&&this.layer.precisionRayPickSurface(this.portionId,e,t,n,r)}},{key:"canPickWorldPos",value:function(){return!0}},{key:"drawPickDepths",value:function(e){this.model.drawPickDepths(e)}},{key:"drawPickNormals",value:function(e){this.model.drawPickNormals(e)}},{key:"delegatePickedEntity",value:function(){return this.parent}},{key:"getEachVertex",value:function(e){this.layer.getEachVertex(this.portionId,e)}},{key:"_destroy",value:function(){this.model.scene._renderer.putPickID(this.pickId)}}]),e}(),Ot=new(function(){function e(){b(this,e),this._uint8Arrays={},this._float32Arrays={}}return P(e,[{key:"_clear",value:function(){this._uint8Arrays={},this._float32Arrays={}}},{key:"getUInt8Array",value:function(e){var t=this._uint8Arrays[e];return t||(t=new Uint8Array(e),this._uint8Arrays[e]=t),t}},{key:"getFloat32Array",value:function(e){var t=this._float32Arrays[e];return t||(t=new Float32Array(e),this._float32Arrays[e]=t),t}}]),e}()),St=0;function Nt(){return St++,Ot}var Lt={NOT_RENDERED:0,COLOR_OPAQUE:1,COLOR_TRANSPARENT:2,SILHOUETTE_HIGHLIGHTED:3,SILHOUETTE_SELECTED:4,SILHOUETTE_XRAYED:5,EDGES_COLOR_OPAQUE:6,EDGES_COLOR_TRANSPARENT:7,EDGES_HIGHLIGHTED:8,EDGES_SELECTED:9,EDGES_XRAYED:10,PICK:11},xt=new G({}),Mt=function(){function e(t){for(var n in b(this,e),this.id=xt.addItem({}),t)t.hasOwnProperty(n)&&(this[n]=t[n])}return P(e,[{key:"destroy",value:function(){xt.removeItem(this.id)}}]),e}();var Ft=function(){var e=Z.mat4(),t=Z.mat4();return function(n,r){r=r||Z.mat4();var i=n[0],a=n[1],s=n[2],o=n[3]-i,l=n[4]-a,u=n[5]-s,c=65535;return Z.identityMat4(e),Z.translationMat4v(n,e),Z.identityMat4(t),Z.scalingMat4v([o/c,l/c,u/c],t),Z.mulMat4(e,t,r),r}}(),Ht=function(){var e=Z.mat4(),t=Z.mat4();return function(n,r,i){var a,s=new Uint16Array(n.length),o=new Float32Array([i[0]!==r[0]?65535/(i[0]-r[0]):0,i[1]!==r[1]?65535/(i[1]-r[1]):0,i[2]!==r[2]?65535/(i[2]-r[2]):0]);for(a=0;a=0?1:-1),o=(1-Math.abs(i))*(a>=0?1:-1);i=s,a=o}return new Int8Array([Math[n](127.5*i+(i<0?-1:0)),Math[r](127.5*a+(a<0?-1:0))])}function kt(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}function Vt(e,t,n){return e[t]*n[0]+e[t+1]*n[1]+e[t+2]*n[2]}var jt={getPositionsBounds:function(e){var t,n,r=new Float32Array(3),i=new Float32Array(3);for(t=0;t<3;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:e;return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n[3]=e[3]*t[0]+t[12],n[4]=e[4]*t[5]+t[13],n[5]=e[5]*t[10]+t[14],n},getUVBounds:function(e){var t,n,r=new Float32Array(2),i=new Float32Array(2);for(t=0;t<2;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;ri&&(n=t,i=r),(r=Vt(e,s,kt(t=Gt(e,s,"floor","ceil"))))>i&&(n=t,i=r),(r=Vt(e,s,kt(t=Gt(e,s,"ceil","ceil"))))>i&&(n=t,i=r),a[s]=n[0],a[s+1]=n[1];return a},decompressNormals:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t},decompressNormal:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t}},Qt=new Float32Array([1,1,1,1]),Wt=new Float32Array([0,0,0,1]),zt=Z.vec4(),Kt=Z.vec3(),Yt=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.instancing,a=void 0!==i&&i,s=r.edges,o=void 0!==s&&s;b(this,e),this._scene=t,this._withSAO=n,this._instancing=a,this._edges=o,this._hash=this._getHash(),this._matricesUniformBlockBufferBindingPoint=0,this._matricesUniformBlockBuffer=this._scene.canvas.gl.createBuffer(),this._matricesUniformBlockBufferData=new Float32Array(96),this._vaoCache=new WeakMap,this._allocate()}return P(e,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()}},{key:"_buildShader",value:function(){return{vertex:this._buildVertexShader(),fragment:this._buildFragmentShader()}}},{key:"_buildVertexShader",value:function(){return[""]}},{key:"_buildFragmentShader",value:function(){return[""]}},{key:"_addMatricesUniformBlockLines",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.push("uniform Matrices {"),e.push(" mat4 worldMatrix;"),e.push(" mat4 viewMatrix;"),e.push(" mat4 projMatrix;"),e.push(" mat4 positionsDecodeMatrix;"),t&&(e.push(" mat4 worldNormalMatrix;"),e.push(" mat4 viewNormalMatrix;")),e.push("};"),e}},{key:"getValid",value:function(){return this._hash===this._getHash()}},{key:"setSectionPlanesStateUniforms",value:function(e){var t=this._scene,n=t.canvas.gl,r=e.model,i=e.layerIndex,a=t._sectionPlanesState.sectionPlanes.length;if(a>0)for(var s=t._sectionPlanesState.sectionPlanes,o=i*a,l=r.renderFlags,u=0;u0&&(this._uReflectionMap="reflectionMap"),n.lightMaps.length>0&&(this._uLightMap="lightMap"),this._uSectionPlanes=[];for(var o=0,l=e._sectionPlanesState.sectionPlanes.length;o3&&void 0!==arguments[3]?arguments[3]:{},i=r.colorUniform,a=void 0!==i&&i,s=r.incrementDrawState,o=void 0!==s&&s,l=Ze.MAX_TEXTURE_IMAGE_UNITS,u=this._scene,c=u.canvas.gl,f=t._state,p=t.model,A=f.textureSet,d=f.origin,v=f.positionsDecodeMatrix,h=u._lightsState,I=u.pointsMaterial,y=p.scene.camera,m=y.viewNormalMatrix,w=y.project,g=e.pickViewMatrix||y.viewMatrix,T=p.worldMatrix,E=p.worldNormalMatrix;if(this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram(e)),this._vaoCache.has(t)?c.bindVertexArray(this._vaoCache.get(t)):this._vaoCache.set(t,this._makeVAO(f));var b=0,D=16;if(this._matricesUniformBlockBufferData.set(T,0),this._matricesUniformBlockBufferData.set(d?Ie(g,d):g,b+=D),this._matricesUniformBlockBufferData.set(e.pickProjMatrix||w.matrix,b+=D),this._matricesUniformBlockBufferData.set(v,b+=D),this._matricesUniformBlockBufferData.set(E,b+=D),this._matricesUniformBlockBufferData.set(m,b+=D),c.bindBuffer(c.UNIFORM_BUFFER,this._matricesUniformBlockBuffer),c.bufferData(c.UNIFORM_BUFFER,this._matricesUniformBlockBufferData,c.DYNAMIC_DRAW),c.bindBufferBase(c.UNIFORM_BUFFER,this._matricesUniformBlockBufferBindingPoint,this._matricesUniformBlockBuffer),c.uniform1i(this._uRenderPass,n),this.setSectionPlanesStateUniforms(t),u.logarithmicDepthBufferEnabled){if(this._uLogDepthBufFC){var P=2/(Math.log(e.pickZFar+1)/Math.LN2);c.uniform1f(this._uLogDepthBufFC,P)}this._uZFar&&c.uniform1f(this._uZFar,u.camera.project.far)}if(this._uPickInvisible&&c.uniform1i(this._uPickInvisible,e.pickInvisible),this._uPickZNear&&c.uniform1f(this._uPickZNear,e.pickZNear),this._uPickZFar&&c.uniform1f(this._uPickZFar,e.pickZFar),this._uPositionsDecodeMatrix&&c.uniformMatrix4fv(this._uPositionsDecodeMatrix,!1,f.positionsDecodeMatrix),this._uUVDecodeMatrix&&c.uniformMatrix3fv(this._uUVDecodeMatrix,!1,(this._instancing,f.uvDecodeMatrix)),this._uIntensityRange&&I.filterIntensity&&c.uniform2f(this._uIntensityRange,I.minIntensity,I.maxIntensity),this._uPointSize&&c.uniform1f(this._uPointSize,I.pointSize),this._uNearPlaneHeight){var R="ortho"===u.camera.projection?1:c.drawingBufferHeight/(2*Math.tan(.5*u.camera.perspective.fov*Math.PI/180));c.uniform1f(this._uNearPlaneHeight,R)}if(A){var C=A.colorTexture,_=A.metallicRoughnessTexture,B=A.emissiveTexture,O=A.normalsTexture,S=A.occlusionTexture;this._uColorMap&&C&&(this._program.bindTexture(this._uColorMap,C.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uMetallicRoughMap&&_&&(this._program.bindTexture(this._uMetallicRoughMap,_.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uEmissiveMap&&B&&(this._program.bindTexture(this._uEmissiveMap,B.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uNormalMap&&O&&(this._program.bindTexture(this._uNormalMap,O.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l),this._uAOMap&&S&&(this._program.bindTexture(this._uAOMap,S.texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l)}if(h.reflectionMaps.length>0&&h.reflectionMaps[0].texture&&this._uReflectionMap&&(this._program.bindTexture(this._uReflectionMap,h.reflectionMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),h.lightMaps.length>0&&h.lightMaps[0].texture&&this._uLightMap&&(this._program.bindTexture(this._uLightMap,h.lightMaps[0].texture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++),this._withSAO){var N=u.sao,L=N.possible;if(L){var x=c.drawingBufferWidth,M=c.drawingBufferHeight;zt[0]=x,zt[1]=M,zt[2]=N.blendCutoff,zt[3]=N.blendFactor,c.uniform4fv(this._uSAOParams,zt),this._program.bindTexture(this._uOcclusionTexture,e.occlusionTexture,e.textureUnit),e.textureUnit=(e.textureUnit+1)%l,e.bindTexture++}}if(a){var F=this._edges?"edgeColor":"fillColor",H=this._edges?"edgeAlpha":"fillAlpha";if(n===Lt["".concat(this._edges?"EDGES":"SILHOUETTE","_XRAYED")]){var U=u.xrayMaterial._state,G=U[F],k=U[H];c.uniform4f(this._uColor,G[0],G[1],G[2],k)}else if(n===Lt["".concat(this._edges?"EDGES":"SILHOUETTE","_HIGHLIGHTED")]){var V=u.highlightMaterial._state,j=V[F],Q=V[H];c.uniform4f(this._uColor,j[0],j[1],j[2],Q)}else if(n===Lt["".concat(this._edges?"EDGES":"SILHOUETTE","_SELECTED")]){var W=u.selectedMaterial._state,z=W[F],K=W[H];c.uniform4f(this._uColor,z[0],z[1],z[2],K)}else c.uniform4fv(this._uColor,this._edges?Wt:Qt)}this._draw({state:f,frameCtx:e,incrementDrawState:o}),c.bindVertexArray(null)}}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null,ee.memory.programs--}}]),e}(),Xt=function(e){I(n,Yt);var t=m(n);function n(e,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=i.instancing,s=void 0!==a&&a,o=i.edges,l=void 0!==o&&o;return b(this,n),t.call(this,e,r,{instancing:s,edges:l})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;if(this._edges)t.drawElements(t.LINES,n.edgeIndicesBuf.numItems,n.edgeIndicesBuf.itemType,0);else{var a=r.pickElementsCount||n.indicesBuf.numItems,s=r.pickElementsOffset?r.pickElementsOffset*n.indicesBuf.itemByteSize:0;t.drawElements(t.TRIANGLES,a,n.indicesBuf.itemType,s),i&&r.drawElements++}}}]),n}(),qt=function(e){I(n,Xt);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!1,edges:!0})}return P(n)}(),Jt=function(e){I(n,Yt);var t=m(n);function n(e,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=i.edges,s=void 0!==a&&a;return b(this,n),t.call(this,e,r,{instancing:!0,edges:s})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;this._edges?t.drawElementsInstanced(t.LINES,n.edgeIndicesBuf.numItems,n.edgeIndicesBuf.itemType,0,n.numInstances):(t.drawElementsInstanced(t.TRIANGLES,n.indicesBuf.numItems,n.indicesBuf.itemType,0,n.numInstances),i&&r.drawElements++)}}]),n}(),Zt=function(e){I(n,Jt);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0,edges:!0})}return P(n)}(),$t=function(e){I(n,Yt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawArrays(t.POINTS,0,n.positionsBuf.numItems),i&&r.drawArrays++}}]),n}(),en=function(e){I(n,Yt);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawArraysInstanced(t.POINTS,0,n.positionsBuf.numItems,n.numInstances),i&&r.drawArrays++}}]),n}(),tn=function(e){I(n,Yt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawElements(t.LINES,n.indicesBuf.numItems,n.indicesBuf.itemType,0),i&&r.drawElements++}}]),n}(),nn=function(e){I(n,Yt);var t=m(n);function n(e,r){return b(this,n),t.call(this,e,r,{instancing:!0})}return P(n,[{key:"_draw",value:function(e){var t=this._scene.canvas.gl,n=e.state,r=e.frameCtx,i=e.incrementDrawState;t.drawElementsInstanced(t.LINES,n.indicesBuf.numItems,n.indicesBuf.itemType,0,n.numInstances),i&&r.drawElements++}}]),n}(),rn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t=this._scene,n=t._sectionPlanesState,r=t._lightsState,i=n.sectionPlanes.length>0,a=[];a.push("#version 300 es"),a.push("// Triangles batching draw vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in float flags;"),t.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),t.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("uniform vec4 lightAmbient;");for(var s=0,o=r.lights.length;s= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),i&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;")),a.push("out vec4 vColor;"),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),t.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;");for(var l=0,u=r.lights.length;l0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching draw fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),n}(),an=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching flat-shading draw vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._lightsState,n=e._sectionPlanesState,r=n.sectionPlanes.length>0,i=[];if(i.push("#version 300 es"),i.push("// Triangles batching flat-shading draw fragment shader"),i.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),i.push("precision highp float;"),i.push("precision highp int;"),i.push("#else"),i.push("precision mediump float;"),i.push("precision mediump int;"),i.push("#endif"),e.logarithmicDepthBufferEnabled&&(i.push("in float isPerspective;"),i.push("uniform float logDepthBufFC;"),i.push("in float vFragDepth;")),this._withSAO&&(i.push("uniform sampler2D uOcclusionTexture;"),i.push("uniform vec4 uSAOParams;"),i.push("const float packUpscale = 256. / 255.;"),i.push("const float unpackDownScale = 255. / 256.;"),i.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),i.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),i.push("float unpackRGBToFloat( const in vec4 v ) {"),i.push(" return dot( v, unPackFactors );"),i.push("}")),r){i.push("in vec4 vWorldPosition;"),i.push("in float vFlags;");for(var a=0,s=n.sectionPlanes.length;a> 16 & 0xF) == 1;"),i.push(" if (clippable) {"),i.push(" float dist = 0.0;");for(var c=0,f=n.sectionPlanes.length;c 0.0) { "),i.push(" discard;"),i.push(" }"),i.push("}")}i.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),i.push("float lambertian = 1.0;"),i.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),i.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),i.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var p=0,A=t.lights.length;p0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching silhouette fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = vColor;"),a.push("}"),a}}]),n}(),on=function(e){I(n,qt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("uniform int renderPass;"),n.push("uniform vec4 color;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),ln=function(e){I(n,qt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry edges drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),un=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry picking vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vPickColor; "),r.push("}"),r}}]),n}(),cn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),fn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vWorldNormal;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec3 worldNormal = octDecode(normal.xy); "),n.push(" vWorldNormal = worldNormal;"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}}]),n}(),pn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching occlusion fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),r.push("}"),r}}]),n}(),An=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec2 vHighPrecisionZW;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching depth fragment shader"),r.push("precision highp float;"),r.push("precision highp int;"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),r.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),r.push("}"),r}}]),n}(),dn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n,!0),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),vn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Batched geometry shadow vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 outColor;"),n.push("void main(void) {"),n.push(" int colorFlag = int(flags) & 0xF;"),n.push(" bool visible = (colorFlag > 0);"),n.push(" bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push(" if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene._sectionPlanesState,t=e.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// Batched geometry shadow fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),t){n.push("in vec4 vWorldPosition;"),n.push("in float vFlags;");for(var r=0;r> 16 & 0xF) == 1;"),n.push(" if (clippable) {"),n.push(" float dist = 0.0;");for(var i=0;i 0.0) { discard; }"),n.push(" }")}return n.push(" outColor = encodeFloat( gl_FragCoord.z); "),n.push("}"),n}}]),n}(),hn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=e._lightsState,r=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Triangles batching quality draw vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("precision highp usampler2D;"),a.push("precision highp isampler2D;"),a.push("precision highp sampler2D;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("precision mediump usampler2D;"),a.push("precision mediump isampler2D;"),a.push("precision mediump sampler2D;"),a.push("#endif"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),n.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),r&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&a.push("worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),a.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));"),a.push("vFragDepth = 1.0 + clipPos.w;")),r&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),n.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._sectionPlanesState,r=e._lightsState,i=n.sectionPlanes.length>0,a=n.clippingCaps,s=[];s.push("#version 300 es"),s.push("// Triangles batching quality draw fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform sampler2D uColorMap;"),s.push("uniform sampler2D uMetallicRoughMap;"),s.push("uniform sampler2D uEmissiveMap;"),s.push("uniform sampler2D uNormalMap;"),s.push("uniform sampler2D uAOMap;"),s.push("in vec4 vViewPosition;"),s.push("in vec3 vViewNormal;"),s.push("in vec4 vColor;"),s.push("in vec2 vUV;"),s.push("in vec2 vMetallicRoughness;"),r.lightMaps.length>0&&s.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(s,!0),r.reflectionMaps.length>0&&s.push("uniform samplerCube reflectionMap;"),r.lightMaps.length>0&&s.push("uniform samplerCube lightMap;"),s.push("uniform vec4 lightAmbient;");for(var o=0,l=r.lights.length;o0&&(s.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),s.push(" vec3 envMapColor = sRGBToLinear(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),s.push(" return envMapColor;"),s.push("}")),s.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),s.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),s.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),s.push("}"),s.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" return 1.0 / ( gl * gv );"),s.push("}"),s.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" return 0.5 / max( gv + gl, EPSILON );"),s.push("}"),s.push("float D_GGX(const in float alpha, const in float dotNH) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),s.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float alpha = ( roughness * roughness );"),s.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),s.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),s.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),s.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),s.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),s.push(" vec3 F = F_Schlick( specularColor, dotLH );"),s.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),s.push(" float D = D_GGX( alpha, dotNH );"),s.push(" return F * (G * D);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),s.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),s.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),s.push(" vec4 r = roughness * c0 + c1;"),s.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),s.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),s.push(" return specularColor * AB.x + AB.y;"),s.push("}"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&(s.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.lightMaps.length>0&&(s.push(" vec3 irradiance = sRGBToLinear(texture(lightMap, geometry.worldNormal)).rgb;"),s.push(" irradiance *= PI;"),s.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),r.reflectionMaps.length>0&&(s.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),s.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),s.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),s.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),s.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),s.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),s.push("}")),s.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),s.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),s.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),s.push("}"),s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var p=0,A=n.sectionPlanes.length;p (0.002 * vClipPosition.w)) {"),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" return;"),s.push("}")):(s.push(" if (dist > 0.0) { "),s.push(" discard;"),s.push(" }")),s.push("}")}s.push("IncidentLight light;"),s.push("Material material;"),s.push("Geometry geometry;"),s.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),s.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),s.push("float opacity = float(vColor.a) / 255.0;"),s.push("vec3 baseColor = rgb;"),s.push("float specularF0 = 1.0;"),s.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),s.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),s.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),s.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),s.push("baseColor *= colorTexel.rgb;"),s.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),s.push("metallic *= metalRoughTexel.b;"),s.push("roughness *= metalRoughTexel.g;"),s.push("vec3 viewNormal = perturbNormal2Arb(vViewPosition.xyz, normalize(vViewNormal), vUV );"),s.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),s.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),s.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),s.push("geometry.position = vViewPosition.xyz;"),s.push("geometry.viewNormal = -normalize(viewNormal);"),s.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),r.lightMaps.length>0&&s.push("geometry.worldNormal = normalize(vWorldNormal);"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&s.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var d=0,v=r.lights.length;d0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching pick flat normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("out vec4 vWorldPosition;"),t&&n.push("out float vFlags;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),t&&n.push(" vFlags = flags;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push(" }"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Triangles batching pick flat normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}}]),n}(),yn=function(e){I(n,Xt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles batching color texture vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._lightsState,r=e._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Triangles batching color texture fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),e.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),a.push("uniform sampler2D uColorMap;"),this._withSAO&&(a.push("uniform sampler2D uOcclusionTexture;"),a.push("uniform vec4 uSAOParams;"),a.push("const float packUpscale = 256. / 255.;"),a.push("const float unpackDownScale = 255. / 256.;"),a.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),a.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),a.push("float unpackRGBToFloat( const in vec4 v ) {"),a.push(" return dot( v, unPackFactors );"),a.push("}")),a.push("uniform float gammaFactor;"),a.push("vec4 linearToLinear( in vec4 value ) {"),a.push(" return value;"),a.push("}"),a.push("vec4 sRGBToLinear( in vec4 value ) {"),a.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),a.push("}"),a.push("vec4 gammaToLinear( in vec4 value) {"),a.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),a.push("}"),t&&(a.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),a.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),a.push("}")),i){a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;");for(var s=0,o=r.sectionPlanes.length;s> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;");for(var f=0,p=r.sectionPlanes.length;f 0.0) { "),a.push(" discard;"),a.push(" }"),a.push("}")}a.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),a.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),a.push("float lambertian = 1.0;"),a.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),a.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),a.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");for(var A=0,d=n.lights.length;A0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.uv=[],this.metallicRoughness=[],this.normals=[],this.pickColors=[],this.offsets=[],this.indices=[],this.edgeIndices=[]})),Tn=Z.mat4(),En=Z.mat4();function bn(e,t,n){for(var r=e.length,i=new Uint16Array(r),a=t[0],s=t[1],o=t[2],l=t[3]-a,u=t[4]-s,c=t[5]-o,f=65525,p=f/l,A=f/u,d=f/c,v=function(e){return e>=0?e:0},h=0;h=0?1:-1),s=(1-Math.abs(r))*(i>=0?1:-1),r=a,i=s}return new Int8Array([Math[t](127.5*r+(r<0?-1:0)),Math[n](127.5*i+(i<0?-1:0))])}function Rn(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}var Cn=Z.vec3(),_n=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=a.eye;e._origin[0]=l[0],e._origin[1]=l[1],e._origin[2]=l[2];var c=t.aabb,f=[Z.safeInv(c[3]-c[0])*Z.MAX_INT,Z.safeInv(c[4]-c[1])*Z.MAX_INT,Z.safeInv(c[5]-c[2])*Z.MAX_INT];if(e._coordinateScale[0]=Z.safeInv(f[0]),e._coordinateScale[1]=Z.safeInv(f[1]),e._coordinateScale[2]=Z.safeInv(f[2]),this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram()),e.pickViewMatrix&&(u=e.pickOrigin||u);var p=[u[0]-l[0],u[1]-l[1],u[2]-l[2]];s.uniform3fv(this._uCameraEyeRtc,p),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.layerNumber),s.uniform3fv(this._uCoordinateScaler,f),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible),s.uniform1i(this._uSolid,t.solid);var A=e.pickViewMatrix||a.viewMatrix,d=l?Ie(A,l):A;if(s.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){var v=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,v)}var h=i._sectionPlanesState.sectionPlanes.length;if(h>0)for(var I=i._sectionPlanesState.sectionPlanes,y=t.layerIndex*h,m=r.renderFlags,w=0;w0,n=[];return n.push("#version 300 es"),n.push("// VBO SnapBatchingDepthBufInitRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),n.push("uniform bool solid;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("out float isPerspective;")),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),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("// VBO SnapBatchingDepthBufInitRenderer 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 int layerNumber;"),r.push("uniform vec3 coordinateScaler;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Bn=Z.vec3(),On=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()+this._scene.pointsMaterial.hash}},{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;e._origin[0]=l[0],e._origin[1]=l[1],e._origin[2]=l[2];var u=t.aabb,c=[Z.safeInv(u[3]-u[0])*Z.MAX_INT,Z.safeInv(u[4]-u[1])*Z.MAX_INT,Z.safeInv(u[5]-u[2])*Z.MAX_INT];if(e._coordinateScale[0]=Z.safeInv(c[0]),e._coordinateScale[1]=Z.safeInv(c[1]),e._coordinateScale[2]=Z.safeInv(c[2]),this._program||(this._allocate(),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var f=a.eye;e.pickViewMatrix&&(f=e.pickOrigin||f);var p=[f[0]-l[0],f[1]-l[1],f[2]-l[2]];s.uniform3fv(this._uCameraEyeRtc,p),s.uniform2fv(this.uVectorA,e.snapVectorA),s.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),s.uniform1i(this._uLayerNumber,e.layerNumber),s.uniform3fv(this._uCoordinateScaler,c),s.uniform1i(this._uRenderPass,n),s.uniform1i(this._uPickInvisible,e.pickInvisible);var A=e.pickViewMatrix||a.viewMatrix,d=l?Ie(A,l):A;if(s.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix),s.uniformMatrix4fv(this._uViewMatrix,!1,d),s.uniformMatrix4fv(this._uProjMatrix,!1,a.projMatrix),i.logarithmicDepthBufferEnabled){var v=2/(Math.log(e.pickZFar+1)/Math.LN2);s.uniform1f(this._uLogDepthBufFC,v)}var h=i._sectionPlanesState.sectionPlanes.length;if(h>0)for(var I=i._sectionPlanesState.sectionPlanes,y=t.layerIndex*h,m=r.renderFlags,w=0;w0;e.pointsMaterial._state;var n=[];return n.push("#version 300 es"),n.push("// SnapBatchingDepthRenderer vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),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("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push(" } else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),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("// SnapBatchingDepthRenderer 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 int layerNumber;"),r.push("uniform vec3 coordinateScaler;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Sn=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new _n(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new On(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),Nn={};var Ln=Z.mat4(),xn=Z.mat4(),Mn=Z.vec4([0,0,0,1]),Fn=Z.vec4([0,0,0,1]),Hn=Z.vec4([0,0,0,1]),Un=Z.OBB3(),Gn=Z.vec3(),kn=Z.vec3(),Vn=Z.vec3(),jn=Z.vec3(),Qn=Z.vec3(),Wn=Z.vec3(),zn=Z.vec3(),Kn=function(){function e(t){var n,r,i;b(this,e),console.log("Creating TrianglesBatchingLayer"),this.model=t.model,this.sortId="TrianglesBatchingLayer"+(t.solid?"-solid":"-surface")+(t.autoNormals?"-autonormals":"-normals")+(t.textureSet&&t.textureSet.colorTexture?"-colorTexture":"")+(t.textureSet&&t.textureSet.metallicRoughnessTexture?"-metallicRoughnessTexture":""),this.layerIndex=t.layerIndex,this._batchingRenderers=(n=t.model.scene,r=n.id,(i=wn[r])||(i=new mn(n),wn[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete wn[r],i._destroy()}))),i),this._snapBatchingRenderers=function(e){var t=e.id,n=Nn[t];return n||(n=new Sn(e),Nn[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Nn[t],n._destroy()}))),n}(t.model.scene),this._buffer=new gn(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Mt({origin:Z.vec3(),positionsBuf:null,offsetsBuf:null,normalsBuf:null,colorsBuf:null,uvBuf:null,metallicRoughnessBuf:null,flagsBuf:null,indicesBuf:null,edgeIndicesBuf:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,textureSet:t.textureSet,pbrSupported:!1}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=Z.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,t.positionsDecodeMatrix&&(this._state.positionsDecodeMatrix=Z.mat4(t.positionsDecodeMatrix)),t.uvDecodeMatrix?(this._state.uvDecodeMatrix=Z.mat3(t.uvDecodeMatrix),this._preCompressedUVsExpected=!0):this._preCompressedUVsExpected=!1,t.origin&&this._state.origin.set(t.origin),this.aabb=Z.collapseAABB3(),this.solid=!!t.solid}return P(e,[{key:"canCreatePortion",value:function(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)for(var F=0,H=a.length;F0){var U=Ln;h?Z.inverseMat4(Z.transposeMat4(h,xn),U):Z.identityMat4(U,U),function(e,t,n,r,i){function a(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}var s,o,l,u,c,f=new Float32Array([0,0,0,0]),p=new Float32Array([0,0,0,0]);for(c=0;cu&&(o=s,u=l),(l=a(p,Rn(s=Pn(p,"floor","ceil"))))>u&&(o=s,u=l),(l=a(p,Rn(s=Pn(p,"ceil","ceil"))))>u&&(o=s,u=l),r[i+c+0]=o[0],r[i+c+1]=o[1],r[i+c+2]=0}(U,i,i.length,g.normals,g.normals.length)}if(l)for(var G=0,k=l.length;G0)for(var $=0,ee=s.length;$0)for(var te=0,ne=o.length;te0){var r=this._state.positionsDecodeMatrix?new Uint16Array(n.positions):bn(n.positions,this._modelAABB,this._state.positionsDecodeMatrix=Z.mat4());if(e.positionsBuf=new pt(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this.model.scene.pickSurfacePrecisionEnabled)for(var i=0,a=this._portions.length;i0){var u=new Int8Array(n.normals);e.normalsBuf=new pt(t,t.ARRAY_BUFFER,u,n.normals.length,3,t.STATIC_DRAW,!0)}if(n.colors.length>0){var c=new Uint8Array(n.colors);e.colorsBuf=new pt(t,t.ARRAY_BUFFER,c,n.colors.length,4,t.DYNAMIC_DRAW,!1)}if(n.uv.length>0)if(e.uvDecodeMatrix){e.uvBuf=new pt(t,t.ARRAY_BUFFER,n.uv,n.uv.length,2,t.STATIC_DRAW,!1)}else{var f=jt.getUVBounds(n.uv),p=jt.compressUVs(n.uv,f.min,f.max),A=p.quantized;e.uvDecodeMatrix=Z.mat3(p.decodeMatrix),e.uvBuf=new pt(t,t.ARRAY_BUFFER,A,A.length,2,t.STATIC_DRAW,!1)}if(n.metallicRoughness.length>0){var d=new Uint8Array(n.metallicRoughness);e.metallicRoughnessBuf=new pt(t,t.ARRAY_BUFFER,d,n.metallicRoughness.length,2,t.STATIC_DRAW,!1)}if(n.positions.length>0){var v=n.positions.length/3,h=new Float32Array(v);e.flagsBuf=new pt(t,t.ARRAY_BUFFER,h,h.length,1,t.DYNAMIC_DRAW,!1)}if(n.pickColors.length>0){var I=new Uint8Array(n.pickColors);e.pickColorsBuf=new pt(t,t.ARRAY_BUFFER,I,n.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var y=new Float32Array(n.offsets);e.offsetsBuf=new pt(t,t.ARRAY_BUFFER,y,n.offsets.length,3,t.DYNAMIC_DRAW)}if(n.indices.length>0){var m=new Uint32Array(n.indices);e.indicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,m,n.indices.length,1,t.STATIC_DRAW)}if(n.edgeIndices.length>0){var w=new Uint32Array(n.edgeIndices);e.edgeIndicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,w,n.edgeIndices.length,1,t.STATIC_DRAW)}this._state.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&e.textureSet&&e.textureSet.colorTexture&&e.textureSet.metallicRoughnessTexture),this._state.colorTextureSupported=!!e.uvBuf&&!!e.textureSet&&!!e.textureSet.colorTexture,this._buffer=null,this._finalized=!0}}},{key:"isEmpty",value:function(){return!this._state.indicesBuf}},{key:"initFlags",value:function(e,t,n){t&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,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{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._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=e,r=this._portions[n],i=4*r.vertsBaseIndex,a=4*r.numVerts,s=this._scratchMemory.getUInt8Array(a),o=t[0],l=t[1],u=t[2],c=t[3],f=0;f3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=e,o=this._portions[s],l=o.vertsBaseIndex,u=o.numVerts,c=l,f=u,p=!!(t&Te),A=!!(t&Re),d=!!(t&Ce),v=!!(t&_e),h=!!(t&Be),I=!!(t&be),y=!!(t&Ee);i=!p||y||A||d&&!this.model.scene.highlightMaterial.glowThrough||v&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,a=!p||y?Lt.NOT_RENDERED:v?Lt.SILHOUETTE_SELECTED:d?Lt.SILHOUETTE_HIGHLIGHTED:A?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED;var m=0;m=!p||y?Lt.NOT_RENDERED:v?Lt.EDGES_SELECTED:d?Lt.EDGES_HIGHLIGHTED:A?Lt.EDGES_XRAYED:h?n?Lt.EDGES_COLOR_TRANSPARENT:Lt.EDGES_COLOR_OPAQUE:Lt.NOT_RENDERED;var w=p&&!y&&I?Lt.PICK:Lt.NOT_RENDERED,g=t&De?1:0;if(r){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var T=c,E=c+f;TI)&&(I=b,r.set(y),i&&Z.triangleNormal(A,d,v,i),h=!0)}}return h&&i&&(Z.transformVec3(this.model.worldNormalMatrix,i,i),Z.normalizeVec3(i)),h}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.normalsBuf&&(e.normalsBuf.destroy(),e.normalsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.indicesBuf&&(e.indicesBuf.destroy(),e.indicessBuf=null),e.edgeIndicesBuf&&(e.edgeIndicesBuf.destroy(),e.edgeIndicessBuf=null),e.destroy()}}]),e}(),Yn=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e,t,n,r=this._scene,i=r._sectionPlanesState,a=r._lightsState,s=i.sectionPlanes.length>0,o=[];for(o.push("#version 300 es"),o.push("// Instancing geometry drawing vertex shader"),o.push("uniform int renderPass;"),o.push("in vec3 position;"),o.push("in vec2 normal;"),o.push("in vec4 color;"),o.push("in float flags;"),r.entityOffsetsEnabled&&o.push("in vec3 offset;"),o.push("in vec4 modelMatrixCol0;"),o.push("in vec4 modelMatrixCol1;"),o.push("in vec4 modelMatrixCol2;"),o.push("in vec4 modelNormalMatrixCol0;"),o.push("in vec4 modelNormalMatrixCol1;"),o.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(o,!0),r.logarithmicDepthBufferEnabled&&(o.push("uniform float logDepthBufFC;"),o.push("out float vFragDepth;"),o.push("bool isPerspectiveMatrix(mat4 m) {"),o.push(" return (m[2][3] == - 1.0);"),o.push("}"),o.push("out float isPerspective;")),o.push("uniform vec4 lightAmbient;"),e=0,t=a.lights.length;e= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),o.push(" }"),o.push(" return normalize(v);"),o.push("}"),s&&(o.push("out vec4 vWorldPosition;"),o.push("out float vFlags;")),o.push("out vec4 vColor;"),o.push("void main(void) {"),o.push("int colorFlag = int(flags) & 0xF;"),o.push("if (colorFlag != renderPass) {"),o.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),o.push("} else {"),o.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),o.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),r.entityOffsetsEnabled&&o.push(" worldPosition.xyz = worldPosition.xyz + offset;"),o.push("vec4 viewPosition = viewMatrix * worldPosition; "),o.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),o.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);"),o.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);"),o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),e=0,t=a.lights.length;e0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),this._withSAO&&(r.push("uniform sampler2D uOcclusionTexture;"),r.push("uniform vec4 uSAOParams;"),r.push("const float packUpscale = 256. / 255.;"),r.push("const float unpackDownScale = 255. / 256.;"),r.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),r.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),r.push("float unpackRGBToFloat( const in vec4 v ) {"),r.push(" return dot( v, unPackFactors );"),r.push("}")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { "),r.push(" discard;"),r.push(" }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),this._withSAO?(r.push(" float viewportWidth = uSAOParams[0];"),r.push(" float viewportHeight = uSAOParams[1];"),r.push(" float blendCutoff = uSAOParams[2];"),r.push(" float blendFactor = uSAOParams[3];"),r.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),r.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;"),r.push(" outColor = vec4(vColor.rgb * ambient, 1.0);")):r.push(" outColor = vColor;"),r.push("}"),r}}]),n}(),Xn=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry flat-shading drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=n._lightsState,a=r.sectionPlanes.length>0,s=[];if(s.push("#version 300 es"),s.push("// Instancing geometry flat-shading drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),n.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),a){s.push("in vec4 vWorldPosition;"),s.push("in float vFlags;");for(var o=0,l=r.sectionPlanes.length;o> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var c=0,f=r.sectionPlanes.length;c 0.0) { "),s.push(" discard;"),s.push(" }"),s.push("}")}for(s.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),s.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),s.push("float lambertian = 1.0;"),s.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),s.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),s.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=i.lights.length;e0,n=[];return n.push("#version 300 es"),n.push("// Instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 color;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 silhouetteColor;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vColor = vec4(silhouetteColor.r, silhouetteColor.g, silhouetteColor.b, min(silhouetteColor.a, float(color.a) / 255.0));"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing fill fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Jn=function(e){I(n,Zt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles instancing edges vertex shader"),n.push("uniform int renderPass;"),n.push("uniform vec4 color;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(color.r, color.g, color.b, color.a);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Zn=function(e){I(n,Zt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Triangles instancing edges vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int edgeFlag = int(flags) >> 8 & 0xF;"),n.push("if (edgeFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vColor = vec4(float(color.r*0.5) / 255.0, float(color.g*0.5) / 255.0, float(color.b*0.5) / 255.0, float(color.a) / 255.0);"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry edges drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),$n=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry picking vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 pickColor;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vPickColor;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry picking fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vPickColor; "),r.push("}"),r}}]),n}(),er=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry depth vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push(" vViewPosition = viewPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),tr=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec2 normal;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("in vec4 modelNormalMatrixCol0;"),n.push("in vec4 modelNormalMatrixCol1;"),n.push("in vec4 modelNormalMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vWorldNormal;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 worldNormal = vec3(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2));"),n.push(" vWorldNormal = worldNormal;"),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4((vWorldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}}]),n}(),nr=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing occlusion vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),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("in float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing occlusion fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),rr=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry depth drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec2 vHighPrecisionZW;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("vHighPrecisionZW = gl_Position.zw;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Instancing geometry depth drawing fragment shader"),a.push("precision highp float;"),a.push("precision highp int;"),n.logarithmicDepthBufferEnabled&&(a.push("in float isPerspective;"),a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;"),a.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); "),a.push("}"),a}}]),n}(),ir=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec3 normal;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n,!0),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),n.push("vec3 octDecode(vec2 oct) {"),n.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),n.push(" if (v.z < 0.0) {"),n.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),n.push(" }"),n.push(" return normalize(v);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec3 vViewNormal;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); "),n.push(" vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" vViewNormal = viewNormal;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),ar=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry shadow drawing vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("bool visible = (colorFlag > 0);"),n.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push("if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),sr=1e3,or=1001,lr=1002,ur=1003,cr=1004,fr=1004,pr=1005,Ar=1005,dr=1006,vr=1007,hr=1007,Ir=1008,yr=1008,mr=1009,wr=1010,gr=1011,Tr=1012,Er=1013,br=1014,Dr=1015,Pr=1016,Rr=1017,Cr=1018,_r=1020,Br=1021,Or=1022,Sr=1023,Nr=1024,Lr=1025,xr=1026,Mr=1027,Fr=1028,Hr=1029,Ur=1030,Gr=1031,kr=1033,Vr=33776,jr=33777,Qr=33778,Wr=33779,zr=35840,Kr=35841,Yr=35842,Xr=35843,qr=36196,Jr=37492,Zr=37496,$r=37808,ei=37809,ti=37810,ni=37811,ri=37812,ii=37813,ai=37814,si=37815,oi=37816,li=37817,ui=37818,ci=37819,fi=37820,pi=37821,Ai=36492,di=3e3,vi=3001,hi=1e4,Ii=10001,yi=10002,mi=10003,wi={3e3:"linearToLinear",3001:"sRGBToLinear"},gi=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=e._lightsState,r=t.sectionPlanes.length>0,i=t.clippingCaps,a=[];return a.push("#version 300 es"),a.push("// Instancing geometry quality drawing vertex shader"),a.push("uniform int renderPass;"),a.push("in vec3 position;"),a.push("in vec3 normal;"),a.push("in vec4 color;"),a.push("in vec2 uv;"),a.push("in vec2 metallicRoughness;"),a.push("in float flags;"),e.entityOffsetsEnabled&&a.push("in vec3 offset;"),a.push("in vec4 modelMatrixCol0;"),a.push("in vec4 modelMatrixCol1;"),a.push("in vec4 modelMatrixCol2;"),a.push("in vec4 modelNormalMatrixCol0;"),a.push("in vec4 modelNormalMatrixCol1;"),a.push("in vec4 modelNormalMatrixCol2;"),this._addMatricesUniformBlockLines(a,!0),a.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("out float vFragDepth;"),a.push("bool isPerspectiveMatrix(mat4 m) {"),a.push(" return (m[2][3] == - 1.0);"),a.push("}"),a.push("out float isPerspective;")),a.push("vec3 octDecode(vec2 oct) {"),a.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),a.push(" if (v.z < 0.0) {"),a.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"),a.push(" }"),a.push(" return normalize(v);"),a.push("}"),a.push("out vec4 vViewPosition;"),a.push("out vec3 vViewNormal;"),a.push("out vec4 vColor;"),a.push("out vec2 vUV;"),a.push("out vec2 vMetallicRoughness;"),n.lightMaps.length>0&&a.push("out vec3 vWorldNormal;"),r&&(a.push("out vec4 vWorldPosition;"),a.push("out float vFlags;"),i&&a.push("out vec4 vClipPosition;")),a.push("void main(void) {"),a.push("int colorFlag = int(flags) & 0xF;"),a.push("if (colorFlag != renderPass) {"),a.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),a.push("} else {"),a.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),a.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&a.push(" worldPosition.xyz = worldPosition.xyz + offset;"),a.push("vec4 viewPosition = viewMatrix * worldPosition; "),a.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); "),a.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 1.0);"),a.push("vec3 viewNormal = vec4(viewNormalMatrix * worldNormal).xyz;"),a.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(a.push("vFragDepth = 1.0 + clipPos.w;"),a.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),r&&(a.push("vWorldPosition = worldPosition;"),a.push("vFlags = flags;"),i&&a.push("vClipPosition = clipPos;")),a.push("vViewPosition = viewPosition;"),a.push("vViewNormal = viewNormal;"),a.push("vColor = color;"),a.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),a.push("vMetallicRoughness = metallicRoughness;"),n.lightMaps.length>0&&a.push("vWorldNormal = worldNormal.xyz;"),a.push("gl_Position = clipPos;"),a.push("}"),a.push("}"),a}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e.gammaOutput,n=e._sectionPlanesState,r=e._lightsState,i=n.sectionPlanes.length>0,a=n.clippingCaps,s=[];s.push("#version 300 es"),s.push("// Instancing geometry quality drawing fragment shader"),s.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),s.push("precision highp float;"),s.push("precision highp int;"),s.push("#else"),s.push("precision mediump float;"),s.push("precision mediump int;"),s.push("#endif"),e.logarithmicDepthBufferEnabled&&(s.push("in float isPerspective;"),s.push("uniform float logDepthBufFC;"),s.push("in float vFragDepth;")),s.push("uniform sampler2D uColorMap;"),s.push("uniform sampler2D uMetallicRoughMap;"),s.push("uniform sampler2D uEmissiveMap;"),s.push("uniform sampler2D uNormalMap;"),this._withSAO&&(s.push("uniform sampler2D uOcclusionTexture;"),s.push("uniform vec4 uSAOParams;"),s.push("const float packUpscale = 256. / 255.;"),s.push("const float unpackDownScale = 255. / 256.;"),s.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),s.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),s.push("float unpackRGBToFloat( const in vec4 v ) {"),s.push(" return dot( v, unPackFactors );"),s.push("}")),r.reflectionMaps.length>0&&s.push("uniform samplerCube reflectionMap;"),r.lightMaps.length>0&&s.push("uniform samplerCube lightMap;"),s.push("uniform vec4 lightAmbient;");for(var o=0,l=r.lights.length;o0&&s.push("in vec3 vWorldNormal;"),this._addMatricesUniformBlockLines(s,!0),s.push("#define PI 3.14159265359"),s.push("#define RECIPROCAL_PI 0.31830988618"),s.push("#define RECIPROCAL_PI2 0.15915494"),s.push("#define EPSILON 1e-6"),s.push("#define saturate(a) clamp( a, 0.0, 1.0 )"),s.push("vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {"),s.push(" vec3 texel = texture( uNormalMap, uv ).xyz;"),s.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),s.push(" return normalize(surf_norm );"),s.push(" }"),s.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),s.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),s.push(" vec2 st0 = dFdx( uv.st );"),s.push(" vec2 st1 = dFdy( uv.st );"),s.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),s.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),s.push(" vec3 N = normalize( surf_norm );"),s.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),s.push(" mat3 tsn = mat3( S, T, N );"),s.push(" return normalize( tsn * mapN );"),s.push("}"),s.push("vec3 inverseTransformDirection(in vec3 dir, in mat4 matrix) {"),s.push(" return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );"),s.push("}"),s.push("struct IncidentLight {"),s.push(" vec3 color;"),s.push(" vec3 direction;"),s.push("};"),s.push("struct ReflectedLight {"),s.push(" vec3 diffuse;"),s.push(" vec3 specular;"),s.push("};"),s.push("struct Geometry {"),s.push(" vec3 position;"),s.push(" vec3 viewNormal;"),s.push(" vec3 worldNormal;"),s.push(" vec3 viewEyeDir;"),s.push("};"),s.push("struct Material {"),s.push(" vec3 diffuseColor;"),s.push(" float specularRoughness;"),s.push(" vec3 specularColor;"),s.push(" float shine;"),s.push("};"),s.push("float GGXRoughnessToBlinnExponent(const in float ggxRoughness) {"),s.push(" float r = ggxRoughness + 0.0001;"),s.push(" return (2.0 / (r * r) - 2.0);"),s.push("}"),s.push("float getSpecularMIPLevel(const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float maxMIPLevelScalar = float( maxMIPLevel );"),s.push(" float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( ( blinnShininessExponent * blinnShininessExponent ) + 1.0 );"),s.push(" return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );"),s.push("}"),r.reflectionMaps.length>0&&(s.push("vec3 getLightProbeIndirectRadiance(const in vec3 reflectVec, const in float blinnShininessExponent, const in int maxMIPLevel) {"),s.push(" float mipLevel = 0.5 * getSpecularMIPLevel(blinnShininessExponent, maxMIPLevel);"),s.push(" vec3 envMapColor = "+wi[r.reflectionMaps[0].encoding]+"(texture(reflectionMap, reflectVec, mipLevel)).rgb;"),s.push(" return envMapColor;"),s.push("}")),s.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),s.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),s.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),s.push("}"),s.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" return 1.0 / ( gl * gv );"),s.push("}"),s.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),s.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),s.push(" return 0.5 / max( gv + gl, EPSILON );"),s.push("}"),s.push("float D_GGX(const in float alpha, const in float dotNH) {"),s.push(" float a2 = ( alpha * alpha );"),s.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),s.push(" return RECIPROCAL_PI * a2 / ( denom * denom);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight, const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float alpha = ( roughness * roughness );"),s.push(" vec3 halfDir = normalize( incidentLight.direction + geometry.viewEyeDir );"),s.push(" float dotNL = saturate( dot( geometry.viewNormal, incidentLight.direction ) );"),s.push(" float dotNV = saturate( dot( geometry.viewNormal, geometry.viewEyeDir ) );"),s.push(" float dotNH = saturate( dot( geometry.viewNormal, halfDir ) );"),s.push(" float dotLH = saturate( dot( incidentLight.direction, halfDir ) );"),s.push(" vec3 F = F_Schlick( specularColor, dotLH );"),s.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),s.push(" float D = D_GGX( alpha, dotNH );"),s.push(" return F * (G * D);"),s.push("}"),s.push("vec3 BRDF_Specular_GGX_Environment(const in Geometry geometry, const in vec3 specularColor, const in float roughness) {"),s.push(" float dotNV = saturate(dot(geometry.viewNormal, geometry.viewEyeDir));"),s.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),s.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),s.push(" vec4 r = roughness * c0 + c1;"),s.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),s.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),s.push(" return specularColor * AB.x + AB.y;"),s.push("}"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&(s.push("void computePBRLightMapping(const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),r.lightMaps.length>0&&(s.push(" vec3 irradiance = "+wi[r.lightMaps[0].encoding]+"(texture(lightMap, geometry.worldNormal)).rgb;"),s.push(" irradiance *= PI;"),s.push(" vec3 diffuseBRDFContrib = (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.diffuse += irradiance * diffuseBRDFContrib;")),r.reflectionMaps.length>0&&(s.push(" vec3 reflectVec = reflect(geometry.viewEyeDir, geometry.viewNormal);"),s.push(" reflectVec = inverseTransformDirection(reflectVec, viewMatrix);"),s.push(" float blinnExpFromRoughness = GGXRoughnessToBlinnExponent(material.specularRoughness);"),s.push(" vec3 radiance = getLightProbeIndirectRadiance(reflectVec, blinnExpFromRoughness, 8);"),s.push(" vec3 specularBRDFContrib = BRDF_Specular_GGX_Environment(geometry, material.specularColor, material.specularRoughness);"),s.push(" reflectedLight.specular += radiance * specularBRDFContrib;")),s.push("}")),s.push("void computePBRLighting(const in IncidentLight incidentLight, const in Geometry geometry, const in Material material, inout ReflectedLight reflectedLight) {"),s.push(" float dotNL = saturate(dot(geometry.viewNormal, incidentLight.direction));"),s.push(" vec3 irradiance = dotNL * incidentLight.color * PI;"),s.push(" reflectedLight.diffuse += irradiance * (RECIPROCAL_PI * material.diffuseColor);"),s.push(" reflectedLight.specular += irradiance * BRDF_Specular_GGX(incidentLight, geometry, material.specularColor, material.specularRoughness);"),s.push("}"),s.push("out vec4 outColor;"),s.push("void main(void) {"),i){s.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),s.push(" if (clippable) {"),s.push(" float dist = 0.0;");for(var p=0,A=n.sectionPlanes.length;p (0.002 * vClipPosition.w)) {"),s.push(" discard;"),s.push(" }"),s.push(" if (dist > 0.0) { "),s.push(" outColor=vec4(1.0, 0.0, 0.0, 1.0);"),e.logarithmicDepthBufferEnabled&&s.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),s.push(" return;"),s.push("}")):(s.push(" if (dist > 0.0) { "),s.push(" discard;"),s.push(" }")),s.push("}")}s.push("IncidentLight light;"),s.push("Material material;"),s.push("Geometry geometry;"),s.push("ReflectedLight reflectedLight = ReflectedLight(vec3(0.0,0.0,0.0), vec3(0.0,0.0,0.0));"),s.push("vec3 rgb = (vec3(float(vColor.r) / 255.0, float(vColor.g) / 255.0, float(vColor.b) / 255.0));"),s.push("float opacity = float(vColor.a) / 255.0;"),s.push("vec3 baseColor = rgb;"),s.push("float specularF0 = 1.0;"),s.push("float metallic = float(vMetallicRoughness.r) / 255.0;"),s.push("float roughness = float(vMetallicRoughness.g) / 255.0;"),s.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),s.push("vec4 colorTexel = sRGBToLinear(texture(uColorMap, vUV));"),s.push("baseColor *= colorTexel.rgb;"),s.push("vec3 metalRoughTexel = texture(uMetallicRoughMap, vUV).rgb;"),s.push("metallic *= metalRoughTexel.b;"),s.push("roughness *= metalRoughTexel.g;"),s.push("vec3 viewNormal = perturbNormal2Arb( vViewPosition.xyz, normalize(vViewNormal), vUV );"),s.push("material.diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),s.push("material.specularRoughness = clamp(roughness, 0.04, 1.0);"),s.push("material.specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),s.push("geometry.position = vViewPosition.xyz;"),s.push("geometry.viewNormal = -normalize(viewNormal);"),s.push("geometry.viewEyeDir = normalize(vViewPosition.xyz);"),r.lightMaps.length>0&&s.push("geometry.worldNormal = normalize(vWorldNormal);"),(r.lightMaps.length>0||r.reflectionMaps.length>0)&&s.push("computePBRLightMapping(geometry, material, reflectedLight);");for(var d=0,v=r.lights.length;d0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry normals vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&n.push("out float vFlags;"),n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),n.push(" vWorldPosition = worldPosition;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&n.push("vFlags = flags;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Batched geometry normals fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("in vec4 vWorldPosition;"),n){r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" vec3 xTangent = dFdx( vWorldPosition.xyz );"),r.push(" vec3 yTangent = dFdy( vWorldPosition.xyz );"),r.push(" vec3 worldNormal = normalize( cross( xTangent, yTangent ) );"),r.push(" outColor = vec4((worldNormal * 0.5) + 0.5, 1.0);"),r.push("}"),r}}]),n}(),Ei=function(e){I(n,Jt);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){var e=this._scene;return[e.gammaOutput,e._lightsState.getHash(),e._sectionPlanesState.getHash(),this._withSAO?"sao":"nosao"].join(";")}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry drawing vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in vec2 uv;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),n.push("uniform mat3 uvDecodeMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;"),n.push("bool isPerspectiveMatrix(mat4 m) {"),n.push(" return (m[2][3] == - 1.0);"),n.push("}"),n.push("out float isPerspective;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vViewPosition;"),n.push("out vec4 vColor;"),n.push("out vec2 vUV;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vViewPosition = viewPosition;"),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),n.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;"),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&(n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("isPerspective = float (isPerspectiveMatrix(projMatrix));")),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n.gammaOutput,i=n._sectionPlanesState,a=n._lightsState,s=i.sectionPlanes.length>0,o=[];if(o.push("#version 300 es"),o.push("// Instancing geometry drawing fragment shader"),o.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),o.push("precision highp float;"),o.push("precision highp int;"),o.push("#else"),o.push("precision mediump float;"),o.push("precision mediump int;"),o.push("#endif"),n.logarithmicDepthBufferEnabled&&(o.push("in float isPerspective;"),o.push("uniform float logDepthBufFC;"),o.push("in float vFragDepth;")),o.push("uniform sampler2D uColorMap;"),this._withSAO&&(o.push("uniform sampler2D uOcclusionTexture;"),o.push("uniform vec4 uSAOParams;"),o.push("const float packUpscale = 256. / 255.;"),o.push("const float unpackDownScale = 255. / 256.;"),o.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );"),o.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );"),o.push("float unpackRGBToFloat( const in vec4 v ) {"),o.push(" return dot( v, unPackFactors );"),o.push("}")),o.push("uniform float gammaFactor;"),o.push("vec4 linearToLinear( in vec4 value ) {"),o.push(" return value;"),o.push("}"),o.push("vec4 sRGBToLinear( in vec4 value ) {"),o.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );"),o.push("}"),o.push("vec4 gammaToLinear( in vec4 value) {"),o.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );"),o.push("}"),r&&(o.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {"),o.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );"),o.push("}")),s){o.push("in vec4 vWorldPosition;"),o.push("in float vFlags;");for(var l=0,u=i.sectionPlanes.length;l> 16 & 0xF) == 1;"),o.push(" if (clippable) {"),o.push(" float dist = 0.0;");for(var f=0,p=i.sectionPlanes.length;f 0.0) { "),o.push(" discard;"),o.push(" }"),o.push("}")}for(o.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),o.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);"),o.push("float lambertian = 1.0;"),o.push("vec3 xTangent = dFdx( vViewPosition.xyz );"),o.push("vec3 yTangent = dFdy( vViewPosition.xyz );"),o.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );"),e=0,t=a.lights.length;e0)for(var y=i._sectionPlanesState.sectionPlanes,m=t.layerIndex*I,w=r.renderFlags,g=0;g0,n=[];return n.push("#version 300 es"),n.push("// Points instancing snap vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),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("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.z += 0.0001;"),n.push("clipPos.xyzw *= tmp;"),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("// Points instancing pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform int layerNumber;"),r.push("uniform vec3 coordinateScaler;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Ci=Z.vec3(),_i=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.canvas.gl,s=t._state,o=t._state.origin,l=s.geometry;e._origin[0]=o[0],e._origin[1]=o[1],e._origin[2]=o[2];var u=t.aabb,c=[Z.safeInv(u[3]-u[0])*Z.MAX_INT,Z.safeInv(u[4]-u[1])*Z.MAX_INT,Z.safeInv(u[5]-u[2])*Z.MAX_INT];if(e._coordinateScale[0]=Z.safeInv(c[0]),e._coordinateScale[1]=Z.safeInv(c[1]),e._coordinateScale[2]=Z.safeInv(c[2]),this._program||(this._allocate(t),!this.errors)){e.lastProgramId!==this._program.id&&(e.lastProgramId=this._program.id,this._bindProgram());var f=i.camera,p=f.eye;e.pickViewMatrix&&(p=e.pickOrigin||p);var A=[p[0]-o[0],p[1]-o[1],p[2]-o[2]];a.uniform3fv(this._uCameraEyeRtc,A),a.uniform2fv(this.uVectorA,e.snapVectorA),a.uniform2fv(this.uInverseVectorAB,e.snapInvVectorAB),a.uniform1i(this._uLayerNumber,e.layerNumber),a.uniform3fv(this._uCoordinateScaler,c),a.uniform1i(this._uRenderPass,n),a.uniform1i(this._uPickInvisible,e.pickInvisible);var d=e.pickViewMatrix||f.viewMatrix,v=o?Ie(d,o):d;if(a.uniformMatrix4fv(this._uViewMatrix,!1,v),a.uniformMatrix4fv(this._uWorldMatrix,!1,r.worldMatrix),a.uniformMatrix4fv(this._uProjMatrix,!1,f.projMatrix),i.logarithmicDepthBufferEnabled){var h=2/(Math.log(e.pickZFar+1)/Math.LN2);a.uniform1f(this._uLogDepthBufFC,h)}var I=i._sectionPlanesState.sectionPlanes.length;if(I>0)for(var y=i._sectionPlanesState.sectionPlanes,m=t.layerIndex*I,w=r.renderFlags,g=0;g0,n=[];return n.push("#version 300 es"),n.push("// Points instancing snap vertex shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("precision highp usampler2D;"),n.push("precision highp isampler2D;"),n.push("precision highp sampler2D;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("precision mediump usampler2D;"),n.push("precision mediump isampler2D;"),n.push("precision mediump sampler2D;"),n.push("#endif"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform bool pickInvisible;"),n.push("uniform mat4 worldMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),n.push("uniform mat4 positionsDecodeMatrix;"),n.push("uniform vec3 uCameraEyeRtc;"),n.push("uniform vec2 snapVectorA;"),n.push("uniform vec2 snapInvVectorAB;"),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("vec2 remapClipPos(vec2 clipPos) {"),n.push(" float x = (clipPos.x - snapVectorA.x) * snapInvVectorAB.x;"),n.push(" float y = (clipPos.y - snapVectorA.y) * snapInvVectorAB.y;"),n.push(" return vec2(x, y);"),n.push("}"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out highp vec3 relativeToOriginPosition;"),n.push("void main(void) {"),n.push("int pickFlag = int(flags) >> 12 & 0xF;"),n.push("if (pickFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("relativeToOriginPosition = worldPosition.xyz;"),n.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push(" vWorldPosition = worldPosition;"),n.push(" vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),n.push("float tmp = clipPos.w;"),n.push("clipPos.xyzw /= tmp;"),n.push("clipPos.xy = remapClipPos(clipPos.xy);"),n.push("clipPos.xyzw *= tmp;"),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("// Points instancing pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("in float isPerspective;"),r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform int layerNumber;"),r.push("uniform vec3 coordinateScaler;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outCoords = ivec4(relativeToOriginPosition.xyz*coordinateScaler.xyz, layerNumber);"),r.push("}"),r}},{key:"webglContextRestored",value:function(){this._program=null}},{key:"destroy",value:function(){this._program&&this._program.destroy(),this._program=null}}]),e}(),Bi=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._snapDepthBufInitRenderer&&!this._snapDepthBufInitRenderer.getValid()&&(this._snapDepthBufInitRenderer.destroy(),this._snapDepthBufInitRenderer=null),this._snapDepthRenderer&&!this._snapDepthRenderer.getValid()&&(this._snapDepthRenderer.destroy(),this._snapDepthRenderer=null)}},{key:"snapDepthBufInitRenderer",get:function(){return this._snapDepthBufInitRenderer||(this._snapDepthBufInitRenderer=new Ri(this._scene,!1)),this._snapDepthBufInitRenderer}},{key:"snapDepthRenderer",get:function(){return this._snapDepthRenderer||(this._snapDepthRenderer=new _i(this._scene)),this._snapDepthRenderer}},{key:"_destroy",value:function(){this._snapDepthBufInitRenderer&&this._snapDepthBufInitRenderer.destroy(),this._snapDepthRenderer&&this._snapDepthRenderer.destroy()}}]),e}(),Oi={};var Si=new Uint8Array(4),Ni=new Float32Array(1),Li=Z.vec4([0,0,0,1]),xi=Z.vec4([0,0,0,1]),Mi=Z.vec4([0,0,0,1]),Fi=new Float32Array(3),Hi=Z.vec3(),Ui=Z.vec3(),Gi=Z.vec3(),ki=Z.vec3(),Vi=Z.vec3(),ji=Z.vec3(),Qi=Z.vec3(),Wi=function(){function e(t){var n,r,i;b(this,e),console.log("Creating TrianglesInstancingLayer"),this.model=t.model,this.sortId="TrianglesInstancingLayer"+(t.solid?"-solid":"-surface")+(t.normals?"-normals":"-autoNormals"),this.layerIndex=t.layerIndex,this._instancingRenderers=(n=t.model.scene,r=n.id,(i=Di[r])||(i=new bi(n),Di[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Di[r],i._destroy()}))),i),this._snapInstancingRenderers=function(e){var t=e.id,n=Oi[t];return n||(n=new Bi(e),Oi[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete Oi[t],n._destroy()}))),n}(t.model.scene),this._aabb=Z.collapseAABB3(),this._state=new Mt({numInstances:0,obb:Z.OBB3(),origin:Z.vec3(),geometry:t.geometry,textureSet:t.textureSet,pbrSupported:!1,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,colorsBuf:null,metallicRoughnessBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,modelNormalMatrixCol0Buf:null,modelNormalMatrixCol1Buf:null,modelNormalMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._metallicRoughness=[],this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[],this._portions=[],t.origin&&this._state.origin.set(t.origin),this._finalized=!1,this.aabb=Z.collapseAABB3(),this.solid=!!t.solid,this.numIndices=t.geometry.numIndices}return P(e,[{key:"createPortion",value:function(e){var t=e.color,n=e.metallic,r=e.roughness,i=null!==e.opacity&&void 0!==e.opacity?e.opacity:255,a=e.meshMatrix,s=e.sceneModelMatrix,o=e.aabb,l=e.pickColor;if(this._finalized)throw"Already finalized";var u=t[0],c=t[1],f=t[2];if(this._colors.push(u),this._colors.push(c),this._colors.push(f),this._colors.push(i),this._metallicRoughness.push(null!=n?n:0),this._metallicRoughness.push(null!=r?r:255),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(a[0]),this._modelMatrixCol0.push(a[4]),this._modelMatrixCol0.push(a[8]),this._modelMatrixCol0.push(a[12]),this._modelMatrixCol1.push(a[1]),this._modelMatrixCol1.push(a[5]),this._modelMatrixCol1.push(a[9]),this._modelMatrixCol1.push(a[13]),this._modelMatrixCol2.push(a[2]),this._modelMatrixCol2.push(a[6]),this._modelMatrixCol2.push(a[10]),this._modelMatrixCol2.push(a[14]),this._state.geometry.normals){var p=Z.transposeMat4(a,Z.mat4()),A=Z.inverseMat4(p);this._modelNormalMatrixCol0.push(A[0]),this._modelNormalMatrixCol0.push(A[4]),this._modelNormalMatrixCol0.push(A[8]),this._modelNormalMatrixCol0.push(A[12]),this._modelNormalMatrixCol1.push(A[1]),this._modelNormalMatrixCol1.push(A[5]),this._modelNormalMatrixCol1.push(A[9]),this._modelNormalMatrixCol1.push(A[13]),this._modelNormalMatrixCol2.push(A[2]),this._modelNormalMatrixCol2.push(A[6]),this._modelNormalMatrixCol2.push(A[10]),this._modelNormalMatrixCol2.push(A[14])}this._pickColors.push(l[0]),this._pickColors.push(l[1]),this._pickColors.push(l[2]),this._pickColors.push(l[3]);for(var d=this._state.geometry.positionsCompressed.length,v=this._state.geometry.positionsCompressed,h=this._state.geometry.positionsDecodeMatrix,I=0;I0){e.colorsBuf=new pt(r,r.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,r.DYNAMIC_DRAW,!1),this._colors=[]}if(this._metallicRoughness.length>0){var s=new Uint8Array(this._metallicRoughness);e.metallicRoughnessBuf=new pt(r,r.ARRAY_BUFFER,s,this._metallicRoughness.length,2,r.STATIC_DRAW,!1)}if(a>0){e.flagsBuf=new pt(r,r.ARRAY_BUFFER,new Float32Array(a),a,1,r.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){e.offsetsBuf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,r.DYNAMIC_DRAW,!1),this._offsets=[]}if(t.positionsCompressed&&t.positionsCompressed.length>0){e.positionsBuf=new pt(r,r.ARRAY_BUFFER,t.positionsCompressed,t.positionsCompressed.length,3,r.STATIC_DRAW,!1),e.positionsDecodeMatrix=Z.mat4(t.positionsDecodeMatrix)}if(t.colorsCompressed&&t.colorsCompressed.length>0){var o=new Uint8Array(t.colorsCompressed);e.colorsBuf=new pt(r,r.ARRAY_BUFFER,o,o.length,4,r.STATIC_DRAW,!1)}if(t.uvCompressed&&t.uvCompressed.length>0){var l=t.uvCompressed;e.uvDecodeMatrix=t.uvDecodeMatrix,e.uvBuf=new pt(r,r.ARRAY_BUFFER,l,l.length,2,r.STATIC_DRAW,!1)}if(t.indices&&t.indices.length>0&&(e.indicesBuf=new pt(r,r.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),t.indices.length,1,r.STATIC_DRAW),e.numIndices=t.indices.length),"triangles"!==t.primitive&&"solid"!==t.primitive&&"surface"!==t.primitive||(e.edgeIndicesBuf=new pt(r,r.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.edgeIndices),t.edgeIndices.length,1,r.STATIC_DRAW)),this._modelMatrixCol0.length>0){var u=!1;e.modelMatrixCol0Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,r.STATIC_DRAW,u),e.modelMatrixCol1Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,r.STATIC_DRAW,u),e.modelMatrixCol2Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,r.STATIC_DRAW,u),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],e.normalsBuf&&(e.modelNormalMatrixCol0Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol0),this._modelNormalMatrixCol0.length,4,r.STATIC_DRAW,u),e.modelNormalMatrixCol1Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol1),this._modelNormalMatrixCol1.length,4,r.STATIC_DRAW,u),e.modelNormalMatrixCol2Buf=new pt(r,r.ARRAY_BUFFER,new Float32Array(this._modelNormalMatrixCol2),this._modelNormalMatrixCol2.length,4,r.STATIC_DRAW,u),this._modelNormalMatrixCol0=[],this._modelNormalMatrixCol1=[],this._modelNormalMatrixCol2=[])}if(this._pickColors.length>0){e.pickColorsBuf=new pt(r,r.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,r.STATIC_DRAW,!1),this._pickColors=[]}e.pbrSupported=!!(e.metallicRoughnessBuf&&e.uvBuf&&e.normalsBuf&&n&&n.colorTexture&&n.metallicRoughnessTexture),e.colorTextureSupported=!!e.uvBuf&&!!n&&!!n.colorTexture,this._state.geometry=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&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)}},{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._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Si[0]=t[0],Si[1]=t[1],Si[2]=t[2],Si[3]=t[3],this._state.colorsBuf&&this._state.colorsBuf.setData(Si,4*e)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Te),i=!!(t&Re),a=!!(t&Ce),s=!!(t&_e),o=!!(t&Be),l=!!(t&be),u=!!(t&Ee),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.SILHOUETTE_SELECTED:a?Lt.SILHOUETTE_HIGHLIGHTED:i?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED)<<4,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.EDGES_SELECTED:a?Lt.EDGES_HIGHLIGHTED:i?Lt.EDGES_XRAYED:o?n?Lt.EDGES_COLOR_TRANSPARENT:Lt.EDGES_COLOR_OPAQUE:Lt.NOT_RENDERED)<<8,c|=(r&&!u&&l?Lt.PICK:Lt.NOT_RENDERED)<<12,c|=(t&De?1:0)<<16,Ni[0]=c,this._state.flagsBuf&&this._state.flagsBuf.setData(Ni,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Fi[0]=t[0],Fi[1]=t[1],Fi[2]=t[2],this._state.offsetsBuf&&this._state.offsetsBuf.setData(Fi,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"getEachVertex",value:function(e,t){if(!this.model.scene.pickSurfacePrecisionEnabled)return!1;var n=this._state,r=n.geometry,i=this._portions[e];if(i)for(var a=r.quantizedPositions,s=n.origin,o=i.offset,l=s[0]+o[0],u=s[1]+o[1],c=s[2]+o[2],f=Li,p=i.matrix,A=this.model.sceneModelMatrix,d=n.positionsDecodeMatrix,v=0,h=a.length;vy)&&(y=P,r.set(m),i&&Z.triangleNormal(d,v,h,i),I=!0)}}return I&&i&&(Z.transformVec3(o.normalMatrix,i,i),Z.transformVec3(this.model.worldNormalMatrix,i,i),Z.normalizeVec3(i)),I}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.metallicRoughnessBuf&&(e.metallicRoughnessBuf.destroy(),e.metallicRoughnessBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.modelNormalMatrixCol0Buf&&(e.modelNormalMatrixCol0Buf.destroy(),e.modelNormalMatrixCol0Buf=null),e.modelNormalMatrixCol1Buf&&(e.modelNormalMatrixCol1Buf.destroy(),e.modelNormalMatrixCol1Buf=null),e.modelNormalMatrixCol2Buf&&(e.modelNormalMatrixCol2Buf.destroy(),e.modelNormalMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy(),this._state=null}}]),e}(),zi=function(e){I(n,tn);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines batching color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push("worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines batching color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),Ki=function(e){I(n,tn);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines batching silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),this._addMatricesUniformBlockLines(n),n.push("uniform vec4 color;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines batching silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = color;"),r.push("}"),r}}]),n}(),Yi=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new zi(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new Ki(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),Xi={};var qi=P((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.offsets=[],this.indices=[]})),Ji=Z.vec4([0,0,0,1]),Zi=Z.vec4([0,0,0,1]),$i=Z.vec4([0,0,0,1]),ea=Z.OBB3(),ta=function(){function e(t){var n,r,i;b(this,e),this.layerIndex=t.layerIndex,this._batchingRenderers=(n=t.model.scene,r=n.id,(i=Xi[r])||(i=new Yi(n),Xi[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Xi[r],i._destroy()}))),i),this.model=t.model,this._buffer=new qi(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Mt({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,indicesBuf:null,positionsDecodeMatrix:Z.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=Z.collapseAABB3(),this._portions=[],this._numVerts=0,this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=Z.vec3(t.origin)),this.aabb=Z.collapseAABB3()}return P(e,[{key:"canCreatePortion",value:function(e,t){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts&&this._buffer.indices.length+t0)if(this._preCompressedPositionsExpected){var r=new Uint16Array(n.positions);e.positionsBuf=new pt(t,t.ARRAY_BUFFER,r,n.positions.length,3,t.STATIC_DRAW)}else{var i=bn(new Float32Array(n.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new pt(t,t.ARRAY_BUFFER,i,n.positions.length,3,t.STATIC_DRAW)}if(n.colors.length>0){var a=new Uint8Array(n.colors);e.colorsBuf=new pt(t,t.ARRAY_BUFFER,a,n.colors.length,4,t.DYNAMIC_DRAW,!1)}if(n.colors.length>0){var s=n.colors.length/4,o=new Float32Array(s);e.flagsBuf=new pt(t,t.ARRAY_BUFFER,o,o.length,1,t.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var l=new Float32Array(n.offsets);e.offsetsBuf=new pt(t,t.ARRAY_BUFFER,l,n.offsets.length,3,t.DYNAMIC_DRAW)}if(n.indices.length>0){var u=new Uint32Array(n.indices);e.indicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,u,n.indices.length,1,t.STATIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&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,!0)}},{key:"flushInitFlags",value:function(){this._setDeferredFlags()}},{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._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=2*e,r=4*this._portions[n],i=4*this._portions[n+1],a=this._scratchMemory.getUInt8Array(i),s=t[0],o=t[1],l=t[2],u=t[3],c=0;c3&&void 0!==arguments[3]&&arguments[3];if(!this._finalized)throw"Not finalized";var i,a,s=2*e,o=this._portions[s],l=this._portions[s+1],u=o,c=l,f=!!(t&Te),p=!!(t&Re),A=!!(t&Ce),d=!!(t&_e),v=!!(t&be),h=!!(t&Ee);i=!f||h||p||A&&!this.model.scene.highlightMaterial.glowThrough||d&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,a=!f||h?Lt.NOT_RENDERED:d?Lt.SILHOUETTE_SELECTED:A?Lt.SILHOUETTE_HIGHLIGHTED:p?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED;var I=f&&!h&&v?Lt.PICK:Lt.NOT_RENDERED,y=t&De?1:0;if(r){this._deferredFlagValues||(this._deferredFlagValues=new Float32Array(this._numVerts));for(var m=u,w=u+c;m0,n=[];return n.push("#version 300 es"),n.push("// Lines instancing color vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),n.push("in vec4 color;"),n.push("in float flags;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 lightAmbient;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("out vec4 vColor;"),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("if (colorFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),n.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);"),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Lines instancing color fragment shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return this._withSAO?(a.push(" float viewportWidth = uSAOParams[0];"),a.push(" float viewportHeight = uSAOParams[1];"),a.push(" float blendCutoff = uSAOParams[2];"),a.push(" float blendFactor = uSAOParams[3];"),a.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);"),a.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBAToDepth(texture(uOcclusionTexture, uv))) * blendFactor;"),a.push(" outColor = vec4(vColor.rgb * ambient, vColor.a);")):a.push(" outColor = vColor;"),n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),ra=function(e){I(n,nn);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Lines instancing silhouette vertex shader"),n.push("uniform int renderPass;"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(n),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),n.push("uniform vec4 color;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),n.push("if (silhouetteFlag != renderPass) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&n.push("vFragDepth = 1.0 + clipPos.w;"),n.push("gl_Position = clipPos;"),n.push("}"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Lines instancing silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = color;"),r.push("}"),r}}]),n}(),ia=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new na(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new ra(this._scene)),this._silhouetteRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy()}}]),e}(),aa={};var sa=new Uint8Array(4),oa=new Float32Array(1),la=Z.vec4([0,0,0,1]),ua=Z.vec4([0,0,0,1]),ca=Z.vec4([0,0,0,1]),fa=new Float32Array(3),pa=function(){function e(t){var n,r,i;b(this,e),this.model=t.model,this.material=t.material,this.sortId="LinesInstancingLayer",this.layerIndex=t.layerIndex,this._linesInstancingRenderers=(n=t.model.scene,r=n.id,(i=aa[r])||(i=new ia(n),aa[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete aa[r],i._destroy()}))),i),this._aabb=Z.collapseAABB3(),this._state=new Mt({obb:Z.OBB3(),numInstances:0,origin:null,geometry:t.geometry,positionsDecodeMatrix:t.geometry.positionsDecodeMatrix,positionsBuf:null,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._colors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],t.origin&&(this._state.origin=Z.vec3(t.origin)),this._finalized=!1,this.aabb=Z.collapseAABB3()}return P(e,[{key:"createPortion",value:function(e){var t=e.color,n=e.opacity,r=e.meshMatrix,i=e.worldMatrix,a=e.aabb;if(this._finalized)throw"Already finalized";var s=t[0],o=t[1],l=t[2];t[3],this._colors.push(s),this._colors.push(o),this._colors.push(l),this._colors.push(n),this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(r[0]),this._modelMatrixCol0.push(r[4]),this._modelMatrixCol0.push(r[8]),this._modelMatrixCol0.push(r[12]),this._modelMatrixCol1.push(r[1]),this._modelMatrixCol1.push(r[5]),this._modelMatrixCol1.push(r[9]),this._modelMatrixCol1.push(r[13]),this._modelMatrixCol2.push(r[2]),this._modelMatrixCol2.push(r[6]),this._modelMatrixCol2.push(r[10]),this._modelMatrixCol2.push(r[14]),Z.collapseAABB3(a);for(var u=this._state.obb,c=u.length,f=0;f0){this._state.colorsBuf=new pt(e,e.ARRAY_BUFFER,new Uint8Array(this._colors),this._colors.length,4,e.DYNAMIC_DRAW,!1),this._colors=[]}if(n>0){this._state.flagsBuf=new pt(e,e.ARRAY_BUFFER,new Float32Array(n),n,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){this._state.offsetsBuf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(this._modelMatrixCol0.length>0){var r=!1;this._state.modelMatrixCol0Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,r),this._state.modelMatrixCol1Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,r),this._state.modelMatrixCol2Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,r),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}this._state.geometry=null,this._finalized=!0}},{key:"initFlags",value:function(e,t,n){t&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)}},{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._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";sa[0]=t[0],sa[1]=t[1],sa[2]=t[2],sa[3]=t[3],this._state.colorsBuf.setData(sa,4*e,4)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Te),i=!!(t&Re),a=!!(t&Ce),s=!!(t&_e),o=!!(t&Be),l=!!(t&be),u=!!(t&Ee),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.SILHOUETTE_SELECTED:a?Lt.SILHOUETTE_HIGHLIGHTED:i?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED)<<4,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.EDGES_SELECTED:a?Lt.EDGES_HIGHLIGHTED:i?Lt.EDGES_XRAYED:o?n?Lt.EDGES_COLOR_TRANSPARENT:Lt.EDGES_COLOR_OPAQUE:Lt.NOT_RENDERED)<<8,c|=(r&&!u&&l?Lt.PICK:Lt.NOT_RENDERED)<<12,c|=(t&De?255:0)<<16,oa[0]=c,this._state.flagsBuf.setData(oa,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(fa[0]=t[0],fa[1]=t[1],fa[2]=t[2],this._state.offsetsBuf.setData(fa,3*e,3)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Lt.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._linesInstancingRenderers.colorRenderer&&this._linesInstancingRenderers.colorRenderer.drawLayer(t,this,Lt.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._linesInstancingRenderers.silhouetteRenderer&&this._linesInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){}},{key:"drawPickDepths",value:function(e,t){}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.positionsBuf&&(e.positionsBuf.destroy(),e.positionsBuf=null),e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.destroy()}}]),e}(),Aa=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{incrementDrawState:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial,r=[];return r.push("#version 300 es"),r.push("// Points batching color vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("in float flags;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),n.filterIntensity&&r.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),n.filterIntensity&&(r.push("float intensity = float(color.a) / 255.0;"),r.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {")),r.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push("worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),n.filterIntensity&&r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),da=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching silhouette vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),this._addMatricesUniformBlockLines(r),r.push("uniform vec4 color;"),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),r.push("if (silhouetteFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points batching silhouette vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("outColor = color;"),a.push("}"),a}}]),n}(),va=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching pick mesh vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 pickColor;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vPickColor;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),r.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("gl_PointSize += 10.0;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching pick mesh vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vPickColor; "),r.push("}"),r}}]),n}(),ha=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batched pick depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vViewPosition;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vViewPosition = viewPosition;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("gl_PointSize += 10.0;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batched pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Ia=function(e){I(n,$t);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points batching occlusion vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push(" } else {"),r.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); "),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push(" gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push(" }"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points batching occlusion fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push(" }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),r.push("}"),r}}]),n}(),ya=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Aa(this._scene)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new da(this._scene)),this._silhouetteRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new va(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new ha(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Ia(this._scene)),this._occlusionRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy()}}]),e}(),ma={};var wa=P((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e6;b(this,e),t>5e6&&(t=5e6),this.maxVerts=t,this.maxIndices=3*t,this.positions=[],this.colors=[],this.intensities=[],this.pickColors=[],this.offsets=[]})),ga=Z.vec4(),Ta=Z.vec4(),Ea=Z.vec4([0,0,0,1]),ba=Z.vec4([0,0,0,1]),Da=Z.vec4([0,0,0,1]),Pa=Z.OBB3(),Ra=function(){function e(t){b(this,e),this.model=t.model,this.sortId="PointsBatchingLayer",this.layerIndex=t.layerIndex,this._pointsBatchingRenderers=function(e){var t=e.id,n=ma[t];return n||(n=new ya(e),ma[t]=n,n._compile(),e.on("compile",(function(){n._compile()})),e.on("destroyed",(function(){delete ma[t],n._destroy()}))),n}(t.model.scene),this._buffer=new wa(t.maxGeometryBatchSize),this._scratchMemory=t.scratchMemory,this._state=new Mt({positionsBuf:null,offsetsBuf:null,colorsBuf:null,flagsBuf:null,positionsDecodeMatrix:Z.mat4(),origin:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numSelectedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numClippableLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this._modelAABB=Z.collapseAABB3(),this._portions=[],this._finalized=!1,t.positionsDecodeMatrix?(this._state.positionsDecodeMatrix.set(t.positionsDecodeMatrix),this._preCompressedPositionsExpected=!0):this._preCompressedPositionsExpected=!1,t.origin&&(this._state.origin=Z.vec3(t.origin)),this.aabb=Z.collapseAABB3()}return P(e,[{key:"canCreatePortion",value:function(e){if(this._finalized)throw"Already finalized";return this._buffer.positions.length+e<3*this._buffer.maxVerts}},{key:"createPortion",value:function(e){if(this._finalized)throw"Already finalized";var t,n=e.positions,r=e.positionsCompressed,i=e.color,a=e.colorsCompressed,s=e.colors,o=e.meshMatrix,l=e.worldMatrix,u=e.worldAABB,c=e.pickColor,f=this._buffer,p=f.positions.length/3;if(this._preCompressedPositionsExpected){if(!r)throw"positionsCompressed expected";for(var A=0,d=r.length;A0)if(this._preCompressedPositionsExpected){var r=new Uint16Array(n.positions);e.positionsBuf=new pt(t,t.ARRAY_BUFFER,r,n.positions.length,3,t.STATIC_DRAW)}else{var i=bn(new Float32Array(n.positions),this._modelAABB,e.positionsDecodeMatrix);e.positionsBuf=new pt(t,t.ARRAY_BUFFER,i,n.positions.length,3,t.STATIC_DRAW)}if(n.colors.length>0){var a=new Uint8Array(n.colors);e.colorsBuf=new pt(t,t.ARRAY_BUFFER,a,n.colors.length,4,t.STATIC_DRAW,!1)}if(n.positions.length>0){var s=n.positions.length/3,o=new Float32Array(s);e.flagsBuf=new pt(t,t.ARRAY_BUFFER,o,o.length,1,t.DYNAMIC_DRAW,!1)}if(n.pickColors.length>0){var l=new Uint8Array(n.pickColors);e.pickColorsBuf=new pt(t,t.ARRAY_BUFFER,l,n.pickColors.length,4,t.STATIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&n.offsets.length>0){var u=new Float32Array(n.offsets);e.offsetsBuf=new pt(t,t.ARRAY_BUFFER,u,n.offsets.length,3,t.DYNAMIC_DRAW)}this._buffer=null,this._finalized=!0}}},{key:"initFlags",value:function(e,t,n){t&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._numPickableLayerPortions++,this.model.numPickableLayerPortions++),t&Ee&&(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++),this._setFlags(e,t,n)}},{key:"setVisible",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&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"}},{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._setFlags(e,t)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";for(var n=2*e,r=4*this._portions[n],i=4*this._portions[n+1],a=this._scratchMemory.getUInt8Array(i),s=t[0],o=t[1],l=t[2],u=0;u0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing color vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),r.push("in vec4 color;"),r.push("in float flags;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),n.filterIntensity&&r.push("uniform vec2 intensityRange;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),n.filterIntensity&&(r.push("float intensity = float(color.a) / 255.0;"),r.push("if (intensity < intensityRange[0] || intensity > intensityRange[1]) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {")),r.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),r.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, 1.0);"),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),n.filterIntensity&&r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing color fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vColor;"),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),_a=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"drawLayer",value:function(e,t,r){v(T(n.prototype),"drawLayer",this).call(this,e,t,r,{colorUniform:!0})}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing silhouette vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 color;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),r.push("uniform vec4 silhouetteColor;"),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vColor;"),r.push("void main(void) {"),r.push("int silhouetteFlag = int(flags) >> 4 & 0xF;"),r.push("if (silhouetteFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push("vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("vColor = vec4(float(silhouetteColor.r) / 255.0, float(silhouetteColor.g) / 255.0, float(silhouetteColor.b) / 255.0, float(color.a) / 255.0);"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing silhouette fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vColor;"),r.push("}"),r}}]),n}(),Ba=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing pick mesh vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 pickColor;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vPickColor;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),r.push(" vPickColor = vec4(float(pickColor.r) / 255.0, float(pickColor.g) / 255.0, float(pickColor.b) / 255.0, float(pickColor.a) / 255.0);"),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing pick mesh fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("outColor = vPickColor; "),r.push("}"),r}}]),n}(),Oa=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing pick depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),r.push("uniform bool pickInvisible;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("out vec4 vViewPosition;"),r.push("void main(void) {"),r.push("int pickFlag = int(flags) >> 12 & 0xF;"),r.push("if (pickFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push(" vFlags = flags;")),r.push(" vViewPosition = viewPosition;"),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing pick depth fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),r.push("uniform float pickZNear;"),r.push("uniform float pickZFar;"),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" float zNormalizedDepth = abs((pickZNear + vViewPosition.z) / (pickZFar - pickZNear));"),r.push(" outColor = packDepth(zNormalizedDepth); "),r.push("}"),r}}]),n}(),Sa=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing occlusion vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in vec4 color;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push(" vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Points instancing occlusion vertex shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0;i 1.0) {"),r.push(" discard;"),r.push(" }")),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var a=0;a 0.0) { discard; }"),r.push("}")}return r.push(" outColor = vec4(0.0, 0.0, 1.0, 1.0); "),e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push("}"),r}}]),n}(),Na=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_getHash",value:function(){return this._scene._sectionPlanesState.getHash()+this._scene.pointsMaterial.hash}},{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=e.pointsMaterial._state,r=[];return r.push("#version 300 es"),r.push("// Points instancing depth vertex shader"),r.push("uniform int renderPass;"),r.push("in vec3 position;"),e.entityOffsetsEnabled&&r.push("in vec3 offset;"),r.push("in float flags;"),r.push("in vec4 modelMatrixCol0;"),r.push("in vec4 modelMatrixCol1;"),r.push("in vec4 modelMatrixCol2;"),this._addMatricesUniformBlockLines(r),r.push("uniform float pointSize;"),n.perspectivePoints&&r.push("uniform float nearPlaneHeight;"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("out float vFragDepth;")),t&&(r.push("out vec4 vWorldPosition;"),r.push("out float vFlags;")),r.push("void main(void) {"),r.push("int colorFlag = int(flags) & 0xF;"),r.push("if (colorFlag != renderPass) {"),r.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),r.push("} else {"),r.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),r.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&r.push(" worldPosition.xyz = worldPosition.xyz + offset;"),r.push(" vec4 viewPosition = viewMatrix * worldPosition; "),t&&(r.push("vWorldPosition = worldPosition;"),r.push("vFlags = flags;")),r.push("vec4 clipPos = projMatrix * viewPosition;"),e.logarithmicDepthBufferEnabled&&r.push("vFragDepth = 1.0 + clipPos.w;"),r.push("gl_Position = clipPos;"),n.perspectivePoints?(r.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;"),r.push("gl_PointSize = max(gl_PointSize, "+Math.floor(n.minPerspectivePointSize)+".0);"),r.push("gl_PointSize = min(gl_PointSize, "+Math.floor(n.maxPerspectivePointSize)+".0);")):r.push("gl_PointSize = pointSize;"),r.push("}"),r.push("}"),r}},{key:"_buildFragmentShader",value:function(){var e,t,n=this._scene,r=n._sectionPlanesState,i=r.sectionPlanes.length>0,a=[];if(a.push("#version 300 es"),a.push("// Points instancing depth vertex shader"),a.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),a.push("precision highp float;"),a.push("precision highp int;"),a.push("#else"),a.push("precision mediump float;"),a.push("precision mediump int;"),a.push("#endif"),n.logarithmicDepthBufferEnabled&&(a.push("uniform float logDepthBufFC;"),a.push("in float vFragDepth;")),i)for(a.push("in vec4 vWorldPosition;"),a.push("in float vFlags;"),e=0,t=r.sectionPlanes.length;e 1.0) {"),a.push(" discard;"),a.push(" }")),i){for(a.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),a.push(" if (clippable) {"),a.push(" float dist = 0.0;"),e=0,t=r.sectionPlanes.length;e 0.0) { discard; }"),a.push("}")}return a.push(" outColor = packDepthToRGBA( gl_FragCoord.z); "),n.logarithmicDepthBufferEnabled&&a.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),a.push("}"),a}}]),n}(),La=function(e){I(n,en);var t=m(n);function n(){return b(this,n),t.apply(this,arguments)}return P(n,[{key:"_buildVertexShader",value:function(){var e=this._scene,t=e._sectionPlanesState.sectionPlanes.length>0,n=[];return n.push("#version 300 es"),n.push("// Instancing geometry shadow drawing vertex shader"),n.push("in vec3 position;"),e.entityOffsetsEnabled&&n.push("in vec3 offset;"),n.push("in vec4 color;"),n.push("in float flags;"),n.push("in vec4 modelMatrixCol0;"),n.push("in vec4 modelMatrixCol1;"),n.push("in vec4 modelMatrixCol2;"),n.push("uniform mat4 shadowViewMatrix;"),n.push("uniform mat4 shadowProjMatrix;"),this._addMatricesUniformBlockLines(n),n.push("uniform float pointSize;"),t&&(n.push("out vec4 vWorldPosition;"),n.push("out float vFlags;")),n.push("void main(void) {"),n.push("int colorFlag = int(flags) & 0xF;"),n.push("bool visible = (colorFlag > 0);"),n.push("bool transparent = ((float(color.a) / 255.0) < 1.0);"),n.push("if (!visible || transparent) {"),n.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"),n.push("} else {"),n.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); "),n.push(" worldPosition = vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);"),e.entityOffsetsEnabled&&n.push(" worldPosition.xyz = worldPosition.xyz + offset;"),n.push(" vec4 viewPosition = shadowViewMatrix * worldPosition; "),t&&(n.push("vWorldPosition = worldPosition;"),n.push("vFlags = flags;")),n.push(" gl_Position = shadowProjMatrix * viewPosition;"),n.push("}"),n.push("gl_PointSize = pointSize;"),n.push("}"),n}},{key:"_buildFragmentShader",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// Instancing geometry depth drawing fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;"),r.push("in float vFlags;");for(var i=0,a=t.sectionPlanes.length;i 1.0) {"),r.push(" discard;"),r.push(" }"),n){r.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;"),r.push(" if (clippable) {"),r.push(" float dist = 0.0;");for(var s=0,o=t.sectionPlanes.length;s 0.0) { discard; }"),r.push("}")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(packNormalToRGB(vViewNormal), 1.0); "),r.push("}"),r}}]),n}(),xa=function(){function e(t){b(this,e),this._scene=t}return P(e,[{key:"_compile",value:function(){this._colorRenderer&&!this._colorRenderer.getValid()&&(this._colorRenderer.destroy(),this._colorRenderer=null),this._depthRenderer&&!this._depthRenderer.getValid()&&(this._depthRenderer.destroy(),this._depthRenderer=null),this._silhouetteRenderer&&!this._silhouetteRenderer.getValid()&&(this._silhouetteRenderer.destroy(),this._silhouetteRenderer=null),this._pickMeshRenderer&&!this._pickMeshRenderer.getValid()&&(this._pickMeshRenderer.destroy(),this._pickMeshRenderer=null),this._pickDepthRenderer&&!this._pickDepthRenderer.getValid()&&(this._pickDepthRenderer.destroy(),this._pickDepthRenderer=null),this._occlusionRenderer&&!1===this._occlusionRenderer.getValid()&&(this._occlusionRenderer.destroy(),this._occlusionRenderer=null),this._shadowRenderer&&!this._shadowRenderer.getValid()&&(this._shadowRenderer.destroy(),this._shadowRenderer=null)}},{key:"colorRenderer",get:function(){return this._colorRenderer||(this._colorRenderer=new Ca(this._scene,!1)),this._colorRenderer}},{key:"silhouetteRenderer",get:function(){return this._silhouetteRenderer||(this._silhouetteRenderer=new _a(this._scene)),this._silhouetteRenderer}},{key:"depthRenderer",get:function(){return this._depthRenderer||(this._depthRenderer=new Na(this._scene)),this._depthRenderer}},{key:"pickMeshRenderer",get:function(){return this._pickMeshRenderer||(this._pickMeshRenderer=new Ba(this._scene)),this._pickMeshRenderer}},{key:"pickDepthRenderer",get:function(){return this._pickDepthRenderer||(this._pickDepthRenderer=new Oa(this._scene)),this._pickDepthRenderer}},{key:"occlusionRenderer",get:function(){return this._occlusionRenderer||(this._occlusionRenderer=new Sa(this._scene)),this._occlusionRenderer}},{key:"shadowRenderer",get:function(){return this._shadowRenderer||(this._shadowRenderer=new La(this._scene)),this._shadowRenderer}},{key:"_destroy",value:function(){this._colorRenderer&&this._colorRenderer.destroy(),this._depthRenderer&&this._depthRenderer.destroy(),this._silhouetteRenderer&&this._silhouetteRenderer.destroy(),this._pickMeshRenderer&&this._pickMeshRenderer.destroy(),this._pickDepthRenderer&&this._pickDepthRenderer.destroy(),this._occlusionRenderer&&this._occlusionRenderer.destroy(),this._shadowRenderer&&this._shadowRenderer.destroy()}}]),e}(),Ma={};var Fa=new Uint8Array(4),Ha=new Float32Array(1),Ua=Z.vec4([0,0,0,1]),Ga=Z.vec4([0,0,0,1]),ka=Z.vec4([0,0,0,1]),Va=new Float32Array(3),ja=function(){function e(t){var n,r,i;b(this,e),this.model=t.model,this.material=t.material,this.sortId="PointsInstancingLayer",this.layerIndex=t.layerIndex,this._pointsInstancingRenderers=(n=t.model.scene,r=n.id,(i=Ma[r])||(i=new xa(n),Ma[r]=i,i._compile(),n.on("compile",(function(){i._compile()})),n.on("destroyed",(function(){delete Ma[r],i._destroy()}))),i),this._aabb=Z.collapseAABB3(),this._state=new Mt({obb:Z.OBB3(),numInstances:0,origin:t.origin?Z.vec3(t.origin):null,geometry:t.geometry,colorsBuf:null,flagsBuf:null,offsetsBuf:null,modelMatrixCol0Buf:null,modelMatrixCol1Buf:null,modelMatrixCol2Buf:null,pickColorsBuf:null}),this._numPortions=0,this._numVisibleLayerPortions=0,this._numTransparentLayerPortions=0,this._numXRayedLayerPortions=0,this._numHighlightedLayerPortions=0,this._numSelectedLayerPortions=0,this._numClippableLayerPortions=0,this._numEdgesLayerPortions=0,this._numPickableLayerPortions=0,this._numCulledLayerPortions=0,this.numIndices=t.geometry.numIndices,this._pickColors=[],this._offsets=[],this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[],this._portions=[],this._finalized=!1,this.aabb=Z.collapseAABB3()}return P(e,[{key:"createPortion",value:function(e){var t=e.meshMatrix,n=e.worldMatrix,r=e.aabb,i=e.pickColor;if(this._finalized)throw"Already finalized";this.model.scene.entityOffsetsEnabled&&(this._offsets.push(0),this._offsets.push(0),this._offsets.push(0)),this._modelMatrixCol0.push(t[0]),this._modelMatrixCol0.push(t[4]),this._modelMatrixCol0.push(t[8]),this._modelMatrixCol0.push(t[12]),this._modelMatrixCol1.push(t[1]),this._modelMatrixCol1.push(t[5]),this._modelMatrixCol1.push(t[9]),this._modelMatrixCol1.push(t[13]),this._modelMatrixCol2.push(t[2]),this._modelMatrixCol2.push(t[6]),this._modelMatrixCol2.push(t[10]),this._modelMatrixCol2.push(t[14]),this._pickColors.push(i[0]),this._pickColors.push(i[1]),this._pickColors.push(i[2]),this._pickColors.push(i[3]),Z.collapseAABB3(r);for(var a=this._state.obb,s=a.length,o=0;o0){this._state.flagsBuf=new pt(e,e.ARRAY_BUFFER,new Float32Array(t),t,1,e.DYNAMIC_DRAW,!1)}if(this.model.scene.entityOffsetsEnabled&&this._offsets.length>0){this._state.offsetsBuf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._offsets),this._offsets.length,3,e.DYNAMIC_DRAW,!1),this._offsets=[]}if(this._modelMatrixCol0.length>0){var n=!1;this._state.modelMatrixCol0Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol0),this._modelMatrixCol0.length,4,e.STATIC_DRAW,n),this._state.modelMatrixCol1Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol1),this._modelMatrixCol1.length,4,e.STATIC_DRAW,n),this._state.modelMatrixCol2Buf=new pt(e,e.ARRAY_BUFFER,new Float32Array(this._modelMatrixCol2),this._modelMatrixCol2.length,4,e.STATIC_DRAW,n),this._modelMatrixCol0=[],this._modelMatrixCol1=[],this._modelMatrixCol2=[]}if(this._pickColors.length>0){this._state.pickColorsBuf=new pt(e,e.ARRAY_BUFFER,new Uint8Array(this._pickColors),this._pickColors.length,4,e.STATIC_DRAW,!1),this._pickColors=[]}this._state.geometry=null,this._finalized=!0}},{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)}},{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._setFlags(e,t)}},{key:"setCollidable",value:function(e,t){if(!this._finalized)throw"Not finalized"}},{key:"setPickable",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&be?(this._numPickableLayerPortions++,this.model.numPickableLayerPortions++):(this._numPickableLayerPortions--,this.model.numPickableLayerPortions--),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){if(!this._finalized)throw"Not finalized";t&Ee?(this._numCulledLayerPortions++,this.model.numCulledLayerPortions++):(this._numCulledLayerPortions--,this.model.numCulledLayerPortions--),this._setFlags(e,t,n)}},{key:"setColor",value:function(e,t){if(!this._finalized)throw"Not finalized";Fa[0]=t[0],Fa[1]=t[1],Fa[2]=t[2],this._state.colorsBuf.setData(Fa,3*e)}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"_setFlags",value:function(e,t,n){if(!this._finalized)throw"Not finalized";var r=!!(t&Te),i=!!(t&Re),a=!!(t&Ce),s=!!(t&_e),o=!!(t&Be),l=!!(t&be),u=!!(t&Ee),c=0;c|=!r||u||i||a&&!this.model.scene.highlightMaterial.glowThrough||s&&!this.model.scene.selectedMaterial.glowThrough?Lt.NOT_RENDERED:n?Lt.COLOR_TRANSPARENT:Lt.COLOR_OPAQUE,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.SILHOUETTE_SELECTED:a?Lt.SILHOUETTE_HIGHLIGHTED:i?Lt.SILHOUETTE_XRAYED:Lt.NOT_RENDERED)<<4,c|=(!r||u?Lt.NOT_RENDERED:s?Lt.EDGES_SELECTED:a?Lt.EDGES_HIGHLIGHTED:i?Lt.EDGES_XRAYED:o?n?Lt.EDGES_COLOR_TRANSPARENT:Lt.EDGES_COLOR_OPAQUE:Lt.NOT_RENDERED)<<8,c|=(r&&!u&&l?Lt.PICK:Lt.NOT_RENDERED)<<12,c|=(t&De?255:0)<<16,Ha[0]=c,this._state.flagsBuf.setData(Ha,e)}},{key:"setOffset",value:function(e,t){if(!this._finalized)throw"Not finalized";this.model.scene.entityOffsetsEnabled?(Va[0]=t[0],Va[1]=t[1],Va[2]=t[2],this._state.offsetsBuf.setData(Va,3*e)):this.model.error("Entity#offset not enabled for this Viewer")}},{key:"drawColorOpaque",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._numTransparentLayerPortions!==this._numPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Lt.COLOR_OPAQUE)}},{key:"drawColorTransparent",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numTransparentLayerPortions&&this._numXRayedLayerPortions!==this._numPortions&&this._pointsInstancingRenderers.colorRenderer&&this._pointsInstancingRenderers.colorRenderer.drawLayer(t,this,Lt.COLOR_TRANSPARENT)}},{key:"drawDepth",value:function(e,t){}},{key:"drawNormals",value:function(e,t){}},{key:"drawSilhouetteXRayed",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numXRayedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_XRAYED)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numHighlightedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_HIGHLIGHTED)}},{key:"drawSilhouetteSelected",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&0!==this._numSelectedLayerPortions&&this._pointsInstancingRenderers.silhouetteRenderer&&this._pointsInstancingRenderers.silhouetteRenderer.drawLayer(t,this,Lt.SILHOUETTE_SELECTED)}},{key:"drawEdgesColorOpaque",value:function(e,t){}},{key:"drawEdgesColorTransparent",value:function(e,t){}},{key:"drawEdgesHighlighted",value:function(e,t){}},{key:"drawEdgesSelected",value:function(e,t){}},{key:"drawEdgesXRayed",value:function(e,t){}},{key:"drawOcclusion",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.occlusionRenderer&&this._pointsInstancingRenderers.occlusionRenderer.drawLayer(t,this,Lt.COLOR_OPAQUE)}},{key:"drawShadow",value:function(e,t){}},{key:"drawPickMesh",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickMeshRenderer&&this._pointsInstancingRenderers.pickMeshRenderer.drawLayer(t,this,Lt.PICK)}},{key:"drawPickDepths",value:function(e,t){this._numCulledLayerPortions!==this._numPortions&&0!==this._numVisibleLayerPortions&&this._pointsInstancingRenderers.pickDepthRenderer&&this._pointsInstancingRenderers.pickDepthRenderer.drawLayer(t,this,Lt.PICK)}},{key:"drawPickNormals",value:function(e,t){}},{key:"destroy",value:function(){var e=this._state;e.colorsBuf&&(e.colorsBuf.destroy(),e.colorsBuf=null),e.flagsBuf&&(e.flagsBuf.destroy(),e.flagsBuf=null),e.offsetsBuf&&(e.offsetsBuf.destroy(),e.offsetsBuf=null),e.modelMatrixCol0Buf&&(e.modelMatrixCol0Buf.destroy(),e.modelMatrixCol0Buf=null),e.modelMatrixCol1Buf&&(e.modelMatrixCol1Buf.destroy(),e.modelMatrixCol1Buf=null),e.modelMatrixCol2Buf&&(e.modelMatrixCol2Buf.destroy(),e.modelMatrixCol2Buf=null),e.pickColorsBuf&&(e.pickColorsBuf.destroy(),e.pickColorsBuf=null),e.destroy()}}]),e}(),Qa=function(){function e(){b(this,e),this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}return P(e,[{key:"reset",value:function(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}]),e}(),Wa=function(){function e(t){b(this,e),this.id=t.id,this.colorTexture=t.colorTexture,this.metallicRoughnessTexture=t.metallicRoughnessTexture,this.normalsTexture=t.normalsTexture,this.emissiveTexture=t.emissiveTexture,this.occlusionTexture=t.occlusionTexture}return P(e,[{key:"destroy",value:function(){}}]),e}(),za=function(){function e(t){b(this,e),this.id=t.id,this.texture=t.texture}return P(e,[{key:"destroy",value:function(){this.texture&&(this.texture.destroy(),this.texture=null)}}]),e}();function Ka(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===r){var a=Ct(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===a)return null;if(33776===i)return a.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(n=Ct(e,"WEBGL_compressed_texture_s3tc")))return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){var s=Ct(e,"WEBGL_compressed_texture_pvrtc");if(null===s)return null;if(35840===i)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){var o=Ct(e,"WEBGL_compressed_texture_etc1");return null!==o?o.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){var l=Ct(e,"WEBGL_compressed_texture_etc");if(null===l)return null;if(37492===i)return 3001===r?l.COMPRESSED_SRGB8_ETC2:l.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===r?l.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:l.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){var u=Ct(e,"WEBGL_compressed_texture_astc");if(null===u)return null;if(37808===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:u.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:u.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:u.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:u.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:u.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:u.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:u.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:u.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:u.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:u.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:u.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:u.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:u.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===r?u.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:u.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){var c=Ct(e,"EXT_texture_compression_bptc");if(null===c)return null;if(36492===i)return 3001===r?c.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:c.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}var Ya=new Uint8Array([0,0,0,1]),Xa=function(){function e(t){var n=t.gl,r=t.target,i=t.format,a=t.type,s=t.wrapS,o=t.wrapT,l=t.wrapR,u=t.encoding,c=t.preloadColor,f=t.premultiplyAlpha,p=t.flipY;b(this,e),this.gl=n,this.target=r||n.TEXTURE_2D,this.format=i||1023,this.type=a||1009,this.internalFormat=null,this.premultiplyAlpha=!!f,this.flipY=!!p,this.unpackAlignment=4,this.wrapS=s||1e3,this.wrapT=o||1e3,this.wrapR=l||1e3,this.encoding=u||3001,this.texture=n.createTexture(),c&&this.setPreloadColor(c),this.allocated=!0}return P(e,[{key:"setPreloadColor",value:function(e){e?(Ya[0]=Math.floor(255*e[0]),Ya[1]=Math.floor(255*e[1]),Ya[2]=Math.floor(255*e[2]),Ya[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(Ya[0]=0,Ya[1]=0,Ya[2]=0,Ya[3]=255);var t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP)for(var n=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],r=0,i=n.length;r1&&void 0!==arguments[1]?arguments[1]:{},n=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);var r=!1;n.bindTexture(this.target,this.texture);var i=n.getParameter(n.UNPACK_FLIP_Y_WEBGL);n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,this.flipY);var a=n.getParameter(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL);n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);var s=n.getParameter(n.UNPACK_ALIGNMENT);n.pixelStorei(n.UNPACK_ALIGNMENT,this.unpackAlignment);var o=n.getParameter(n.UNPACK_COLORSPACE_CONVERSION_WEBGL);n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,n.NONE);var l=Ka(n,this.minFilter);n.texParameteri(this.target,n.TEXTURE_MIN_FILTER,l),l!==n.NEAREST_MIPMAP_NEAREST&&l!==n.LINEAR_MIPMAP_NEAREST&&l!==n.NEAREST_MIPMAP_LINEAR&&l!==n.LINEAR_MIPMAP_LINEAR||(r=!0);var u=Ka(n,this.magFilter);u&&n.texParameteri(this.target,n.TEXTURE_MAG_FILTER,u);var c=Ka(n,this.wrapS);c&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,c);var f=Ka(n,this.wrapT);f&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,f);var p=Ka(n,this.format,this.encoding),A=Ka(n,this.type),d=qa(n,this.internalFormat,p,A,this.encoding,!1);if(this.target===n.TEXTURE_CUBE_MAP){if(ae.isArray(e))for(var v=e,h=[n.TEXTURE_CUBE_MAP_POSITIVE_X,n.TEXTURE_CUBE_MAP_NEGATIVE_X,n.TEXTURE_CUBE_MAP_POSITIVE_Y,n.TEXTURE_CUBE_MAP_NEGATIVE_Y,n.TEXTURE_CUBE_MAP_POSITIVE_Z,n.TEXTURE_CUBE_MAP_NEGATIVE_Z],I=0,y=h.length;I1;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);var o=Ka(i,this.wrapS);o&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,o);var l=Ka(i,this.wrapT);if(l&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,l),this.type===i.TEXTURE_3D||this.type===i.TEXTURE_2D_ARRAY){var u=Ka(i,this.wrapR);u&&i.texParameteri(this.target,i.TEXTURE_WRAP_R,u),i.texParameteri(this.type,i.TEXTURE_WRAP_R,u)}s?(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Ja(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ja(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Ka(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Ka(i,this.magFilter)));var c=Ka(i,this.format,this.encoding),f=Ka(i,this.type),p=qa(i,this.internalFormat,c,f,this.encoding,!1);i.texStorage2D(i.TEXTURE_2D,a,p,t[0].width,t[0].height);for(var A=0,d=t.length;A5&&void 0!==arguments[5]&&arguments[5];if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}var s=n;return n===e.RED&&(r===e.FLOAT&&(s=e.R32F),r===e.HALF_FLOAT&&(s=e.R16F),r===e.UNSIGNED_BYTE&&(s=e.R8)),n===e.RG&&(r===e.FLOAT&&(s=e.RG32F),r===e.HALF_FLOAT&&(s=e.RG16F),r===e.UNSIGNED_BYTE&&(s=e.RG8)),n===e.RGBA&&(r===e.FLOAT&&(s=e.RGBA32F),r===e.HALF_FLOAT&&(s=e.RGBA16F),r===e.UNSIGNED_BYTE&&(s=3001===i&&!1===a?e.SRGB8_ALPHA8:e.RGBA8),r===e.UNSIGNED_SHORT_4_4_4_4&&(s=e.RGBA4),r===e.UNSIGNED_SHORT_5_5_5_1&&(s=e.RGB5_A1)),s!==e.R16F&&s!==e.R32F&&s!==e.RG16F&&s!==e.RG32F&&s!==e.RGBA16F&&s!==e.RGBA32F||Ct(e,"EXT_color_buffer_float"),s}function Ja(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}var Za={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}},$a=function(){function e(t,n,r){b(this,e),this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=t,this.onProgress=n,this.onError=r}return P(e,[{key:"itemStart",value:function(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}},{key:"itemEnd",value:function(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}},{key:"itemError",value:function(e){void 0!==this.onError&&this.onError(e)}},{key:"resolveURL",value:function(e){return this.urlModifier?this.urlModifier(e):e}},{key:"setURLModifier",value:function(e){return this.urlModifier=e,this}},{key:"addHandler",value:function(e,t){return this.handlers.push(e,t),this}},{key:"removeHandler",value:function(e){var t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}},{key:"getHandler",value:function(e){for(var t=0,n=this.handlers.length;t0&&void 0!==arguments[0]?arguments[0]:4;b(this,e),this.pool=t,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}return P(e,[{key:"_initWorker",value:function(e){if(!this.workers[e]){var t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}},{key:"_getIdleWorker",value:function(){for(var e=0;e0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),as++}return this._transcoderPending}},{key:"transcode",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,a){var s=r;n._init().then((function(){return n._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:s},e)})).then((function(e){var n=e.data,r=n.mipmaps,s=(n.width,n.height,n.format),o=n.type,l=n.error,u=n.dfdTransferFn,c=n.dfdFlags;if("error"===o)return a(l);t.setCompressedData({mipmaps:r,props:{format:s,minFilter:1===r.length?1006:1008,magFilter:1===r.length?1006:1008,encoding:2===u?3001:3e3,premultiplyAlpha:!!(1&c)}}),i()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),as--}}]),e}();ss.BasisFormat={ETC1S:0,UASTC_4x4:1},ss.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},ss.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},ss.BasisWorker=function(){var e,t,n,r=_EngineFormat,i=_TranscoderFormat,a=_BasisFormat;self.addEventListener("message",(function(s){var c,f=s.data;switch(f.type){case"init":e=f.config,c=f.transcoderBinary,t=new Promise((function(e){n={wasmBinary:c,onRuntimeInitialized:e},BASIS(n)})).then((function(){n.initializeBasis(),void 0===n.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((function(){try{for(var t=function(t){var s=new n.KTX2File(new Uint8Array(t));function c(){s.close(),s.delete()}if(!s.isValid())throw c(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var f=s.isUASTC()?a.UASTC_4x4:a.ETC1S,p=s.getWidth(),A=s.getHeight(),d=s.getLevels(),v=s.getHasAlpha(),h=s.getDFDTransferFunc(),I=s.getDFDFlags(),y=function(t,n,s,c){for(var f,p,A=t===a.ETC1S?o:l,d=0;d